This is only a preview of the December 2021 issue of Silicon Chip. You can view 40 of the 112 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Articles in this series:
Items relevant to "Hummingbird Audio Amplifier":
Items relevant to "SMD Trainer Board":
Articles in this series:
Items relevant to "Digital Lighting Controller Translator":
Items relevant to "USB Cable Tester – Part 2":
Purchase a printed copy of this issue for $11.50. |
Hands-on with Tim Blythman
Raspberry Pi is a trademark of the
Raspberry Pi Foundation
The Raspberry Pi
Pico Microcontroller
The Raspberry Pi Foundation (www.raspberrypi.org) is well known for
its range of inexpensive single-board computers, firmly aimed at the
educational market but used by many others. Now they have released a
very low-cost microcontroller board with an interesting set of peripherals.
O
ver the last ten or so years, the
Raspberry Pi Foundation has continued to surprise us (in a good way)
with their range of Raspberry Pi SBCs
(single-board computers). These tiny
boards have been used from embedded
applications through to fully-fledged
desktop machines.
Over 30 million units have been sold
since they were introduced, undoubtedly helped by very attractive pricing.
We have reviewed several of these,
including the model 3B+ (July 2018;
siliconchip.com.au/Article/11141)
and the 4B (August 2019; siliconchip.
com.au/Article/11772).
These boards can run the Raspberry
Pi Foundation’s Linux-based desktop operating system, now known as
Raspberry Pi OS. Earlier versions were
known as ‘Raspbian’ as a nod to their
Debian Linux roots. In addition, other
third-party operating systems have
been produced and ported to the various Raspberry Pi computers.
Some operating systems turn these
boards into media centres or retro gaming consoles. However, the boards’
target price of US$35 (currently about
$46) also means that they are well
suited for their primary intended use
as an educational computer.
The minimalist Raspberry Pi Zero
boards can be had for under $10; we
used one in our Speech Synthesiser
48
Silicon Chip
from July 2019 (siliconchip.com.au/
Article/11703). It’s incredible that
something as powerful as a desktop
computer from around twenty years
ago can be so small and cheap.
Pico board
However, the new Raspberry Pi Pico
cannot be used as a desktop computer;
it is a microcontroller board featuring the Raspberry Pi Foundation’s
own RP2040 microcontroller. Still, it
echoes the philosophy of other Raspberry Pi products.
The claimed target price is US$4,
and we purchased our units from DigiKey and Core Electronics for roughly
the equivalent in Australian currency
(excluding shipping) of about $5.25.
Unfortunately, being so cheap has
meant that there have been minor
delays in obtaining the Pico, presumably due to high demand as well as
the ongoing chip shortages.
They are also now available from
Altronics. The low price also means
that it should find a good following
in the educational sector and various
Like many other microcontroller boards, the Pico is suited to breadboard use,
although it does not come with header pins. This is a cost-saving measure that
we have seen on other Raspberry Pi products like the Pi Zero. We have fitted the
three-pin SWD header with right-angled pins at the opposite end to the microUSB socket.
Australia’s electronics magazine
siliconchip.com.au
Board
Used in
Clock
RP2040
ESP8266
ESP32
PIC32MX470
SAMD21
Pico
D1 Mini
Various
modules
Micromite
Plus
Arduino
MKR
133MHz
160MHz
240MHz
120MHz
48MHz
RAM
264kB
80kB
520kB
128kB
32kB
Flash
external
(2MB)
external
(4MB)
up to 4MB
512kB
256kB
Cores
2 x ARM
1 x Tensilica
2 x Xtensa
LX6
1 x MIPS
1 x ARM
Pins
56
32
48
64
48
GPIO
30
11
34
45
22
UART
2
1
3
4
1
SPI
2
1
4
2
1
I2C
2
software only
2
2
1
PWM
16
software only
16
5
12
ADC
4 x 12-bit
1 x 10-bit
18 x 12-bit
28 x 10-bit
7 x 12-bit
USB
host/device
no
OTG
host/device
host/device
no
WiFi
WiFi &
Bluetooth
no
no
Radio
Table 1: how the Raspberry Pi Pico (RP2040) compares to other ‘similar’
microcontroller chips.
other diverse fields, as we have seen
with the other Raspberry Pi products.
The RP2040 chip
The basic specs of this chip are
shown in Table 1, compared to some
other familiar parts.
The Pico’s RP2040 microcontroller
was designed internally by the Raspberry Pi Foundation.
This not only helps to keep the cost
down, but it also allows the chip to
be customised, and we will elaborate
later on the interesting and unusual
peripherals that have been incorporated as a result.
The RP2040 is based on the ARM
Cortex M0+. Boards such as the Arduino Zero and MKR series also sport
such a processor; it is well-established.
It is a 32-bit processor and, as is fairly
typical for those, runs from 3.3V.
The chip does not have internal
flash memory, instead needing an
external serial flash chip. Thus, various flash memory sizes can be provided by simply changing the external flash. An internal cache means
that the flash speed does not typically
limit the processor’s operating speed,
and there is an option to copy and run
code from RAM.
The chip does have 16kB of internal
boot mask ROM. This includes ‘bootstrap’ code which initialises the chip
siliconchip.com.au
and can download firmware to the
flash chip via USB flash drive emulation. It also provides some optimised
floating-point, bit manipulation and
memory functions.
You can download the full (600+
page) data sheet which explains all this
from siliconchip.com.au/link/abab
Peripherals
The RP2040 features a single-cycle
hardware multiplier, dual processor
cores and a DMA peripheral. All of
these are handy for implementing
signal processing type applications,
amongst other things.
While there are 36 pins that could be
used for general-purpose I/O (GPIO),
six of these are generally used for the
flash memory interface (in four-bit
QSPI mode), leaving 30 for practical
use. Four of these remaining pins are
connected to the analog-to-digital converter (ADC) peripheral, and can be
used as analog inputs.
Broadly, any of these 30 pins can
be used with just about any digital
peripheral (such as SPI, I2C, PWM or
UART), but each pin only in specific
roles and grouped as such. This is similar to the PIC32 peripheral pin select
(PPS) system.
Each physical pin also has so-called
‘pad’ settings that control features
such as drive strength, slew rate,
Australia’s electronics magazine
The Tiny 2040 board (shown at
triple actual size) might be worth
considering if you need a smaller
device with fewer pins. Despite its
smaller size (18 x 21mm), it was more
expensive than the Pico due to the
way the Raspberry Pi Foundation
discounts its products.
input levels, pull-ups and pull-downs.
These work independently of the
peripheral that is driving the pin.
There is a USB peripheral that supports both device (full-speed) and host
(full-speed and low speed) modes.
At the Pico’s price, we can see it
being used simply as a USB ‘widget’;
for example, emulating a keyboard,
mouse or other simple devices such
as a serial port.
PIO
Probably the most interesting
peripheral is the PIO or programmable
input-output block. It could almost be
considered to be a unique microprocessor optimised for input and output
functions.
Rather than having its function set
by registers, each PIO block is controlled by a state machine with a
small program that can be changed
at runtime.
We’ve already seen people using the
PIOs to generate HDMI-compatible DVI
video signals (with some processor
overclocking), so it is very versatile.
There are examples at https://github.
com/raspberrypi/pico-examples/tree/
master/pio, including driving devices
like WS2812 serial LEDs and HUB75
LED matrices. There are also examples
to reproduce standard peripheral functions such as SPI and UART.
December 2021 49
The Pico board
The Pico board measures 51 x
21mm, with a micro-USB socket at
one end and a 3-pin serial wire debug
(SWD) header at the other. The two
sides are lined with 20-way castellated
vias. As expected at the price point,
none of the headers are populated.
Apart from the RP2040 IC and its
surrounding passive components,
a 3.3V switchmode regulator (surrounded by the necessary passives)
provides power for the board. The
dual-mode (PWM/PFM) regulator can
be controlled by the micro via GPIO23.
A tactile pushbutton is used to enter
bootloader mode at reset. There are no
other buttons to effect a reset, so the
simplest way to start the bootloader
is to hold the button while plugging
in the board.
A solitary LED and its series resistor are connected to GPIO25, while
you can use a divider connected to
GPIO24 to detect the presence of USB
power. Thus the full complement of
I/O pins are not brought out to external headers.
A 12MHz crystal and the flash chip
in an 8-pin leadless package round out
the component list. There are six test
pads on the back of the PCB, along
with a QR code, which appears to be
a serial number. The back of the PCB
also has the I/O pin labels.
Four holes to suit M2 machine
screws are present. The board is suitable for use with a breadboard by soldering on headers, mounting in an
enclosure via the holes or even soldering to a larger carrier board.
In short, the board is not overly
adorned but has been well-designed
to suit a wide range of purposes and
end-users. For the price, we cannot
complain.
But wait, there’s more
In addition to the Pico, the Raspberry Pi Foundation is also making bare RP2040 chips available for
sale. In addition to this, several other
boards are available with the same
microcontroller, including some made
by Sparkfun and Adafruit.
Many of these boards have opensource schematics (the Pico’s is in its
30-page data sheet), so creating your
own variant won’t be too hard, if you
don’t mind soldering QFN parts!
There is also an Arduino “Nano
RP2040 Connect” board, including
a WiFi chip. It isn’t as cheap as the
Raspberry Pi Pico, but it’s good to see
such broad support for the new chip.
Programming
As noted earlier, the bootloader
ROM on the RP2040 provides a USB
interface when the Pico is started with
the bootloader button pressed.
This shows up as a virtual USB
drive, as seen in Fig.1. It’s not a real
drive that can load and save files, but
it does provide two small files for reference.
We saw a similar system on the Curiosity Nano AVR128DA48 board we
reviewed (January 2021; siliconchip.
com.au/Article/14696). This allows
programming (or uploading firmware)
by a simple drag-and-drop process.
The Pico is the same, although it
uses the so-called UF2 file format
rather than the HEX file that is otherwise commonly used. The UF2 format has been designed by Microsoft
to make uploading simple for both
the user and the microcontroller. It
is documented at https://github.com/
microsoft/uf2
Probably the most significant consequence of this arrangement is that
it is practically impossible to ‘brick’
the Pico. The USB interface is defined
in an immutable ROM and can be
accessed by keeping the bootloader
pin low at reset or power-up.
More info can be found at www.
raspberrypi.org/documentation/
rp2040 including guides to getting
started and various data sheets. Much
of the software is open source, and
there are also third-party tools becoming available; we’ll mention those that
we found useful.
Silicon Chip
When we first obtained our boards,
there were two main ways of programming the Pico provided by the Raspberry Pi Foundation. The first of these
is Micropython. The Python language
is provided with many Raspberry Pi
OS distributions.
It’s also possible to set up a compiled C environment. This is a bit
more involved, both regarding setup
and use, but it appears some people
have created an installer to simplify
the setup process. Even so, a lot of
command-line interaction is needed.
More recently, there is now also
an Arduino Boards Manager add-on
which means that the Pico (and other
RP2040-based boards) can be programmed through the Arduino IDE.
Micropython
Micropython is a subset of the
Python 3 programming language that
is optimised for microcontrollers. Programming with Micropython is a bit
like programming with MMBasic on
the Micromite.
It includes a read-evaluate-print
loop (REPL) prompt, similar to many
older home computers. You can type
single commands and see their immediate effect or enter complex programs
and run them. You can also develop
code in a PC-based IDE (integrated
development environment) and then
run the program on the Micropython
hardware.
The Pico is not the only board that
can run Micropython; many 32-bit
boards (especially those with ARM
processors) can do so, as can the
ESP8266 and ESP32.
One advantage of Micropython (and
other Python variants) over BASIC
is that the Python language is standardised, so it is easier to find and
write libraries that can be imported.
This, in turn, makes it potentially more
powerful, versatile and portable.
Micropython implements a simple
filesystem on the flash chip to allow
user programs to be installed and extra
Fig.1: when the Pico’s
bootloader is active and it’s
plugged into a USB port, it
appears as a virtual drive to
which you can copy a firmware
file. The bootloader code is in
a mask ROM baked into the
RP2040 microcontroller at the
factory, so all RP2040-based
boards should have this feature.
The Raspberry Pi Pico is built on a
tiny 51 x 21mm board and is shown at
actual size above.
50
Software
Australia’s electronics magazine
siliconchip.com.au
libraries and other files to be loaded.
With ample flash available, the Pico is
well-suited to this role.
Getting started with Micropython on
the Pico is a simple case of loading the
UF2 firmware file and then opening a
serial terminal program to interface to
the serial port, where the REPL prompt
and interaction occur.
Fig.2 shows several commands
being issued at the prompt, including one to list the included modules.
A module is what might be called a
library file in other languages. For
example, the “machine” module supports various I/O functions, including the ADC, pulse-width modulation
(PWM) and communication peripherals such as SPI and I2C.
You can find more information
about Micropython and the UF2 files
needed to run Micropython on the Pico
at https://micropython.org/download/
rp2-pico/
Example Micropython code for the
Pico can be found at https://github.
com/micropython/micropython/tree/
master/examples/rp2
Note that the RP2 designation is the
superset of microcontrollers which
includes the RP2040 used in the Pico.
Fig.2: Micropython will run on the Pico. It has an interactive prompt and a
flash-based filesystem that can hold user programs and libraries. Although the
language is a subset of Python, the overall feel is similar to BASIC computers
like the Micromite.
Fig.3: utilities
like the Project
Generator make
C development
quite easy once
the environment
is set up. Many
compiler options
are hidden by
simply using
the “nmake”
command to
initiate the
compilation
process.
C language SDK
Most of the microcontroller programming that we do is in the C language, typically on PIC microcontrollers using the MPLAB X IDE, so we
were keen to see how useful and easy
this would be. It is very much dependent on working with a command
prompt. We found a few GUI tools to
help set up projects, but you need to
provide your own text editor.
The documentation page has links
for the C SDK (software development
kit) in a GitHub repository and a script
for setting this up on a Raspberry Pi
and other Linux computers. It also
includes several example programs.
The SDK requires various other programs to be installed to provide a complete development environment, and
we were not able to set this up successfully on a Windows PC. However,
this appeared to be a problem with just
one of the necessary programs, which
hopefully has been fixed by the time
this article is published.
Fortunately, someone has bundled
together all the necessary components
in a simple installer, which you can
find at https://github.com/ndabas/
pico-setup-windows
siliconchip.com.au
We recommend this alternative for
those who are comfortable programming in an IDE, unless you are familiar with manually setting up compiler
toolchains.
This also installs some example programs and a project generator utility.
This utility is used to set compiler
options beyond what can be configured by the source code.
This is shown in Fig.3; it is started
with the “pico_project.py –gui” command from the pico-project-generator
folder.
Australia’s electronics magazine
There is also a “pico-env.cmd” file
that can be used to set up a prompt
with the appropriate environment
variables. We found it handy to create
shortcuts to these two utilities, as we
were accessing them often.
After doing that, we had no trouble copying bits and pieces from the
example code into our generated C
file. Then, to compile it, we changed
to the “build” subdirectory and ran the
“nmake” command. This resulted in
a UF2 file in the build subdirectory,
ready for uploading.
December 2021 51
We haven’t tried it but we expect
that for those who have installed
the SDK on a Raspberry Pi or other
Linux machine, the experience will
be much the same, perhaps except
for the use of “make” instead of Microsoft’s “nmake”.
Arduino
The Arduino Team has recently
released the Arduino Nano RP2040
Connect board, although we have
not tested it yet. We think this will
be a handy board, as it will incorporate the NINA-W102 WiFi and Bluetooth radio module, as seen in several
other Arduino boards. That includes
the MKR Vidor, which we reviewed
in March 2019 (siliconchip.com.au/
Article/11448)
They also announced that the Arduino IDE (specifically, the Boards Manager) would support other RP2040
based boards, including the Pico. In
fact, this support is already available,
so we were able to test out programming the Pico using the Arduino IDE.
This is as simple as searching for
“RP2040” in the Boards Manager and
installing the “Arduino Mbed OS
RP2040 boards”. Mbed OS is a platform for developing on ARM microcontrollers.
We found an interesting catch-22
while trying to use this board profile.
It assumes that each board is assigned
a serial port for programming.
This is not necessarily the case with
a new Pico and definitely not in bootloader mode.
Once a sketch has been uploaded,
it includes a serial port, but the difficulty is in performing the first upload.
We found the easiest way to get around
this was to use the Sketch → Export
Compiled Binary option to generate
a UF2 file, then use the bootloader to
install it.
After this, we could see and select a
serial port as for other Arduino boards.
Sometimes the port number changed,
but that was easy to fix.
As an aside, we found another
board variant at https://github.com/
earlephilhower/arduino-pico which
also circumvents this problem. It is a
third-party board profile that builds
the binary using the C SDK that we
mentioned earlier.
Cleverly, it does not require a serial
port for uploading, but can detect the
presence of the virtual USB drive
that the Pico’s bootloader creates and
52
Silicon Chip
uploads the file that way. Thus it’s
another handy way to rescue boards
that the Arduino IDE otherwise can’t
recognise.
You can install it by adding a link
to https://github.com/earlephilhower/
arduino-pico/releases/download/
global/package_rp2040_index.json in
the Boards Manager Preferences.
The window shown in Fig.4 includes
the two board profiles that we tried.
This version also includes support
for some Picoprobe boards, as well as
a board from Adafruit.
Picoprobe
A Picoprobe is essentially a Pico
programmed with firmware that
allows it to behave like an ARM SWD
debugger and a USB-serial converter.
As we noted in our review in June 2021
(siliconchip.com.au/Article/14890),
the Arduino 2.0 IDE can perform
in-circuit debugging, but requires a
probe; it appears that the Picoprobe
can fill that role.
There are examples showing how
one Pico can be used to debug another.
Since many debugging interfaces can
also be used for programming, the
Picoprobe variants described use the
Picoprobe interface instead of the
serial port for programming.
Other boards
Apart from the Arduino Nano
RP2040 Connect that we mentioned,
there is also the Adafruit Feather
RP2040, plus variants from Sparkfun
and Pimoroni. We managed to get one
of the Pimoroni boards, called the Tiny
2040, as seen in our photo.
But it appears that demand is high
for these very cheap boards, and supplies are being snapped up as soon as
they become available.
No doubt, these circumstances
aren’t helped by current chip shortages.
Conclusion
Like the Raspberry Pi single-board
computers, the Pico microcontroller
board offers exceptional value and
ease of use. The sheer number of ways
that it can be easily programmed is
pleasing to see.
Assuming that supply can keep up
with demand, we do not doubt that
the Pico and other RP2040 variants
will be used not just for education,
but just about anywhere that a 32-bit
microcontroller is needed.
With HDMI-compatible video
already being coaxed from the chip
and native USB support, it is not a
stretch to imagine people tacking this
board onto a project for these peripherals alone. So like the Raspberry Pi,
it will see a variety of uses.
The Pico, as well as numerous other
RP2040-based boards and accessories,
are available (subject to supply constraints) from:
• Altronics: siliconchip.com.au/
link/aba8
• Core Electronics: siliconchip.
com.au/link/aba9
• Digi-Key: siliconchip.com.au/
SC
link/abaa
Fig.4: we tried two different Arduino board profiles for working with RP2040
boards like the Pico. The Arduino team has also announced the Arduino Nano
RP2040 Connect board, which will include a WiFi chip like many other recent
Arduino boards.
Australia’s electronics magazine
siliconchip.com.au
|