Table of Contents
In Fire Beetle ESP 32 Project I wrote about connecting the FireBeetle ESP32 with the Arduino IDE and writing a little C-style program. Another interesting approach is to use MicroPython.
To get MicroPython onto the board we use the esptool command line. Because we are in the Python ecosystem we use pip to install esptool:
pip install esptool
Go to https://micropython.org/download/esp32/
and download the latest release as of today is v1.19.1 (2022-06-18) .bin
Before we can install the firmware it is recommended to erase the flash
On my machine the port is /dev/tty.usbserial-14130. This can vary depending on your OS and setup.
esptool.py --port /dev/tty.usbserial-14130 erase_flash
Flashing the firmware looks like the following:
esptool.py --chip esp32 --baud 115200 --port /dev/tty.usbserial-14130 write_flash -z 0x1000 ./esp32-idf3-20191220-v1.12.bin
To prevent flash errors we set the transmission speed to 115200 baud
Connect via Serial
When you work with an unixoid system like linux or macos you can use screen to connect via serial port. On Windows you can download the program putty
screen /dev/tty.usbserial-14130 115200
After connecting you will get the prompt from the python command line aka REPL
Working with scripts
After fiddling around with the REPL we want to write our first program. We write a program like the Arduino blink sketch but just in Python:
The onboard blue led is connected to pin 2
from machine import Pin import time p2 = Pin(2, Pin.OUT) def blink(): while True: p2.value(0) time.sleep(1) p2.value(1) time.sleep(1) blink()
Save this script in a file with the name blink.py
To upload scripts to the FireBeetle board we use another nice library called ampy from AdaFruit. We install it via pip as well
pip install adafruit-ampy
With ampy we can upload the file to our board.
ampy --port /dev/tty.usbserial-14130 put blink.py
If it doesn’t work right away, please close your terminal connection.
When the upload is finished you can reconnect via serial console and import your script and the led should start to blink
Running scripts on startup
When your script should start directly at power on, you upload it as main.py
ampy --port /dev/tty.usbserial-14130 put blink.py /main.py
If you had fun so far feel free to read my Mailbox IoT ESP 32 Project article as well