Tags

, ,

Simpson DOHDOH

It fascinates me how incredibly dumb I can be.  Guess what I didn’t think through this time?  The PyBoard V1.1 doesn’t come with wireless networking.  A lot of this post is about trying to get to an mqtt module using MicroPython on a PyBard….um….geez…what’s the point of installing this library if the hardware doesn’t have a wireless chip?  What a dolt I can be!  

Yet – I did learn how to update MicroPython using dfs-util as well as where to get the latest MicroPython from.  I also have a much better idea about the PyBoard effort.  I see the PyBoard effort as an excellent way to learn MicroPython without overcomplicating things (like adding networking).  I did get to use HomeBrew and understand the brew install environment a little better.

MicroPython

Playing around with MicroPython is off track from getting the Leaf Spa going.  The challenge with using the Arduino UNO is it’s lack of wireless support.  But I could add that in….with that said, I see MicroPython as being an extremely useful tool for rapid prototyping.  There are many advantages over the Arduino IDE.  This keeps me continuing to spend time understanding the MicroPython environment.

Useful commands

>>> import os
>>> os.uname()
(sysname=’pyboard’, nodename=’pyboard’, release=’1.8.7′, version=’v1.8.7 on 2017-01-08′, machine=’PYBv1.1 with STM32F405RG’)

>>> help(‘modules’)
object modules is of type str
encode — <function>
find — <function>
rfind — <function>
index — <function>
rindex — <function>
join — <function>
split — <function>
splitlines — <function>
rsplit — <function>
startswith — <function>
endswith — <function>
strip — <function>
lstrip — <function>
rstrip — <function>
format — <function>
replace — <function>
count — <function>
partition — <function>
rpartition — <function>
center — <function>
lower — <function>
upper — <function>
isspace — <function>
isalpha — <function>
isdigit — <function>
isupper — <function>
islower — <function>

A good link to have around – the link to the (most recent) MicroPython documentation.

Trying out MQTT

I wanted to try out mqtt using the MicroPython library umqtt.simple…Now this is great!  Thank you Mike Teachman for your GitHub repository where your work: “Using MQTT to publish to adafruit io. Micropython implementation on ESP8266” resides! 

Hmmm…the library wasn’t included so I asked a question about this on the MicroPython forum.  Yet again, the extremely helpful pythoncoder answered:  

If you install the latest release build of firmware (esp8266-20170108-v1.8.7.bin) from http://micropython.org/download you should find it ready installed.

There is a FAQ on MQTT here http://forum.micropython.org/viewtopic.php?f=16&t=2239&p=12683&hilit=MQTT+FAQ#p12683. 

ummm…..

Simpson DOHDOH!

I should have immediately checked the version of MicroPython…my mind didn’t go there.  It was the very end of the day.  Note to self: wait to ask questions in the morning.  Most answers fall into our heads when we sleep.

