Micropython on the ESP-32

Some time ago i bought an esp-32 and now is the time to play with it. I like python so micropython will be flashed on it. I downloaded the latest firmware from micropython.org and installed the esptool to flash the firmware.

sudo pip3 install esptool

I attached the esp-32 to my computer with a micro-usbcable and looked for the port it got attached to.

 sudo dmesg

I this case it was /dev/ttyUSB0.
Because it is the first time I flash micropython on the chip it is recommended to erase the flash first

 esptool.py --port /dev/ttyUSB0 erase_flash

Then flashed micropython on the chip. (your version of the .bin file may differ)

esptool.py --chip esp32 --port /dev/ttyUSB0 write_flash -z 0x1000 esp32-20180403-v1.9.3-503-gbcfff4fc.bin

Did it work? Well, let’s connect with it to get a repl.

screen /dev/ttyUSB0 115200

Yeah, we got a repl: >>>

print("Hello World"

My version of the esp-32 has a led on pin 16 which is on if the pin is low and off if the pin is high.

import machine
led = machine.Pin(16, machine.Pin.OUT)
led.value(0) # led is on
led.value(1) # led is off

You can exit screen with Ctrl-a \ y. On the computer create a file called main.py with the following code

import machine
import time
led = machine.Pin(16, machine.Pin.OUT)
while True:

To ‘upload’ a file we need a tool called ampy.

sudo pip3 install ampy

Now ‘upload’ main.py to the esp-32 with ampy.

ampy -p /dev/ttyUSB0 put main.py

Powercycle the esp-32 and it will start main.py automaticly.
Yeah, we have blinky running!


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.