ESP32 MicroPython Blinking LED (DevKitC + Thonny)

A quick first project to validate your toolchain: CP210x driver → MicroPython → Thonny → blink an LED on GPIO16.

Board: ESP32 DevKitC (Wroom-32) • Language: MicroPython • IDE: Thonny

Contents

What you need

ESP32 documentation is hosted by Espressif at documentation.espressif.com.

1) USB-to-UART driver (CP210x)

Most ESP32 dev boards expose USB via a USB‑to‑UART bridge chip, commonly the Silicon Labs CP2102/CP210x. If the corresponding driver is missing, your board may not show up as a COM port.

Check in Windows

  1. Open Device Manager with Win + X, then M.
  2. Plug in the ESP32 with a Micro‑USB cable.
  3. Look for a new COM port (for example under “Ports (COM & LPT)”).

If no new port appears, install the Silicon Labs VCP driver:

Download CP210x VCP drivers

After installation, unplug/replug the board and verify the COM port appears.

2) Thonny + MicroPython

For a quick prototype, we’ll use MicroPython with the Thonny IDE. MicroPython is interpreted (great for rapid iteration); for performance‑heavy applications, a compiled environment (e.g., Arduino/ESP-IDF) may be preferable.

  1. Install Thonny, then connect the ESP32.
  2. In Thonny: Tools → Options → Interpreter.
  3. Select MicroPython (ESP32) and your board’s COM port.
  4. Hold the board’s BOOT button and click Install or update MicroPython.

3) Wiring the LED

Connect an LED to GPIO 16 through a 390 Ω series resistor to ground:

Tip: Keep the USB cable connected during development; the board can be powered over USB for this test.

4) The blinking script

Paste the following script into Thonny:

# Import the Pin class so we can control ESP32 GPIO pins (turn pins on/off, read inputs, etc.)
from machine import Pin

# Import time so we can pause between LED on/off states (create the “blink” timing)
import time

# Create a Pin object for the LED.
# Pin.OUT means we will drive the pin as an output (HIGH or LOW).
led = Pin(16, Pin.OUT)

# Run forever (this loop never ends unless you reset the board or stop the program)
while True:
	# Set the pin HIGH (3.3V) -> typically turns the LED ON
	led.value(1)
	print("1")
	# Wait 0.5 seconds with the LED in its current state
	time.sleep(0.5)

	# Set the pin LOW (0V) -> typically turns the LED OFF
	led.value(0)
	print("0")
	# Wait another 0.5 seconds before repeating the loop
	time.sleep(0.5)
					

5) Run and validate

Click the Play button in Thonny to run the script from your computer.

If everything is set up correctly, the LED on GPIO16 will blink every 0.5 seconds, confirming the mockup is working.

6) Run the program automatically at startup

Now that the code works, we can flash it to the MCU so it runs automatically when the ESP32 powers up. Connect the board to your computer, open Thonny, and choose File → Save As… → MicroPython device, then save the script as main.py so it runs at startup. After that, press the reset button (or unplug and reconnect the board), and the LED should begin blinking.

In the script, we added two Python print debugging statements inside the blinking loop: one prints “1” when the LED is set to 1, and the other prints “0” when the LED is set to 0. These messages are sent over USB, so if you start Thonny after the board is powered up and already blinking, the printed values will appear in the Thonny Shell window.

We can also use other serial-port applications, such as PuTTY or Tera Term, to view the print values sent by the flashed script; just remember that only one program can use the USB serial port at a time.

If you want to replace the existing startup program on the ESP32, save your new script to the device as main.py and overwrite the existing file. After saving, press reset (or unplug and reconnect the board), and the new script will run at startup. Occasionally, you may find that you need to reinstall MicroPython from the Thonny options to make this work — if so, remember to hold the BOOT button during installation.

Resources