The current version (shows up when connect to PyBoard in CoolTerm:

MicroPython v1.8.2 on 2016-07-13; PYBv1.1 with STM32F405RG

Updating the MicroPython Version

I’m following the directions noted here.

Put the PyBoard into Device Firmware Upgrade mode

I followed the directions noted here.

Install dfu-util

 The dfu-util homepage notes:”Mac OS X users can also get dfu-util from Homebrew with “brew install dfu-util” or from MacPorts.

I had previously installed Homebrew.  So I did the brew install within a terminal window:

$ brew install dfu-util

==> Installing dependencies for dfu-util: libusb

==> Installing dfu-util dependency: libusb

==> Downloading https://homebrew.bintray.com/bottles/libusb-1.0.20.yosemite.bott

######################################################################## 100.0%

==> Pouring libusb-1.0.20.yosemite.bottle.tar.gz

Error: The `brew link` step did not complete successfully

The formula built, but is not symlinked into /usr/local

Could not symlink include/libusb-1.0

/usr/local/include is not writable.

 

You can try again using:

  brew link libusb

==> Summary

🍺  /usr/local/Cellar/libusb/1.0.20: 11 files, 293.3K

==> Installing dfu-util

==> Downloading https://homebrew.bintray.com/bottles/dfu-util-0.9.yosemite.bottl

######################################################################## 100.0%

==> Pouring dfu-util-0.9.yosemite.bottle.tar.gz

🍺  /usr/local/Cellar/dfu-util/0.9: 10 files, 121.6K

hmmm…The Error says /usr/local/include is not writable.  Within a terminal window, I go to /usr/local and type ls -al include:

drwxrwxr-x  4 root  wheel  136 Jan 28  2016 include

Include:

  • is a directory (d)
  • gives full access to root – the owner…oh wait, I probably should run with sudo….so I try sudo brew install dfu-util and get back:

Error: Cowardly refusing to ‘sudo brew install’

You can use brew with sudo, but only if the brew executable is owned by root.

However, this is both not recommended and completely unsupported so do so at

your own risk.

OK, I’m clueless…but since when has this stopped me?

  • gives full access to the wheel group (I have no idea what / who is members of the wheel group)
  • gives read, directory search access to everyone else.

So I’m thinking the challenge is everyone else also needs write permissions.  I type sudo chmod 777 include.  This adds write permissions for everyone:

drwxrwxrwx   4 root      wheel   136 Jan 28  2016 include

I’ll rerun the dfu-util install….

$ brew install dfu-util

Warning: dfu-util-0.9 already installed

$ sudo dfu-util -l 

dyld: Library not loaded: /usr/local/opt/libusb/lib/libusb-1.0.0.dylib

  Referenced from: /usr/local/bin/dfu-util

  Reason: image not found

Just peachy. I used the info here to uninstall (I think) dfu-util.

$  brew tap beeftornado/rmtree && brew install brew-rmtree

==> Tapping beeftornado/rmtree

Cloning into ‘/usr/local/Library/Taps/beeftornado/homebrew-rmtree’…

remote: Counting objects: 8, done.

remote: Compressing objects: 100% (7/7), done.

remote: Total 8 (delta 0), reused 4 (delta 0), pack-reused 0

Unpacking objects: 100% (8/8), done.

Checking connectivity… done.

Tapped 0 formulae (35 files, 47.0K)

Error: No available formula with the name “brew-rmtree” 

==> Searching for similarly named formulae…

Error: No similarly named formulae found.

==> Searching taps…

Error: No formulae found in taps.

==> You haven’t updated Homebrew in a while.

A formula for brew-rmtree might have been added recently.

Run `brew update` to get the latest Homebrew updates!

MacBook-Pro:local margaret$ brew rmtree dfu-util

==> Examining installed formulae required by dfu-util…

 /

 

Can safely be removed

———————-

libusb

 

Proceed?[y/N]: y

==> Cleaning up packages safe to remove

 

Uninstalling /usr/local/Cellar/dfu-util/0.9… (10 files, 121.6K)

 

Uninstalling /usr/local/Cellar/libusb/1.0.20… (11 files, 293.3K)

I noticed the text noted I hadn’t updated brew for awhile so I did that. The other thing I needed to do was give write permissions to all directories in /usr/local.

$ sudo chmod -R 777 /usr/local

repeating install using Homebrew…

$ brew install dfu-util

==> Installing dependencies for dfu-util: libusb

==> Installing dfu-util dependency: libusb

==> Downloading https://homebrew.bintray.com/bottles/libusb-1.0.20.yosemite.bott

Already downloaded: /Library/Caches/Homebrew/libusb-1.0.20.yosemite.bottle.tar.gz

==> Pouring libusb-1.0.20.yosemite.bottle.tar.gz

🍺  /usr/local/Cellar/libusb/1.0.20: 11 files, 293.3K

==> Installing dfu-util

==> Downloading https://homebrew.bintray.com/bottles/dfu-util-0.9.yosemite.bottl

Already downloaded: /Library/Caches/Homebrew/dfu-util-0.9.yosemite.bottle.tar.gz

==> Pouring dfu-util-0.9.yosemite.bottle.tar.gz

🍺  /usr/local/Cellar/dfu-util/0.9: 10 files, 121.6K

 

ChallengesBringOpportunitesYIPPEE

$ sudo dfu-util -l dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc. Copyright 2010-2016 Tormod Volden and Stefan Schmidt This program is Free Software and has ABSOLUTELY NO WARRANTY Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Deducing device DFU version from functional descriptor length Found Runtime: [05ac:8289] ver=0106, devnum=6, cfg=1, intf=3, path=”20-8.3″, alt=0, name=”UNKNOWN”, serial=”UNKNOWN”

Download the MicroPython Binary

I downloaded pybv10-20170108-v1.8.7.dfu from here.

Flash the Binary onto the PyBoard

$ sudo dfu-util –alt 0 -D pybv10-20170108-v1.8.7.dfu 

Password:

dfu-util 0.9

 

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.

Copyright 2010-2016 Tormod Volden and Stefan Schmidt

This program is Free Software and has ABSOLUTELY NO WARRANTY

Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

 

Match vendor ID from file: 0483

Match product ID from file: df11

Deducing device DFU version from functional descriptor length

Opening DFU capable USB device…

ID 0483:df11

Run-time device DFU version 011a

Claiming USB DFU Interface…

Setting Alternate Setting #0 …

Determining device status: state = dfuERROR, status = 10

dfuERROR, clearing status

Determining device status: state = dfuIDLE, status = 0

dfuIDLE, continuing

DFU mode device DFU version 011a

Device returned transfer size 2048

DfuSe interface name: “Internal Flash  “

file contains 1 DFU images

parsing DFU image 1

image for alternate setting 0, (2 elements, total size = 302392)

parsing element 1, address = 0x08000000, size = 15284

Download[=========================] 100%        15284 bytes

Download done.

parsing element 2, address = 0x08020000, size = 287092

Download[=========================] 100%       287092 bytes

Download done.

done parsing DfuSe file

FrustratedBummer

when I went into CoolTerm, the serial port was no longer seen. The USB was powering the PyBoard (lights flashed on the PyBoard)…so….and of course…

Simpson DOHDOH

I didn’t save the previous installation as suggested here…AND…I installed 1.8.7 for the PyBoard v1.0….Now THIS is where machine intelligence would help me out.  Have the attention to detail and repeat exactly what needs to be done :-)…because as me without this machine intelligence, I make too many mistakes…reran the dfu install using the right version of 1.8.7 – 

