For a couple of pounds I purchased a couple of ESP8266 NodeMCU WEMOS development boards to play with. Decided to go with the NodeMCU versions so that they come with a micro USB and 3.3 regulator onboard.
As I’ve been playing with Python for a while I decided to download MicroPython on to the ESP to provide control of real-world devices. Instructions on downloading, formatting and getting started with MicroPython can be found here.
I’ve included my notes here as things were not as plain-sailing as I would have liked.
Connecting the ESP8266 to my Mac – sounds easy but the hardest part is finding a USB cable that has data connections instead of just being wired for 5v-GND. Most charging cables come with only power wired so after trying about 6 cables I found one that worked.
So how did I know I had a good cables as all powered up the ESP? You need to see if your Mac shows the USB device turning up. Before connecting type “ls /dev | grep -I usb” and then connect the device. You should see the device show up if the cable has the right connections.
Now download the esptool for programming the ESP and transmits the firmware to the ESP.
And down a copy of the Micropython Firmware from the above MicroPython site.
If you need to find out ESP board information such as flash size use:
To program the ESP I used the following command:
esptool.py --port /dev/ttyUSB_DEVICE --baud 460800 write_flash --flash_size=detect 0 FIRMWARE>BIN
ttyUSB_DEVICE is your device found from the ls /dev command above
FIRMWARE.BIN is the file you downloaded from the MicroPython site
With luck the firmware would have downloaded and successfully been verified – woohoo!
Now you can connect to the device and get a REPL prompt.
REPL prompt – that sounds easy but it took a few goes to find the right command on the Mac to create a serial connection to the ESP on the USB port and then get it working. The “screen” command is available on the Mac and the speed to connect with is 115200.
screen /dev/cuUSB_DEVICE 115200
I found that I sometimes got an error about no Pty device. This turned out to be zombie screen processes locking out the device port. Perform a “ps -ef | grep -i usb” to find the zombie processes and kill them (show no mercy).
You can not follow the instructions on the MicroPython site to interact with the REPL prompt. If you want to upload/download files then you will need “WebREPL“.
Notes on uploading files to Execute
- Use the web version of WebREPL or WebREPL.py to send or get files from the ESP
- I found that once a file is uploaded you need to reset before attempting to run the file. A soft reset can be performed by pressing Ctrl-D in the browser or at the REPL command prompt in screen
- To run the file import it!
Controlling a 5050 WS2812B RGB LED Ring
This was a few pounds on Ebay so tried to connect it to the ESP8266 WEMOS which was pretty simple after I soldered some wires on. I connected the 5v and GND straight to the ESP pins, and the Din (DI) wire to D2 on the WEMOS. This is GPIO04 (pin out found here).
Power consumption = each led is around 18mA on.
If you want to create an online wiring diagram with drag-n-drop components then use https://www.circuito.io/app which is pretty cool.
To control the leds you need to run some MicroPython code on the ESP but you can use the example below:
import machine, neopixel
np = neopixel.NeoPixel(machine.Pin(4), 12) #we have 12 leds on GPIO4
np = (128, 0, 0) # Led 0 half bright single color - red I think
np = (0, 128, 0) # Led 2 another colour
np = (0, 0, 128)
You should have some (3) leds now light up, if it all works!