Python on a Pico
You'll run MicroPython on a four-dollar board, blink and read a sensor from the live prompt, and make it run your program on its own at power-up.
About
You don't have to write C to program a board. A Raspberry Pi Pico costs about four dollars, and MicroPython on it gives you a prompt where you type a line and the pin changes before you've hit enter again. That makes trying a new sensor or a new part much faster. The Pico here is a microcontroller; a Raspberry Pi running Linux is a computer, and that lives over in Homelab & Hardware. The catch is that a file called main.py runs at boot, and a bad one can lock you out of the prompt, so you'll learn the way back in.
At a glance
- Per requirement
- 15 XP
- Completion bonus
- 75 XP
- Requirements
- 5
- Takes
- One evening
- Skill level
- Beginner (done it a few times)
- Cost
- Cheap (under $10)
- Supplies
- You need some
- Where
- At home
- Other people
- On your own
Requirements
-
1
Flash the MicroPython firmware onto a Pico or an ESP32. Hold BOOTSEL while you plug the Pico in, drag the .uf2 file onto the drive that appears, and it reboots as a Python board. Thonny is the easiest editor to start with and finds the board by itself. Take a screenshot of the prompt showing the MicroPython version line. Photo
-
2
Blink the onboard LED from the live prompt, one line at a time. Type machine.Pin('LED', machine.Pin.OUT).toggle() and watch it change as you press enter. Then write a for loop at the prompt that blinks it ten times. Film the LED following your typing. Video
-
3
Read a sensor from the prompt and print it as a real unit. Use the ADC on a potentiometer, or the Pico's built-in temperature sensor on ADC channel 4. Convert the raw 16-bit number to volts or degrees with the formula from the Pico datasheet, and print it. Take a screenshot of ten readings. Photo
-
4
Save a program as main.py so it runs with no computer attached. Make it blink a pattern and print a reading once a second. Unplug from the laptop, power it from a phone charger, and see it run. Then plug the laptop back in and get back to the prompt, which means pressing Ctrl-C in Thonny or the terminal; if your loop ignores that, hold BOOTSEL and drag on the flash_nuke .uf2 to wipe it and start again. Film it running from the charger. Video
-
5
Do one thing in Python that would be a chore in C. Build a list of readings and print the max, min and average with one line each, or format a line of text with an f-string, or time a block with time.ticks_ms. Say what it was. Take a screenshot of the code and its output. Photo