Lesson plan

MicroPython on the ESP32 lesson plan

Python on an ESP32 DevKit: the REPL and blink, pins and PWM, the ADC, timers and interrupts, I2C sensors, WiFi in five lines, and a lamp you switch from a web page.

4 chapters, 7 lessons, about 5 hours, on the ESP32 DevKit V1. Every lesson runs in the browser, with nothing to install.

The unit

Objectives and materials

By the end, students can

  • Blink and the REPL, then buttons and PWM brightness.
  • Read a knob with the ADC, and let timers and interrupts do the waiting.
  • Two chips on I2C, then WiFi, JSON and HTTP.
  • A web lamp with a button, a socket server and a self-test.

Materials for the whole unit

  • ESP32 DevKit V1
  • LED x 2
  • OLED display, 128x64
  • Potentiometer
  • Pressure, humidity and temperature, BME280
  • Pushbutton
  • Resistor x 2

Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.

Chapter 1. About 1 h 30 min

First Python on the ESP32

Blink and the REPL, then buttons and PWM brightness.

LessonTimeWhat students do
REPL and blinkBlink an LED from main.py, then type Python straight into the ESP32: math, a pin by hand, and a question for the chip itself.45 min
  1. Run it
  2. print() talks back
  3. The REPL
  4. A pin by hand
  5. Ask the chip
  6. Your turn: faster
Pins and PWMRead a button with the pin’s own pull-up, catch the moment it is pressed, and set an LED to any brightness with PWM.45 min
  1. Run it
  2. Press it
  3. PWM is fast blinking
  4. Predict the reading
  5. Why % and //
  6. Your levels

Materials

  • ESP32 DevKit V1
  • LED x 2
  • Pushbutton
  • Resistor x 2

Check for understanding

Each student finishes "Pins and PWM" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Your levels".

Chapter 2. About 1 h 30 min

Sensors and time

Read a knob with the ADC, and let timers and interrupts do the waiting.

LessonTimeWhat students do
The ADC: volts in, numbers outA knob makes a voltage, the ADC turns it into a number, and that number drives an LED. Then the trap every ESP32 beginner falls in: attenuation.45 min
  1. Run it
  2. All the way down
  3. Predict the middle
  4. The attenuation trap
  5. Honest numbers
  6. Your turn: a percent
Timers and interruptsA hardware timer blinks an LED on its own, an interrupt counts button presses the instant they happen, and you meet contact bounce and beat it.45 min
  1. Run it
  2. Count the ticks
  3. Faster
  4. An interrupt per press
  5. Bounce
  6. Beat the bounce

Materials

  • ESP32 DevKit V1
  • LED
  • Potentiometer
  • Pushbutton
  • Resistor

Check for understanding

Each student finishes "Timers and interrupts" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Beat the bounce".

Chapter 3. About 1 h 30 min

Buses and networks

Two chips on I2C, then WiFi, JSON and HTTP.

LessonTimeWhat students do
I2C sensorsTwo chips share two wires: scan the bus, read a register by hand, turn a BME280’s raw numbers into weather, and draw it on an OLED.45 min
  1. Scan the bus
  2. Weather in numbers
  3. Make it hot
  4. The screen
  5. Read a register yourself
  6. Your turn: an alarm
WiFi in five linesJoin a network, get an address, read the signal, fetch JSON from a server, post your own, and see what a wrong password looks like.45 min
  1. Join the network
  2. Signal strength
  3. Fetch JSON
  4. Post your own
  5. A wrong password
  6. Your turn: what time is it?

Materials

  • ESP32 DevKit V1
  • OLED display, 128x64
  • Pressure, humidity and temperature, BME280

Check for understanding

Each student finishes "WiFi in five lines" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Your turn: what time is it?".

Chapter 4. About 45 min

Project

A web lamp with a button, a socket server and a self-test.

LessonTimeWhat students do
Project: a web lampEverything at once: a socket server on port 80, a page that switches a lamp, a button that does too, and a self-test that proves the logic before the server starts.45 min
  1. Run it
  2. Test before you serve
  3. The button still works
  4. Switch it from the web
  5. Add a route, test first
  6. Make it yours

Materials

  • ESP32 DevKit V1
  • LED
  • Pushbutton
  • Resistor

Check for understanding

Each student finishes "Project: a web lamp" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Make it yours".

Your class

Teach this unit as a class

Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.

The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.