MicroPython on the ESP8266-EVB (evaluation board) from Olimex
We are not use to publish paper un english but this time we will offer a translation for our friend at Olimex.
Today, I got my toolbox and decided to make the Olimex ESP8266-EVB board running MicroPython. It is an affordable ESP8266 evaluation board with relay and a user button, an ESP8266-DEV (an ESP8266 with 2Mio of Flash). The board also expose a very interesting UEXT port but we will cover it later on.
ESP8266-EVB from Olimex |
We will use a Linux computer (Linux Mint) to flash the ESP8266. You can also use a Raspberry-Pi to do the work (or an OlinuXino computer board for Olimex addicted user).
We do need:
- An ESP8266-EVB - evaluation board available at shop.mchooby.be or www.olimex.com .
- A 5V power supply unit - to power up the EVB board and ESP8266-DEV
- A Console cable 3.3V - also called USB-Serial-TTL available at shop.mchobby.be .
Console cable 3.3V |
We do need various software items (like the ESPtool).
If you need additiona linformation, you can have a look to our french tutoriel on Flasher MicroPython sur ESP8266 (Flashing MicroPython on ESP8266).
Install ESPTool
We will use the ESPtool to flash the ESP8266. That tool can be installed with the pip software (Python Install Package) usually available on Linux distros.
sudo pip install esptool
ESPTool is a Python 2.7 script. As it also Python 3 compatible (as read on the Net) it should also been possible to install it with the pip3 software.
MicroPython Firmware
It will be necessary to download the latest MicroPython firmware for ESP8266.
The ESP8266 MicroPython firmware are available at http://micropython.org/download/#esp8266
MicroPython Firmware - available at MicroPython.org |
So, we will download the file esp8266-20180511-v1.9.4.bin, name to be replaced as suited.
cd ~ wget http://micropython.org/resources/firmware/esp8266-20180511-v1.9.4.bin
How to activate the Flash Mode on the ESP8266
It will be necessary to activate the Flash Mode on the ESP8266 to erase the Flash and upload the MicroPython Firmware.
On the Olimex's ESP8266 you have to hold down the GPIO 0 button while applying a power cycle. The GPIO 0 button is released only after the power cycle. Voila! the board is in Flash Mode.
ESP8266-EVB (Evaluation Board) |
As first step, we do wire the console USB cable on the ESP8266's serial port. The ESP8266's serial port is available on the UEXT connector of ESP8266-EVB board.
Connect the USB-to-Serial converter (console cable) on the UEXT port |
Connect the USB-to-Serial converter (console cable) on the UEXT port of ESP8266-EVB (Evaluation Board) |
~ $ dmesg
..
[314212.993727] usb 2-2: Product: USB-Serial Controller
[314212.993731] usb 2-2: Manufacturer: Prolific Technology Inc.
[314213.370802] usbcore: registered new interface driver usbserial
[314213.370812] usbcore: registered new interface driver usbserial_generic
[314213.370819] usbserial: USB Serial support registered for generic
[314213.374407] usbcore: registered new interface driver pl2303
[314213.374417] usbserial: USB Serial support registered for pl2303
[314213.374430] pl2303 2-2:1.0: pl2303 converter detected
[314213.374956] usb 2-2: pl2303 converter now attached to ttyUSB0
The kernel messages mention the /dev/ttyUSB0 as serial device now attached to the computer.
Erase the ESP8266 Flash
The very first operation on the ESP8266 is the FLASH ERASING. This operation is performed with the ESPTool utility.
Set the ESP8266 in Flash Mode like described before.
Now, enter the following command:
esptool.py --port /dev/ttyUSB0 erase_flash
Which produce the following output while erasing the flash.
$ esptool.py --port /dev/ttyUSB0 erase_flash esptool.py v2.0.1 Connecting.... Detecting chip type... ESP8266 Chip is ESP8266 Uploading stub... Running stub... Stub running... Erasing flash (this may take a while)... Chip erase completed successfully in 2.5s Hard resetting...
After a flashing operation, it is very important to physically reset the microcontroler. As the Olimex's ESP8266 does not have a reset button, we do suggest to power cycle the microcontroler (the Evaluation Board in this case).
Unplug the PSU and plug it again after few seconds.
Flash the MicroPython firmware
In this second step, we will send the MicroPython firmware inside the Flash of the ESP8266. Again, we will use the ESPTool.
Set the ESP8266 in Flash Mode like explained before in this document.
Now, enter the following comands:
cd ~ esptool.py --port /dev/ttyUSB0 --baud 115200 write_flash --flash_size=detect -fm dio 0 esp8266-20180511-v1.9.4.bin
Which produce the following result while falsing the firmware to the board:
$ esptool.py --port /dev/ttyUSB0 --baud 115200 write_flash --flash_size=detect -fm dio 0 esp8266-20180511-v1.9.4.bin esptool.py v2.0.1 Connecting........_____....._____....._____.. Detecting chip type... ESP8266 Chip is ESP8266 Uploading stub... Running stub... Stub running... Configuring flash size... Auto-detected Flash size: 2MB Flash params set to 0x0230 Compressed 604872 bytes to 394893... Wrote 604872 bytes (394893 compressed) at 0x00000000 in 35.3 seconds (effective 137.1 kbit/s)... Hash of data verified. Leaving... Hard resetting...
After a Flash operation, it is important to restart the board. Just apply a new power cycle.
Connecting the ESP8266 through the serial port
As the MicroPython firmware is running, we can use the REPL (the MicroPython commande line) running on the microcontroler serial port.
The easiest is to run the screen command from your Linux machine.
screen /dev/ttyUSB0 115200
You can quit screen when you finished with it by pressing the keys Ctrl a followed by k and after y (for yes) -OR- pressing the keys Ctrl a followed by :quit and pressing the return key.
Once connected woth the serial REPL try to press the return key (to confirm a first empty line)) and you should see the REPL command promp >>> .
You can key-in the help() function (followed by return key) and you will see MicroPython displaying messages on the screen.
If you can't get the REPL prompt (the ">>>") then you should try to press the keys Ctrl c several times (this would stop the script currently running on the board).
Voila, we have covered the REPL connection. Your are now ready to write your first MicroPython lines in the REPL!
RShell, the advanced toolbox
With screen would only allow REPL interaction with the board.
It also exist a utility named RSHELL running as a command line interpreter allowing file transfers and directory manipulation through the serial port (over the REPL prompt).
You can also issue a REPL session from RShell. Using this tool requires some reading but this time would offer great benefits.
You can read the RShell english documentation from GitHub, we also produced a RShell french tutorial on the MCHobby's wiki.
Warning: you absolutely must reduce the RShell exchange buffer to 128 bytes. When experimenting RShell with ESP8266 we did noticed that default buffer size could corrupt the MicroPython file system while transferring files.
rshell --port /dev/ttyUSB0 --baud 115200 --buffer-size 128 --editor nano
Interact with the ESP8266-EVBLike mentionned on the picture (here below), the relay is wired on the GPIO 5 and the button on the GPIO 0.
Find here below a copy of the REPL session used to control the relay
Relay module on the ESP8266-EVB board |
>>> from machine import Pin >>> relay = Pin(5, Pin.OUT) >>> relay.value( 1 ) # relay activated >>> relay.value( 0 ) # relay switched off >>> relay.value( 1 ) # relay activated >>> relay.value( 0 ) # relay switched off >>> relay.value( 1 ) # relay activated >>> relay.value( 0 ) # relay switched off
The REPL session here below demonstrate how to read the button wired on the GPIO 0.
Entrée bouton de la carte ESP8266-EVB |
Summary :
- Switch OPEN : GPIO 0 = HIGH (3.3v)
- Switch CLOSED : GPIO 0 = LOW (0v)
>>> from machine import Pin >>> from time import sleep_ms >>> btn = Pin( 0, Pin.IN, pull=Pin.PULL_UP ) >>> while True: >>> print( '--' if btn.value()==1 else 'PRESSED' ) >>> sleep_ms( 300 )Which produce the following results on the REPL sessions:
-- PRESSED PRESSED PRESSED -- -- -- -- -- PRESSED -- -- PRESSED -- -- -- --
Great, its fabulous! Now you can integrate the ESP8266-EVB board to your next MicroPython project (or still by using the Arduino IDE if you'd prefer).
The UEXT connector
We will also take a minute to check the UEXT connector of the board.
This one is particularly interesting because it also carries the I2C bus.
UEXT connector and corresponding ESP8266's GPIO |
UEXT is a standardized interface that ease the connexion of sensors and relay board. We will have the opportunity to inspect this connector and some extensions.
Disovering MicroPython
MC Hobby produce many MicroPython french tutorials on its Wiki.
You may also find MicroPython english documentation on MicroPython.org.
Where to buy
- Olimex's ESP8266-EVB is available from stock at MCHobby.
- Olimex's ESP8266-DEV is available from stock at MCHobby.
Écrire un commentaire