Getting Started With Micropython On The Raspberry Pi Pico
Getting Started With Micropython On The Raspberry Pi Pico
Getting Started With Micropython On The Raspberry Pi Pico
MicroPython
on the
Raspberry Pi Pico
Not a Linux machine:
a microcontroller
Custom silicon, designed by
Raspberry Pi Foundation
Lots of I/O
Great documentation
$5.25 🇨🇦, any qty.
Arduino killer
Image credit: Raspberry Pi Foundation
RP2040 Overview
Dual-core ARM Cortex-M0+ at
133 MHz
264 KB RAM
No Flash storage
(Pico has 2 MB external)
26 × multi-function GPIO pins
2 × SPI, 2 × I2C, 2 × UART, 3 ×
12-bit ADC, 16 × PWM
8 × PIO state machines
Image credit: Raspberry Pi Foundation
So where do I get one?
In theory, you can buy as many
My Canada Post experience
as you want, but:
BuyaPi: ordered Jan 21, arrived
BuyaPi: Sold Out Feb 2.
Canakit: Sold Out Average speed: house spider
(preorders ship Feb 28)
Elmwood: ordered Jan 27,
Elmwood: Sold Out arrived Feb 3.
Newark, Digikey: on order Average speed: 3-toed sloth
Don’t use Canada Post
because 😷
What is MicroPython?
Python 3 implementation
Small: 256 KB flash, 16 KB RAM
(minimum)
Compiled on-chip; standalone
Subset of standard Python library
Core developers were hired to
implement for Pico
Now includes ARMv6M assembler
micropython.org
MicroPython Differences
System libraries are typically limited, e.g.:
Strings are always UTF-8; 8-bit codecs excluded
Time is monotonic (fractional) seconds: no timezones or DST
No CSV, numpy, pip (→ upip), …
.py → .mpy (like .pyc) compilation isn’t automatic
Hardware interface modules:
machine: for hardware features like pins, PWM, I²C, ADC, …
rp2: RP2040 PIO assembler, raw Flash access
help() docstrings short or absent: see online docs
Flashing MicroPython
Pico firmware is distributed as
UF2 images
Hold BOOTSEL while plugging
in
Pico appears as a USB storage
device
Drag/copy UF2 to PICO storage
Pico reboots; USB disappears
Raspberry Pi Foundation’s
recommended editor
Installed by default
Includes loading/saving to Pico
flash
Has a simple graph tool
… plus firmware updater
… and (Raspberry) REPL
sorry not sorry
(and no, I don’t know why the graph broke)
“but my $EDITOR …!!1!”
You don’t have to use Thonny
… it’s just more work if you don’t.
The command-line MicroPython tool with REPL access is rshell:
https://github.com/dhylands/rshell/tree/pico
Make sure you get the this branch, as it handles the quirks of the
Pico’s RTC
… and yes, the Foundation has shipped yet another device which
doesn’t have battery backup on its clock ☹
All of the Pins
raspberrypi.org/documentation/pico/getting-started
Documentation
This is absolutely stellar for a board at launch + 3 weeks
Data sheets, API guides, code, Fritzing parts … all at
raspberrypi.org/documentation/pico/getting-started
Unexpected Quirks
It’s a new board, and folks are just learning, but:
Trevor Woerner used an MCP3008 with a thermistor and Raspberry Pi
last month:
Let’s use a Pico
… which is cheaper than
an MCP3008 (by 50¢ !)
… and can act as a serial
datalogger, perhaps
writing to a Raspberry Pi over USB serial.
Image credit: Trevor Woerner
twoerner.blogspot.com/2021/01/sensing-temperature-with-raspberrypi.html
Wiring
Pins used:
ADC2 (pin 34)
3V3 (pin 36)
AGND (pin 33)
10 kΩ resistor between 3V3 and
thermistor
10 kΩ @ 25 °C thermistor, β =
3950