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:

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 (with even rebooting your Mac)
  2. Wipe the flash memory clean:
    , which will display the following output:
  3. Download the latest MicroPython Standard (not the SPIRAM version) Firmware for ESP32 boards: (currently v1.9.4-…) and flash it onto the board:
    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: E.g.,:

“MicroPython v1.9.4-779-g5064df207 on 2019-01-12; ESP32 module with ESP32

How much Memory?

.. gc.mem_free() returns the free heap size in bytes. Therefore, about 100 KBytes of Heap Memory is available.

Modules

Builtins

File System

There is already a boot.py file stored in the file system. Additionally, a main.py (which will automatically execute after boot.py) could be put there, for instance using ‘ampy -p /dev/tty.SLAB_USBtoUART put ~/Desktop/main.py’

Adding the following variables to your ~/.bash_profile makes working with ampy command line tool much more convenient:

However, enabling webrepl makes the development process much faster. If possible, I recommend to provide the ESP32 with a static IP address, e.g. by mapping its MAC address to an IP in your Wifi Router settings.

Next edit the boot.py, providing your wifi router’s SSID and password, so that it looks something like this:

If you don’t want to enter a password every time you connect to the ESP32 via WebREPL, you may also want to create a webrepl_cfg.py file with just one line like this:

Share this post:

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