MicroPython Development

MicroPython on the ESP8266/ESP32


screen connects your terminal to a remote shell or REPL (like MicroPython) running on the serial port.
  • screen /dev/tty.SLAB_USBtoUART 115200 connects to a REPL running on an ESP.  (Different devices uses different ports.)
  • To quit screen, press ⌃A+k+y . This leaves my terminal messed up where programs that print line feeds just do the line feed w/out the carriage return. The reset command fixes this.

Using the REPL:
  • ⌃D reboots the board. This will run boot.py and then main.py. If one of these files contains an infinite loop (for example, to run a web server or to continuously print or upload sensor values), you won't see the >>> prompt again. In this case, press ⌃C to get back to the prompt.

ampy

ampy is a command-line tool that manipulates the file system.
  • Install pip3 install -u adafruit-ampy 
  • ampy -p /dev/tty.SLAB_USBtoUART put file.py copies a file from the host current directory to an ESP.

rshell

rshell opens an interactive shell with commands that support the functionality of both screen and ampy.
  • Install pip3 install -u adafruit-ampy 
  • rshell -p /dev/tty.SLAB_USBtoUART creates an rshell connection.
  • rshell may be unable to connect, if the MCU is running a loop that doesn’t return to the MicroPython prompt. (I think it hangs at Testing if ubinascii.unhexlify exists.) In this case, use screen (above) to connect, press ⌃C to quit the MicroPython prompt (you should then see the >>> prompt), quit screen, and try rshell again.
  • While running rshell, you have access to these commands:
  • repl opens an Python REPL.
  • ls /pyboard lists installed files.
  • rsync . /pyboard copies new and changed files from the current host directory to the MCU.

Documentation Links

  • The micropython-lib repository (as of 8.14.2019) documents some packages that are present, at least, on the ESP8266/EPS32 boards, and not documented in the main MicroPython documentation: