2019-03-16

An introduction to Micropython

The purpose of this project is to teach a litle about the Python programing language and embedded systems using MicroPython and the ESP8266 chip.

All of these instructions can be found at the MicroPython document site. These are my notes and steps I use.

The first thing you will need to do is install the esptool. This is a python program that that will enable firmware to be erased and uploaded to the module. The esptool can be found here: esptool

Once the esptool is installed you will need a copy of the MicroPython firmware. It can be found here. Firmware for ESP8266 boards

It is best to erase the flash of the device before the new firmware is installed. To do that we first need to determine which port the module is connected to. Run from a terminal:

dmesg | grep tty

And you should see something like below, the device is connected to usb port “ttyUSB0”

[mac@ASUS-FEDORA MicroPy]$ dmesg | grep tty
[    0.242104] printk: console [tty0] enabled
[  979.091143] usb 1-1: cp210x converter now attached to ttyUSB0

Now run:

esptool.py --port /dev/ttyUSB0 --baud 115200 erase_flash

This will return:

[mac@ASUS-FEDORA MicroPy]$ esptool.py --port /dev/ttyUSB0 --baud 115200 erase_flash
esptool.py v2.3.1
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 1.8s
Hard resetting via RTS pin…

Next, in terminal, CD to where the firmware is located. If you are using the version “esp8266-20190125-v1.10.bin”, run:

esptool.py --port /dev/ttyUSB0 --baud 115200 write_flash --flash_size=detect 0 esp8266-20190125-v1.10.bin

Or, if you cannot get a REPL in the next step, run:

esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect -fm dio 0 esp8266-20190125-v1.10.bin

If you are using different firmware, adjust.

[mac@ASUS-FEDORA FirmWare]$ esptool.py --port /dev/ttyUSB0 --baud 115200 write_flash --flash_size=detect 0 esp8266-20190125-v1.10.bin
esptool.py v2.3.1
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Flash params set to 0x0040
Compressed 615388 bytes to 399928...
Wrote 615388 bytes (399928 compressed) at 0x00000000 in 35.4 seconds (effective 139.2 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin…

To test the install, from the terminal run:

picocom /dev/ttyUSB0 -b115200

It might be necessary to hit the enter key a few times or push the reset button on the device for the REPL to show.

[mac@ASUS-FEDORA FirmWare]$ picocom /dev/ttyUSB0 -b115200
picocom v3.1

port is        : /dev/ttyUSB0
flowcontrol    : none
baudrate is    : 115200
parity is      : none
databits are   : 8
stopbits are   : 1
escape is      : C-a
local echo is  : no
noinit is      : no
noreset is     : no
hangup is      : no
nolock is      : no
send_cmd is    : sz -vv
receive_cmd is : rz -vv -E
imap is        : 
omap is        : 
emap is        : crcrlf,delbs,
logfile is     : none
initstring     : none
exit_after is  : not set
exit is        : no

Type [C-a] [C-h] to see available commands
Terminal ready

>>> 

The above >>> is the Python REPL. You can now run commands just as you would from your PC.