Raspberry Pi Pico

../_images/Pico.jpg

The Raspberry Pi Pico is a low-cost microcontroller board from the Raspberry Pi Foundation. It supports programming in CircuitPython, MicroPython, and C++. We will be using CircuitPython, which needs to be installed once on each new board.

The Pico has a breadboard-friendly layout and many pins for input and output, but the only built-in I/O device is a single LED. It is our workhorse for building embedded devices and is available as Physcomp Lab part 1005.

Pico 1 Features

The board includes many I/O pins but no on-board sensors. The only I/O device is a single green LED. The core specifications include:

  • Dual-core Arm Cortex M0+ processor, flexible clock running up to 133 MHz. (No hardware floating point.)

  • 264KB of SRAM

  • 2MB of on-board Flash memory (QSPI)

  • USB 1.1 with device and host support

  • 26 × multi-function GPIO pins (3.3V logic)

  • 2 × SPI, 2 × I2C, 2 × UART, 3 × 12-bit ADC, 16 × controllable PWM channels

  • 8 PIO programmable I/O state machine units

  • single green LED on GP25

Pico 1 Pinout Diagram

../_images/Pico-R3-SDK11-Pinout.png

Raspberry Pi Pico diagram of pin functions.

CircuitPython Firmware Installation

The Pico ships with a permanent bootloader in firmware but without CircuitPython onboard. If you take a fresh, new Pico from the parts drawer it will need CircuitPython installed or updated. Installation of the CircuitPython firmware is as easy as copying a file to a USB stick, but there are a few steps to prepare.

The basic process for installing CircuitPython is as follows:

  1. You will need a Raspberry Pi Pico and a USB micro-B cable compatible with your computer.

  2. Download a current stable CircuitPython installer for this particular board. This will be a .uf2 file from https://circuitpython.org/board/raspberry_pi_pico/. Multiple language translations are available.

  3. Locate the white BOOTSEL pushbutton on the Pico. It’s the only switch, on the top side close to the micro-USB connector.

  4. Press and hold BOOTSEL while connecting the USB cable. Note: holding down the switch is not strictly necessary for the very first installation, but is needed to enter firmware mode for subsequent updates.

  5. If successful, a new ‘drive’ will be mounted on your computer as RPI-RP2.

  6. Copy the CircuitPython .uf2 file that you downloaded to this drive RPI-RP2; drag-and-drop works fine.

  7. After a brief delay, RPI-RP2 will disappear, a new ‘drive’ called CIRCUITPY will appear, and a new USB serial port will become available.

After installing the core system, you can test it using your terminal emulator to interact directly with the CircuitPython command line.

CircuitPython Programming

Please see CircuitPython Introduction for a general guide to getting started with CircuitPython. This section will address only the details specific to the Pico.

The Pico plugs into a USB port on your computer using a micro-B USB cable. This has three effects:

  1. the Pico presents itself as a virtual ‘disk drive’ for programming

  2. the Pico provides a virtual serial port for console text interaction

  3. the port powers the Pico enough for computing and sensing (although not actuation)

Now you may try out the course-supplied Pico sample code by copying the corresponding .py file into the CIRCUITPY drive as code.py. A good starting point is Introductory Examples - Raspberry Pi Pico.

For online examples, you can simply cut and paste into code.py using your Python editor. The default behavior is that saving a new version of code.py on CIRCUITPY will trigger a reload and it will immediately run. Syntax errors will generate messages on the serial console.

Note: It is convenient to edit your code directly on the Pico, but please remember to back up your code.py files to a laptop for documentation and reference.

Optional CircuitPython Library Installation

If you wish to install additional modules to support particular hardware, you’ll also need to download a CircuitPython Library Bundle.

Note that the bundle is not specific to the Pico, but the major version must match your CircuitPython firmware version.

  1. Download the matching release of the CircuitPython library bundle from https://circuitpython.org/libraries. This will be .zip file containing a large number of .mpy library files and sample code.

  2. Unpack the zip file in a convenient place on your desktop or laptop. You’ll be installing just a subset of files.

  3. Locate the specific modules withing the lib/ folder of the unpacked zip. These may be individual .mpy files or sub-folders. Copy them as-is into the lib/ folder on your CIRCUITPY drive, preserving any folder structure. For example, adafruit_motor/ is a subfolder containing individual files for several types of motor.

  4. You may also wish to explore the examples/ folder of the zip file. These are Python sources which demonstrate usage of the libraries.

  5. You may need to add additional modules if an installed module has dependencies. The requirements/ folder of the zip has machine-readable specifications which include dependencies.

Tutorials and Information Online

Please see CircuitPython Programming Documentation for general CircuitPython programming information.

The following notes may help guide you to board-specifice Pico information online.

  1. Adafruit Store - Raspberry Pi Pico RP2040. This is the purchasing page at Adafruit, one of many sources for the board.

  2. Raspberry Pi Foundation - Pico-series Microcontrollers. Specifications, MicroPython guide, C/C++ guide, pinouts, design files.

  3. Raspberry Pi Foundation - Pico pinout diagram.

  4. CircuitPython Pico Downloads

Technical Notes

External logic power

Section 4.5 of the Raspberry Pi Pico datasheet addresses powering the Pico directly instead of via micro-USB. The safest way is to use an external Schottky diode to connect the external supply to the VSYS pin. Then the Pico will be powered by either USB or the external supply, whichever has the higher voltage. The recommended supply range is between 2.3 and 5.5V.

Variants

There are now several variants of the Raspberry Pi Pico. Current details can be found at https://www.raspberrypi.com/documentation/microcontrollers/pico-series.html

  • Pico (stocked as lab part 1005: https://ioref.org/parts/1005)

  • Pico H, same but with pre-soldered header pin (also stocked as lab part 1005: https://ioref.org/parts/1005)

  • Pico W, includes WiFi interfaces

  • Pico WH, includes WiFi interface and pre-soldered header pins

  • Pico 2, based on faster RP2350 chip, 520KB memory

  • Pico 2W, also includes a WiFi transceiver