Micro Python on ESP32 (HUZZAH32)

Adafruit’s HUZZAH32 Feather board is built with the official WROOM32 module:

ESP32-WROOM Module
  • Two CPU cores that can be individually controlled, and the CPU clock frequency is adjustable from 80 MHz to 240 MHz
  • 448 kB of ROM for booting and core functions.
  • 520 kB of on-chip SRAM for data and instructions.
  • 8 kB of SRAM in RTC, which is called RTC FAST Memory and can be used for data storage;
  • 8 kB of SRAM in RTC, which is called RTC SLOW Memory and can be accessed by the co-processor during the Deep-sleep mode.
  • 4 MByte flash include in the WROOM32 module
  • Support for multiple external QSPI flash and SRAM chips.
  • Wi-Fi Radio: 802.11 b/g/n (802.11n up to 150 Mbps) WPA/WPA2/WPA2-Enterprise/WPS
  • BLE Radio: Bluetooth v4.2 BR/EDR and BLE specification
  • On-board PCB antenna

GPIO & Analog Pins

  • A0 – this is an analog input A0 and also an analog output DAC2. It can also be used as a GPIO #26. It uses ADC #2
  • A1 – this is an analog input A1 and also an analog output DAC1. It can also be used as a GPIO #25. It uses ADC #2
  • A2 – this is an analog input A2 and also GPI #34. Note it is not an output-capable pin! It uses ADC #1
  • A3 – this is an analog input A3 and also GPI #39. Note it is not an output-capable pin! It uses ADC #1
  • A4 – this is an analog input A4 and also GPI #36. Note it is not an output-capable pin! It uses ADC #1
  • A5 – this is an analog input A5 and also GPIO #4. It uses ADC #2
  • 21 – General purpose IO pin #21
  • 13 – This is GPIO #13 and also an analog input A12 on ADC #1. It’s also connected to the red LED next to the USB port
  • 12 – This is GPIO #12 and also an analog input A11 on ADC #2. This pin has a pull-down resistor built into it, we recommend using it as an output only, or making sure that the pull-down is not affected during boot.
  • 27 – This is GPIO #27 and also an analog input A10 on ADC #2
  • 33 – This is GPIO #33 and also an analog input A9 on ADC #1. It can also be used to connect a 32 KHz crystal.
  • 15 – This is GPIO #15 and also an analog input A8 on ADC #2
  • 32 – This is GPIO #32 and also an analog input A7 on ADC #1. It can also be used to connect a 32 KHz crystal.
  • 14 – This is GPIO #14 and also an analog input A6 on ADC #2
  • A13 – This is general purpose input #35 and also an analog input A13, which is a resistor divider connected to the VBATline

Operating voltage/Power supply
The ESP32 runs on 3.3V power and logic, and unless otherwise specified, GPIO pins are not 5V safe!

Micro Python

MicroPython is a tiny open source Python programming language interpreter that runs on small embedded development boards.

Philip van Allen published a Getting Started Guide for using Micro Python on ESP32 boards like the Adafruit Huzzah32. With Python3 installed on a Mac, the following libraries are needed: esptool, adafruit-ampy and can be quickly installed like so:

  • pip3 install esptool –upgrade
  • pip3 install adafruit-ampy –upgrade

Like mentioned in Philip’s guide,

  1. Install Legacy MacVCP USB to Serial driver for Adafruit Huzzah32, after which and once connected with a USB cable, the ESP32 board will show up as /dev/tty.SLAB_USBtoUART
  2. Wipe the flash memory clean: esptool.py –chip esp32 -p /dev/tty.SLAB_USBtoUART erase_flash, which will display the following output:
  3. Download the latest MicroPython Standard firmware: (currently v1.9.4-417) and flash it onto the board:
    esptool.py –chip esp32 -p /dev/tty.SLAB_USBtoUART write_flash -z 0x1000 ~/Downloads/esp32-20180731-v1.9.4-417-g21dae8771.bin, which will display the following output:

After a reset, screen /dev/tty.SLAB_USBtoUART 115200 will show the python prompt and entering help()will display the following output:

and CTRL-D shows the current OS version:

MicroPython v1.9.4-417-g21dae8771 on 2018-07-31; ESP32 module with ESP32″

Modules

>> help(‘modules’)

__main__ framebuf socket upip _boot gc ssl upip_utarfile _onewire hashlib struct upysh _thread heapq sys urandom _webrepl inisetup time ure apa106 io ubinascii urequests array json ucollections uselect binascii machine ucryptolib usocket btree math uctypes ussl builtins micropython uerrno ustruct cmath neopixel uhashlib utime collections network uhashlib utimeq dht ntptime uheapq uzlib ds18x20 onewire uio webrepl errno os ujson webrepl_setup esp random umqtt/robust websocket esp32 re umqtt/simple websocket_helper flashbdev select uos zlib Plus any modules on the filesystem >>>

Builtins

> import builtins
>> dir(builtins)

[‘__build_class__’, ‘__class__’, ‘__import__’, ‘__name__’, ‘__repl_print__’, ‘ArithmeticError’, ‘AssertionError’, ‘AttributeError’, ‘BaseException’, ‘EOFError’, ‘Ellipsis’, ‘Exception’, ‘GeneratorExit’, ‘ImportError’, ‘IndentationError’, ‘IndexError’, ‘KeyError’, ‘KeyboardInterrupt’, ‘LookupError’, ‘MemoryError’, ‘NameError’, ‘NotImplemented’, ‘NotImplementedError’, ‘OSError’, ‘OverflowError’, ‘RuntimeError’, ‘StopAsyncIteration’, ‘StopIteration’, ‘SyntaxError’, ‘SystemExit’, ‘TypeError’, ‘UnicodeError’, ‘ValueError’, ‘ZeroDivisionError’, ‘abs’, ‘all’, ‘any’, ‘bin’, ‘bool’, ‘bytearray’, ‘bytes’, ‘callable’, ‘chr’, ‘classmethod’, ‘compile’, ‘complex’, ‘delattr’, ‘dict’, ‘dir’, ‘divmod’, ‘enumerate’, ‘eval’, ‘exec’, ‘execfile’, ‘filter’, ‘float’, ‘frozenset’, ‘getattr’, ‘globals’, ‘hasattr’, ‘hash’, ‘help’, ‘hex’, ‘id’, ‘input’, ‘int’, ‘isinstance’, ‘issubclass’, ‘iter’, ‘len’, ‘list’, ‘locals’, ‘map’, ‘max’, ‘memoryview’, ‘min’, ‘next’, ‘object’, ‘oct’, ‘open’, ‘ord’, ‘pow’, ‘print’, ‘property’, ‘range’, ‘repr’, ‘reversed’, ’round’, ‘set’, ‘setattr’, ‘slice’, ‘sorted’, ‘staticmethod’, ‘str’, ‘sum’, ‘super’, ‘tuple’, ‘type’, ‘zip’] >>>

File System

There is already a boot.py file stored and adding a main.py (which will automatically execute after boot.py) we can for instance show the content of all files:

  • Ctrl-A Ctrl-\\
  • ampy -p /dev/tty.SLAB_USBtoUART put ~/Desktop/main.py
  • screen /dev/tty.SLAB\_USBtoUART 115200
  • Ctrl-D

 

One Reply to “Micro Python on ESP32 (HUZZAH32)”

  1. You, Sir, are a steely eyed missile man. Everything I needed to get moving forward. Take a bow.

Leave a Reply