Lessons and the learning game

CircuitPython from zero

Learn Python on real hardware with CircuitPython on a Pico: LEDs, buttons, knobs, NeoPixels, an I2C sensor, an OLED, and a mood light you design.

The bench

Every lesson opens one maker bench: a Raspberry Pi Pico running CircuitPython 10.3.1, with

  • a red LED through 220 ohms on GP15
  • a button from GP14 to ground
  • a 10 k knob with its wiper on GP26 (A0)
  • eight NeoPixels (WS2812) on GP16
  • a BME280 sensor and a 128 x 64 SSD1306 OLED sharing I2C on GP4 (SDA) and GP5 (SCL), at 0x76 and 0x3C

Take the course at /learn/path/circuitpython-from-zero on /learn.

How it runs

The Pico runs Adafruit's official CircuitPython firmware, byte for byte, on Mokxi's simulated RP2040. At Run, code.py is saved onto the board's CIRCUITPY drive over its USB, the way a computer saves it, and CircuitPython's auto-reload runs it. The Adafruit libraries a lesson imports (neopixel, adafruit_bme280, adafruit_displayio_ssd1306, adafruit_display_text) are put in lib/ for you. code.py starts printing about two seconds after Run, after CircuitPython's own boot. See CircuitPython on the Pico in Mokxi.

The lessons

  1. code.py. print, a variable, a loop, "Code done running.", auto-reload and the REPL.
  2. digitalio. An LED output, a button input with a pull-up, blinking with time.monotonic() so a press is never missed, and counting presses.
  3. analogio and pwmio. A knob read as 0 to 65535 and as volts, and an LED dimmed by PWM duty cycle.
  4. NeoPixels. Color tuples, fill, single pixels, show(), a chase, and how much power a strip draws.
  5. I2C sensors. A bus scan, a BME280's temperature, humidity and pressure, and Fahrenheit.
  6. displayio basics. A display, a Group of Labels, the terminal font, scale, and text that redraws itself.
  7. Project: a mood light. A knob for the color, a button for the mode (glow, breathe, rainbow, off), a heat warning from the BME280, and the OLED showing what it is doing.

Honest limits

  • The sensor and knob values are the ones you set on the parts; there is no room to measure.
  • The first second of each run is CircuitPython's safe-mode window, as on a real board, so code.py prints about two seconds in.
  • NeoPixel power is not drawn from a real supply: the course explains the current a real strip needs.

Touch apps on the Cheap Yellow Display, another beginner embedded course.