ESP-32 config wifi in micropython

Make a file with the name with the following code:

def do_connect():
    import network
    sta_if = network.WLAN(network.STA_IF)
    if not sta_if.isconnected():
        print('connecting to network...')
        sta_if.connect('essd', 'password')
        while not sta_if.isconnected():
        print('network config:', sta_if.ifconfig())

Edit to:

import ConnectWifi

Upload both files with ampy to the esp-32

ampy -p /dev/ttyUSB0 put
ampy -p /dev/ttyUSB0 put

Now when your micropython device boots up it will connect immediately connect to the configured wifi-network.

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 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 --port /dev/ttyUSB0 erase_flash

Then flashed micropython on the chip. (your version of the .bin file may differ) --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 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’ to the esp-32 with ampy.

ampy -p /dev/ttyUSB0 put

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