Stage 2 of 6 · Theory then bench · about 35 minutes
Meet the ESP32
A complete computer the size of a stick of gum, with Wi-Fi, for the price of a sandwich. This page explains what kind of thing that is, where it sits in the system you are building, and how to get it blinking under your own Python before the hour is out.
Two kinds of computer
A single-board computer like the Pi and a microcontroller like the ESP32 are both "computers", and engineering treats them as different species because every number in their comparison differs by orders of magnitude:
| Raspberry Pi (single-board computer) | ESP32 (microcontroller) | |
|---|---|---|
| Processor | Multi-core, GHz class | Dual-core, 240 MHz |
| Memory | Gigabytes of RAM | About half a megabyte of RAM |
| Storage | Removable drive, gigabytes | A few megabytes of flash, on-chip |
| Software model | An operating system runs many programs | Your program is the only program; no OS beneath it |
| Start-up | Boot chain, ~half a minute (Week 2) | Running in under a second |
| Power | Watts | Tens of milliamps working; microamps asleep |
| Analog input | None | Many ADC channels, on-chip |
| Radio | Wi-Fi and Bluetooth | Wi-Fi and Bluetooth, on the same chip |
| Cost and size | Tens of dollars, credit card | A few dollars, postage stamp (module itself) |
| Natural role | Hub: storage, services, dashboards, heavy logic | Node: sensing and acting at the physical edge |
Read the table as trade-offs, not rankings. The Pi's operating system is why it can run Mosquitto, Flask and your control app at once, and also why it boots slowly and burns power; the ESP32's bareness is why it starts instantly and runs on next to nothing, and also why it will never host your dashboard. The row that forces this week's hand is analog input: the Pi simply has no ADC, so "how bright is it?" is a question the ESP32 answers and the Pi cannot. Background on the species: microcontroller and ESP32; the chip's maker documents it at Espressif's product page.
Node and hub: you are here
The board, part by part
Your kit's board is an ESP32 DevKit: the ESP32 module itself plus everything needed to develop on it comfortably. A tour, metal side up:
- The module with the antenna (the metal can and the zigzag trace at one end): the actual ESP32, its flash chip and the printed Wi-Fi antenna. Keep fingers and wires off the antenna end when the radio matters, from next week on.
- The USB connector and its bridge chip: USB carries 5 V power and a serial data line; a small bridge chip (CP210x or CH340, board depending) translates USB to the chip's serial port. Your laptop sees it as a "COM port" or
/dev/tty..., and that is the REPL's road in. No port appearing usually means a power-only cable or a missing bridge driver. - The 3.3 V regulator: the board takes USB's 5 V and makes the 3.3 V everything runs at. Week 4's rule 1 carries over verbatim: the logic is 3.3 V, never put 5 V on a GPIO pin, and the 5 V pin (often marked VIN) feeds the regulator, not your circuits.
- EN and BOOT buttons: EN resets the chip (a fresh start without unplugging); BOOT, held during a connection attempt, puts the chip in firmware-download mode. You may never need BOOT; Thonny usually manages it, and the troubleshoot page says when to press it yourself.
- The pin headers: GPIO, power and ground rows that plug straight into your breadboard. This week's cast:
3V3andGNDfor the circuits, GPIO2 (most DevKits wire the onboard LED here), GPIO25 for the external LED, GPIO34 for the light reading. One family trait to respect now: GPIO 34 to 39 are input-only, perfect for sensing, useless for driving anything.
Boards vary in detail (pin count, bridge chip, LED pin); the MicroPython ESP32 quick reference is the course's settling authority, the way pinout.xyz was for the Pi.
Firmware, and MicroPython as firmware
On the Pi, Week 2's boot chain ended in an operating system that then loads programs; on a microcontroller there is no such chain. Whatever sits in the chip's flash memory is the machine's entire behaviour, running directly at power-on: that program is called firmware. Normally firmware is compiled C, rebuilt and reflashed for every change. MicroPython is the move that makes this course possible: a firmware whose job is to be a Python interpreter, with a tiny filesystem for your scripts. Flash it once, and from then on "changing the firmware's behaviour" means editing a Python file, exactly the workflow you already own. It is a lean reimplementation of Python 3 for machines with kilobytes, not gigabytes: the language is the one you know; the standard library is a careful subset; and a new module, machine, exposes the chip's pins and peripherals (reference).
Flashing with Thonny
Cable and port
Connect the board with a USB data cable. A power LED lights; your laptop gains a serial port. No port after a minute: switch cables first, then install the bridge driver named on the troubleshoot table.
Point Thonny at the board
In Thonny: Tools → Options → Interpreter, choose MicroPython (ESP32) and the board's port. Thonny is the same editor from Week 4; only the interpreter choice is new.
Install the firmware
Use the interpreter dialog's install or update MicroPython option, which downloads the official firmware and flashes it over the cable (the independent route, downloading from micropython.org/download and flashing with esptool, does the same thing by hand). A progress bar, a couple of minutes, done; this is a once-per-board event.
Meet the REPL
The Shell pane shows a MicroPython banner and the familiar
>>>. That prompt runs on the ESP32, reached over the serial line: the same live-conversation REPL as Week 4, with a new machine on the other end.2 + 2to say hello.
First blink, from the REPL
>>> from machine import Pin
>>> led = Pin(2, Pin.OUT)
>>> led.on()
>>> led.off()
The onboard LED answers (on a few boards it is wired inverted, so on and off swap; the lesson survives). Read the line with Week 6 eyes: Pin is a class, Pin(2, Pin.OUT) a constructor call with two facts, led an instance with methods. Then the loop, as a script this time, pasted into Thonny's editor and run:
from machine import Pin
from time import sleep
led = Pin(2, Pin.OUT)
while True:
led.on()
sleep(0.5)
led.off()
sleep(0.5)
time.sleep survives the trip to MicroPython unchanged. Ctrl+C in the Shell interrupts the loop and returns the prompt, the serial REPL's version of a habit you already have.
MicroPython vs the Python you know
| Topic | On the Pi (Weeks 4 to 6) | On the ESP32 (from today) |
|---|---|---|
| The language | Python 3 | The same language: your constructs, functions and classes run as-is |
| Pins | gpiozero: LED(17).on(), padded and friendly | machine: Pin(2, Pin.OUT).on(), one thin layer above the chip |
| Where code runs | A process among many, on Linux | The only program on the chip |
| Reaching it | SSH over the network | Serial REPL over USB (the network comes Week 9) |
| Libraries | Full standard library, pip, venvs | A curated subset plus machine, network; no pip or venv on the board |
| Files | The Pi's Linux filesystem | A small on-chip filesystem; Thonny's Files view uploads and downloads |
| Memory | Effectively unlimited for our scripts | Hundreds of kilobytes: plenty for this course, worth respecting |
main.py: the board becomes an appliance
Save a script to the device (Thonny: File → Save as → MicroPython device) under the name main.py, and MicroPython runs it automatically at every power-up, laptop or no laptop. Plug the board into any USB charger and your blink runs forever: the moment a script becomes main.py, the board stops being a peripheral and becomes an appliance, which is the whole microcontroller idea in one file name. Two habits from day one: keep the canonical copy of every board script in your Git repository and upload working versions, the board's filesystem is a deployment target, not your archive; and remember that a main.py with an infinite loop keeps the REPL busy, Ctrl+C interrupts it when the cable returns.
Checklist for this stage
Check yourself
The Pi has gigabytes and gigahertz; why does the course add a machine with half a megabyte?
Define firmware in one sentence, and say what is unusual about MicroPython as firmware.
Week 4's REPL and today's REPL: same idea, different what?
Why does rule 1 (3.3 V logic) survive the change of boards, when the board visibly accepts 5 V USB?
Your blink script works in Thonny but the board does nothing on a USB charger. Most likely explanation?
main.py: it ran from the editor session only. Autostart requires the file, with that exact name, on the board's own filesystem.Read led = Pin(2, Pin.OUT) with Week 6 vocabulary.
Pin is the class; Pin(2, Pin.OUT) is a constructor call supplying the two facts this instance cannot invent (which pin, which direction); led names the instance, whose methods (on, off, value) act on its own state. gpiozero and machine differ in padding, not in model.