$ sudo dfu-util –alt 0 -D pybv11-20170108-v1.8.7.dfu

ChallengesBringOpportunitesYIPPEE!

Now we’re going with 1.8.7!…..

I found this OS command useful to figure out the version:

>>> import os
>>> os.uname()
(sysname=’pyboard’, nodename=’pyboard’, release=’1.8.7′, version=’v1.8.7 on 2017-01-08′, machine=’PYBv1.1 with STM32F405RG’)

Yapping to Adafruit.io

To yap with Adafruit.io, MicroPython needs access to a umqtt library.  There is a simple.umqtt library….

So I type in REPL:

>>> from umqtt.simple import MQTTClient
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
ImportError: no module named ‘umqtt’

Frustrated BUMMER

Spiffy…1.8.7 doesn’t seem to have the umqtt.simple module installed…which begs the question how do I list out what modules ARE installed?  And why was the advice I was given in the MicroPython forum that 1.8.7 did include umqtt?

Simpson DOHBECAUSE the PYBOARD DOESN’T COME WITH A WIRELESS CHIP YAH DUMMY!

Turning Stuff ON/OFF

Sure – the relay circuit went POP, SPITZ….lights flashed…plastic burnt…but my husband says as long as the house doesn’t burn down I can keep going.  Personally, he should tighten this up a bit…but that is one of the many characteristics that make me love him even more.

So I’m taking a step back and making sure I understand what the heck is going on with the relay circuit.

The 4 channel relay board I’m using has 4 Songle SRD-05VDC-SL-C relays.  Now this should be simple.  I get the DC circuit…here’s what I had in the January   Build Log:

ChallengesBringOpportunites YIPPEE!

I mentioned the helpful Harry’s Bench post in a previous build log.  Here is a helpful entry showing the relay’s inputs:

GND goes to the Arduino GND and VCC goes to Arduino 5V.  There are four inputs controlled by Arduino pins.  The inputs map to the numbers on the relay.  To test the input side, I hooked up an Arduino to the input side of the relay and ran the Simple4ChannelRelayTest.ino sketch.

 

 AC -> Relay Output

I like this image from the Circuit Basics blog entry “How to Set Up a 5V Relay on the Arduino.”:

NewImage

The Live/Hot/Power wire on the plug is connected to the COM pin of the relay.  The NO pin connects with the Live/Hot/Power wire on the load (in this case the light bulb).

I had this image in an earlier build log.  I repeat it here to remember.  The thought process I have is to maintain an attention to detail when it comes to the VAC side:

and plug using US colors:

Ah..but even better is this Circuit Basics blog entry: “TURN ANY APPLIANCE INTO A SMART DEVICE WITH AN ARDUINO CONTROLLED POWER OUTLET”

Build an Arduino Controlled Power Outlet 24

That’s it for today.  Be Kind.

Advertisements