© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
C. BellBeginning MicroPython with the Raspberry Pi Picohttps://doi.org/10.1007/978-1-4842-8135-2_1

1. Introducing the Raspberry Pi Pico

Charles Bell1  
Warsaw, VA, USA

The Raspberry Pi foundation (raspberrypi.org) has changed the world by providing powerful, low-cost computer boards. The Raspberry Pi is by far the biggest selling and most popular of the many small computer boards available. Perhaps even more important is the Raspberry Pi is designed for education. Educators can use the Raspberry Pi to teach computer science, electronics, hardware automation, and Internet of Things (IoT) projects using Python, Java, or C++ programming languages.

Better still, the ability to run a powerful desktop operating system means you can use a Raspberry Pi just like your laptop or desktop to build your project and connect it to other hardware via the general-purpose input/output (GPIO) pins. With those accolades, it was only a matter of time before the Raspberry Pi foundation extended their global dominance.

The Raspberry Pi Pico is a departure from the dominance of the Raspberry Pi small computer boards because it isn’t another small computer board. So, it doesn’t have the ability to run an operating system, and there are no video ports, no USB host ports, or even a power connector. Rather, the Raspberry Pi Pico is the first microcontroller to use a small Raspberry Pi–based chip (RP2040). Better still, the cost of the Pico is a mere $4.00, and the RP2040 itself is only $1.00.

Why is this important? It means the Raspberry Pi is one of the newest contenders in the microcontroller field, and, as we will see, the Raspberry Pi foundation has risen to the challenge with a very powerful, very affordable microcontroller that runs one of the world’s most popular programming environments – MicroPython (Python for microcontrollers) – making the Raspberry Pi Pico easy to program and easier to use.

In this chapter, we will learn what makes the Pico different from the Raspberry Pi boards, what a microcontroller is, and a demonstration of how easy it is to work with the Raspberry Pi Pico. Let’s begin by defining what a microcontroller is and how they are used.

What Is a Microcontroller?

One of the greatest advances in physical computing has been the proliferation of microcontrollers. A microcontroller consists of a processor with a small instruction set, memory, and programmable input/output circuitry contained on a single chip. Microcontrollers are usually packaged with supporting circuitry and connections on a small, printed circuit board.

Microcontrollers are used in embedded systems where small software programs can be tailored to control and monitor hardware devices, making them ideal for use in small projects such as appliances or smart controller boards. Microcontrollers are sometimes called an “embedded controller,” “embedded processor,” or “microcontroller unit (MCU).”

A typical microcontroller has one or more integrated circuits or a single chip that contains all of the components for the microcontroller. Typically, the processing unit, memory, and I/O circuitry are considered part of the microcontroller. However, microcontrollers often employ other circuits and components such as analog-to-digital converters (ADC), digital-to-analog converters (DAC), and at least one form of serial communication port for programming such as a USB port.

These hardware features make microcontrollers ideal solutions for interfacing with other hardware to perform minimal computational operations while controlling the hardware. In other words, they make excellent programmable controllers.

Microcontroller VS. Microprocessor: What is The Difference?

You may be thinking a microcontroller is just a smaller version of a microprocessor. While some microcontrollers are quite powerful, they are not microprocessors. A microprocessor is designed to maximize computing power on the chip while connecting to a bus (think parallel highway for digital communication) for making use of RAM and input/output (I/O) ports like USB and video graphics, whereas a microcontroller is designed with a much smaller set of dedicated functionality to perform operations with a set of general-purpose input/output (GPIO) pins typically to control hardware components. Thus, a microcontroller has limited computing power, making them useful for hardware automation like a robot, household appliance, etc., whereas a microprocessor is useful for computationally intensive solutions like computers, aircraft, etc.

Now that we have a general idea of what a microcontroller is, let’s take a short tour of the Raspberry Pi Pico.

A Tour of the Raspberry Pi Pico

The Raspberry Pi Pico, hence Pico, is a small, green printed circuit board the size of a stick of gum. Along either long side are the GPIO pins with a micro-USB connector on one of the shorter ends. On the other end is a set of debugging pins that you can use for advanced diagnostics. Figure 1-1 shows the Pico from above oriented with the USB port to the right.
Figure 1-1

The Raspberry Pi Pico – top view (courtesy of raspberrypi.org)

Notice the GPIO headers on the top and bottom edges. The three pins on the left are the debugging pins. The only other component on the board we need to know about is the BOOTSEL (boot selection) switch located in the upper right of the figure. This switch is used to place the Pico in boot mode where it runs the MicroPython platform, or, if held down while the USB cable is connected to your computer, it will connect as a removable drive allowing you to load new files or change the base platform files. We will see how to do this later in this section.

Figure 1-2 shows the underside of the Pico. Notice here we see the GPIO pins are labeled, making it easy to locate a specific pin. The places labeled with “TP” are test points that you can use to test voltage should you need to perform any advanced diagnostics of the board. Once again, the pins on the left are for the Serial Wire Debug (SWD) interface. We will not be using that interface in this book, but you can read more about it in Chapter 6 of the Pico data sheet (book): https://datasheets.raspberrypi.org/pico/getting-started-with-pico.pdf.
Figure 1-2

The Raspberry Pi Pico – bottom view (courtesy of raspberrypi.org)

The heart of the Pico is the large (relative to the board) black chip located in the center of the board on the top side. This is the RP2040 microprocessor, and it provides all of the features that make up the Pico.

Introducing the RP2040

Let’s begin with the name. The name may seem strange at first. Normally, we think the number is some sort of revision or version,1 but this is not the case for the RP2040. Figure 1-3 depicts the nomenclature of the name. As you can see, it is an encoded phrase to represent four characteristics of the microprocessor. It is likely we will see variants of this microprocessor in the future, and we should expect its name (number) to vary according to this nomenclature.
Figure 1-3

RP2040 nomenclature (courtesy of raspberrypi.org)

The RP2040 is a single chip combining memory, a dual-core processor, interfaces, and supporting electronics. In many ways, it is a self-contained powerhouse of a microcontroller. The chip is built to deliver high performance with low power consumption. In fact, it can also support extended execution using battery power. And, best of all, it boasts the ability to run MicroPython, making programming very easy to learn breaking the steep programming learning curve common to microcontrollers. In other words, you don’t have to have a degree in programming or electronics to be able to use it.

The many features of the RP2040 are listed as follows:
  • Dual ARM Cortex-M0+ @ 133MHz

  • 264kB on-chip SRAM in six independent banks

  • Support for up to 16MB of off-chip flash memory via dedicated QSPI bus

  • DMA controller

  • Fully connected AHB crossbar

  • Interpolator and integer divider peripherals

  • On-chip programmable LDO to generate core voltage

  • 2 on-chip PLLs to generate USB and core clocks

  • 30 GPIO pins, 4 of which can be used as analogue inputs

  • Peripherals include
    • 2 UARTs

    • 2 SPI controllers

    • 2 I2C controllers

    • 16 PWM channels

    • USB 1.1 controller and PHY, with host and device support

    • 8 PIO state machines

So, what is all of that mumbo jumbo? For most, these features may not mean a whole lot, but in essence, we’re talking about a seriously capable chip. Those features you may be most interested in include the SPI and I2C controllers (2 of each), the 16 pulse-width modulation channels, and the 30 GPIO pins. Suffice to say, it can handle just about anything you would need for your electronics project. Cool!


For a complete description of the features of the RP2040, see the data sheet at https://datasheets.raspberrypi.org/rp2040/rp2040-datasheet.pdf.

The RP2040 microcontroller can be purchased separately, and there are a growing number of vendors building boards around the RP2040. We will see a few of them in a later section. But first, let’s look at the hardware of the Pico in more detail.

Pico Hardware Overview

So, what is the Pico? Simply, the Pico is a printed circuit board built around the RP2040 along with supporting circuitry to create a small microcontroller board about the size of a stick of gum. It breaks out (think wiring) all of the interfaces supported by the RP2040 along with power and ground pins to help round out the GPIO pins.

The Pico is a low-cost board that offers more features than any other board in the price range. In fact, you can find the Pico for as little as $4.00! That’s amazing considering what you get. For that price, you will get a Pico without headers attached, and you can buy the headers (male or female pins) cut to length. If you do not know how to solder, you can get the Pico with headers soldered on for a couple of dollars more. Even so, it’s still well below what you’d expect to pay for a full-featured microcontroller board.

Let’s talk about those header pins for a moment. If you look closely, you will see the pins have what appear to be two rows: one hole closer to the center of the board and another half hole on the edge giving the long edges of the board a serrated look. This design, called castellations, allows you to solder the board in a surface mount configuration or use male header pins for use with a breadboard or female header pins to allow the use of jumper wires to connect components to the Pico. Figure 1-4 shows the header in more detail.
Figure 1-4

Close-up of the Pico header (courtesy of raspberrypi.org)


For a complete guide on how to solder headers onto the Raspberry Pi Pico, visit https://magpi.raspberrypi.org/articles/how-to-solder-gpio-pin-headers-to-raspberry-pi-pico.

Along with the features of the RP2040, the Pico has been designed with the following features:
  • RP2040 microcontroller with 2MB Flash

  • Micro-USB-B port for power and data (and for reprogramming the Flash)

  • 21x51 1mm thick PCB with 0.1" through-hole pins also with edge castellations

  • 40-pin GPIO header
    • Exposes 26 multifunction 3.3V general-purpose I/O (GPIO)

    • 23 GPIO are digital-only and 3 are ADC capable

    • Can be surface mounted as a module

  • 3-pin ARM Serial Wire Debug (SWD) port

  • Can be powered via the micro-USB, external supplies, or batteries

  • High quality, low cost, high availability

  • Comprehensive SDK, software examples, and documentation


For a complete description of the features of the Pico, see the data sheet at https://datasheets.raspberrypi.org/pico/pico-datasheet.pdf.

Now that we know more about the features of the Pico, let’s look at a few alternatives that use the same RP2040 chip.

Wait, What About WiFi? Where’s The WiFi?

Savvy readers may have noticed the Pico does not have a WiFi chip. This is intentional and designed to keep costs low. Does that mean you cannot use WiFi with the Pico? No, it does not. MicroPython fully supports networking protocols, and you can indeed use the Pico with WiFi, but it requires external components to do so. We will see more about how to use the Pico with WiFi in Chapters 13 and 14.

RP2040-Based Alternatives

There are a number of RP2040-based microcontroller boards that have been built around the RP2040. Some offer unique features not found on the Pico, and others are familiar adaptation to existing product lines. All of them get their powerful base from the RP2040 and works the same as the Pico. Some variants are priced several times that of the Pico, but you get a lot more for your money such as Grove connectors, additional components like programmable LEDs, buttons, etc.2

If you want to try out any of these alternatives, you’re welcome to do so. The book will be based on the cheaper Pico, but any of these boards can be used for the projects in this book with some minor adaptations to the wiring. You will find most cost a bit more than the base Pico but, depending on your needs (or familiarity/affinity for a vendor’s products), may be worth the extra cost.

Let’s look at a few offerings from the most popular vendors including Adafruit (adafruit.com) and SparkFun (sparkfun.com). There are others and more are arriving, but these are the current crop of boards.

Adafruit Feather 2040

Adafruit has a very successful line of small boards under the Feather banner. It’s all about powerful features in a lightweight package. It was no surprise that Adafruit adapted the Feather platform for the Raspberry Pi RP2040. This board has the same features as the Pico, but in a slightly different physical layout without castellated headers. It has an 8MB SPI flash chip for storing files, 21 GPIO pins (one more additional ADC), built-in 200mA+ lipoly charger, an RGB NeoPixel for general use, a STEMMA/QT connector for use with their pantheon of STEMMA/QT components (modules), and a USB-C port instead of the micro-USB on the Pico. Figure 1-5 shows the Adafruit Feather RP2040 board. The board costs about $12.00.
Figure 1-5

Adafruit Feather RP2040 (courtesy of adafruit.com)

For a complete description of this board, see www.adafruit.com/product/4884.

Adafruit ItsyBitsy RP2040

If you’re looking for similar features, but in a slightly smaller package, the Adafruit ItsyBitsy RP2040 may do the trick. Built on their ItsyBitsy platform, this board offers a range of features familiar to that line of boards and all of the features as the Pico, with many of the same features as the Feather RP2040 including two extra GPIO ports, but uses the same micro-USB connector as the Pico. Figure 1-6 shows the Adafruit ItsyBitsy RP2040 board. The board costs about $10.00.
Figure 1-6

Adafruit ItsyBitsy RP2040 (courtesy of adafruit.com)

For a complete description of this board, see www.adafruit.com/product/4888.

Adafruit QT Py

Yeah, the name is intentional. It is a cutie-pie! This is an extreme version of the RP2040 built to support the Adafruit STEMMA QT line of components. It features a lot of the same features as the other two Adafruit boards but with a tiny footprint and is one of the smallest RP2040 boards on the market. This board has the same features as the Pico as well as the Feather RP2040 but in an ultra-compact size. It has the same USB-C connector as the Feather RP2040, but only 13 GPIO pins. Despite its small size, it does have a STEMMA/QT connector. It has been fitted with a castellated header, and, since it takes up less space, it offers more versatility with installation. Figure 1-7 shows the Adafruit QT Py board. The board costs about $10.00.
Figure 1-7

Adafruit QT Py (courtesy of adafruit.com)

For a complete description of this board, see www.adafruit.com/product/4900.

SparkFun Pro Micro – RP2040

The SparkFun Pro Micro RP2040 is one of several RP2040-based boards from SparkFun. Like the Adafruit offerings, it boasts all of the features of the RP2040 along with a WS2812B addressable LED, a boot and reset button, a castellated header, and a Qwiic connector for use with their Qwiic pantheon of I2C devices. It has a USB-C connector instead of the micro-USB on the Pico. Interestingly, it also has a resettable PTC fuse that you can reset should your circuit trip the fuse. In addition, it has 18 GPIO pins, a four-channel ADC with an internal temperature sensor and 12-bit conversion. The board also includes an additional 16MB external QSPI flash chip to store program code, double that of the Feather RP2040. Figure 1-8 shows the SparkFun Pro Micro RP2040. The board costs about $10.00.
Figure 1-8

SparkFun Pro Micro RP2040 (courtesy of sparkfun.com)

For a complete description of this board, see www.sparkfun.com/products/17717.

SparkFun Thing Plus – RP2040

The SparkFun Thing Plus is a more compact option that is similar to the Adafruit Feather–sized boards with many of the same features as the SparkFun Pro Micro RP2040 but in a larger format without the castellated header. It has 18 GPIO pins, 16MB flash memory, a JST single-cell battery connector, an addressable WS2812 RGB LED, as well as a Qwiic connector. The board is unique in that it has an SD card slot and mounting holes making it easy to add to projects with enclosures. Figure 1-9 shows the SparkFun Pro Micro RP2040. The board costs about $18.00.
Figure 1-9

SparkFun Thing Plus – RP2040 (courtesy of sparkfun.com)

For a complete description of this board, see www.sparkfun.com/products/17745.

SparkFun MicroMod Pi RP2040 Processor

The SparkFun MicroMod Pi RP2040 Processor Board is an interesting deviation from the standard microcontroller board. Instead of building a new board with all of the features, connections, electronics, and headers, SparkFun has come up with a novel idea. They use a modular board for the processor and a separate host board (also called a carrier board) for the rest of the components. That is, you can purchase one of several processors and use with one of several carrier boards.

The SparkFun MicroMod Pi RP2040 Processor Board therefore is a RP2040 mounted on a small card that you can plug into one of the carrier boards. You simply connect it to the carrier board that gives you the inputs and outputs you need for your project. Do you want to use the RP2040 with a different carrier board? No problem! Just switch it to the other one. Cool.


For more information about the complete line of SparkFun MicroMod products, see www.sparkfun.com/categories/622.

There are several boards you can use, each with a unique set of features. The following lists a few that may be applicable to most projects built with the RP2040 and MicroPython (there are many others):
Let’s take a look at the double MicroMod Qwiic Carrier Board. Figure 1-10 shows the SparkFun MicroMod Qwiic Carrier Board – double with two Qwiic modules mounted. Notice above the USB-C connector is the MicroMod RP2040 mounted in its slot. The board costs about $12.00.
Figure 1-10

SparkFun MicroMod Qwiic Carrier Board – double (courtesy of sparkfun.com)

For a complete description of this board, see www.sparkfun.com/products/17724.

The SparkFun MicroMod Pi RP2040 Processor Board is the RP2040 packaged on a small board with an M.2 connector. Connecting your MicroMod Pi RP2040 Processor Board is very easy and the same as mounting a component with an M.2 connector. Just match up the key on the edge connector to the key to the M.2 connector, insert it, and use a screw to fix the module to the carrier. As you surmised, it has all of the same features as the RP2040. The functionality supported depends on the carrier board on which it is employed. Figure 1-11 shows the SparkFun MicroMod RP2040 Processor. The processor costs about $12.00.
Figure 1-11

SparkFun MicroMod RP2040 Processor (courtesy of sparkfun.com)

For a complete description of this board, see www.sparkfun.com/products/17720.

Arduino Nano RP2040 Connect

The Arduino Nano RP2040 Connect board is one of the most anticipated new RP2040 boards available. It is expected to be widely available by the time this book is in print, and many cannot wait to get hold of one.3 Why? Because the Arduino has been the king under the mountain of microcontrollers. If you have used any other microcontroller board, chances are it was an Arduino or Arduino variant.

It comes as no surprise that Arduino.cc would employ the RP2040 on their own format of microcontrollers. Arduino has placed the RP2040 on their Nano format board complete with all of the features of an Arduino Nano plus a NINA WiFi and Bluetooth module! Yes, this board is the first to have onboard WiFi and Bluetooth. There are so many features that it is no wonder the expectations are high for this board. Figure 1-12 shows the Arduino Nano RP2040 Connect. It is slightly smaller than the Pico with fewer GPIO pins but has the castellated header of the Pico and the same micro-USB connector. The board costs about $25.00.
Figure 1-12

Arduino Nano RP2040 Connect (courtesy of arduino.cc)

For a complete description of this board, see https://store.arduino.cc/nano-rp2040-connect-with-headers. If you plan to use this board, see the online documentation at https://docs.arduino.cc/hardware/nano-rp2040-connect.


You must use a special MicroPython image for the Arduino Nano RP2040 despite product descriptions stating support for MicroPython. There is also a port of CircuitPython that works that is very similar to MicroPython (more on that in Chapter 2). See https://learn.adafruit.com/circuitpython-on-the-arduino-nano-rp2040-connect for more details.

Pimoroni Pico LiPo

Pimoroni has long been a vendor of excellent and sometimes quirky (in a very cool way) components for microcontrollers and the Raspberry Pi. You may have seen and used one of their many distinctive cases for the Raspberry Pi.

Pimoroni has a product line named Pirate that they use to market products related to the Raspberry Pi including a really cool radio kit4 that uses a Raspberry Pi Zero WiFi board. They have made a RP2040 Pirate version with extra memory, a USB-C connector, STEMMA/QT and Qwiic connectors, as well as onboard LiPo charging. On top of that, they retained the Pico format along with the castellated header. Figure 1-13 shows the Pimoroni Pico LiPo. The board costs $12.00 and up depending on memory size.
Figure 1-13

Pimoroni Pico LiPo (courtesy of pimoroni.com)

For a complete description of this board, see https://shop.pimoroni.com/products/pimoroni-pico-lipo.

Now that we have learned about the technical details concerning the Raspberry Pi Pico, the RP2040, and some of the alternative boards available, let’s take a look at how to get started using the Pico.

Getting Started with the Pico

While the Pico can be programmed with C++, we will use MicroPython in this book to learn how to build electronics and IoT projects. We choose MicroPython because it is easy to install and the language is easy to learn. But where can you buy one of these little boards?

Where to Buy

The Raspberry Pi has become world known and is available from many online vendors, and some local electronics stores carry them as well. Given our new connected, post-pandemic world where you can order any you want and have it delivered, we can find our Raspberry Pi Pico and all of our accessories online. The following lists a few of the more popular online vendors:
  • The Pi Hut: Mann Enterprises LTD located in the UK is the premier Raspberry Pi shop. They have just about anything you could need for the Raspberry Pi including the Pico, micro:bit, Arduino, robotics, and more. Check them out at https://thepihut.com/.

  • PiShop.US: The American Raspberry Pi shop located in the United States. They have all things Raspberry Pi, Arduino, and more. Find them at www.pishop.us/.

  • Adafruit: Limor Fried, Adafruit founder and lead engineer, together with a team of talented engineers develop community-driven products and code. They carry many Adafruit designed products for many of the most popular electronics platforms including the Arduino as well as their own brand of Arduino boards, Raspberry Pi, and more. They also host one of the most comprehensive learning systems available. If you need to learn how to do something, check out https://learn.adafruit.com/. Chances are you’ll find all of your answers there. Also, check out their wares at www.adafruit.com/.

  • SparkFun: Another most excellent online electronics vendor and a favorite of mine, SparkFun is located in the United States and carry a vast line of microcontrollers, discrete components, Arduino, Raspberry Pi, and so much more. You simply will get lost in the depth of their catalog. They are the makers of the Qwiic component system and have many modules to choose from including their own brand of most products. They also host a vast learning website and document every component they sell. If you need help with their products or want to learn how to build something, check out https://learn.sparkfun.com/. With excellent customer service and fast shipping, SparkFun should be on your go-to list of vendors. Check out their products at www.sparkfun.com.

  • Seeed Studio: Seeed Studio is located in China. They carry all manner of electronics for all of the major brands as well as they are the makers of the Grove component system, which we will be using later in this book. They also have a vast Wiki devoted to all of their products with ample instructions and documentation. See their Wiki at https://wiki.seeedstudio.com/. While transit time for some may be a concern, chances are the nice people at Seeed Studio will have what you need. Look for them at www.seeedstudio.com/.

  • Mouser: One of the largest online electronics stores (their catalog is thousands of pages long) and based in the United States is Mouser. They have almost everything on the planet for the electronics enthusiast. Their website is more industry driven, but if you search for products by name or description, you will find what you need. See www.mouser.com for more details.

  • Pimoroni: A growing online vendor that sells all of their own products directly as well as many accessories for the Arduino and Raspberry Pi. If you want a Pimoroni product but can’t find it at a local vendor, get it from the source at https://shop.pimoroni.com/.

The Pico is typically sold packaged in a static-free packet without headers. Some vendors offer the Pico with headers attached (Seeed Studio) as well as bundles with the USB cable and more.


If you want to order new Raspberry Pi products when they are released, The Pi Hut (https://thepihut.com/) typically has them in stock the day they are released.

Now that we know where to buy our Pico kit, let’s look at what accessories you need to get started.

Required Accessories

The list of required accessories is quite short. In fact, the only thing you need to get started with the Pico is a USB-B female to micro-USB-B male cable. That’s it!


For the most excellent description of USB cables and connectors on the Internet, see https://learn.sparkfun.com/tutorials/connector-basics/usb-connectors.

However, that won’t get you all you need to do the projects in this book. You will need more components and some electronics to build the projects. Rather than list all those here, you will find a list of required components in each project chapter. For example, you may need a breadboard, jumper wires, and one or more electronic components.

There are some optional and recommended accessories you should consider.

Optional and Recommended Accessories

There are a growing number of accessories available for the Pico. So many, in fact, it is difficult to keep up with the list! Rather than attempt that, this section presents some of the products that have been shown to enhance your experience with the Pico. While some of these may be required or at least optional for the projects in the book, you can get by without them if you’re on a tight budget. However, if you have some funds to building a kit for the Pico, these are some of the best options you can find.

There are host boards (not unlike the MicroMod carrier boards from SparkFun), add-on boards, and basic components that you may want to consider. Let’s start with the host boards. There are several excellent boards, but we will look at three of the first boards available for the Pico.

One of the host boards that has proven to be a good place to start with basic projects is the Maker Pi Pico Base (without Pico) from Cytron (https://thepihut.com/products/maker-pi-pico-base-without-pico). You can get this board with the Pico already soldered in place or with a header ready for you to plug in your Pico with male headers soldered on. The board costs about $9.50 and is available from The Pi Hut.

The Maker Pi Pico Base includes a reset button and access to all GPIO pins on two 20-way pin headers with clear labels. Better still, each pin has an LED indicator to let you know if the pin is in use. Now, that’s a nice touch! But it doesn’t end there. There are three programmable pushbuttons, an RGB LED, buzzer, audio jack, a micro-SD card slot, and six Grove ports. Most intriguing is the addition of a socket for an ESP-01 WiFi module. Yes, you can provide WiFi for your Pico! Figure 1-14 shows the Maker Pi Pico Base (without Pico).
Figure 1-14

Maker Pi Pico Base (without Pico) (courtesy of thepihut.com)

You can find the data sheet with complete details of all of its features at https://cdn.shopify.com/s/files/1/0176/3274/files/Maker_Pi_Pico_Datasheet.pdf?v=1617963762. See https://github.com/CytronTechnologies/MAKER-PI-PICO for example code for the Pico.

Another similar board is from Pimoroni. The Pico Omnibus (Dual Expander) (https://shop.pimoroni.com/products/pico-omnibus) is a simple board that contains two mirrored docking ports that mirror the GPIO header of the Pico but with male pins. This allows you to use up to two Pico add-on boards at the same time without having to fuss with soldering stacking headers. The pins are all clearly labeled in white on a black PCB and come with rubber feet you can apply yourself. The board costs about $9.00, and you can find it at thepihut.com or pimoroni.com. Figure 1-15 shows the Pico Omnibus (Dual Expander).
Figure 1-15

Pico Omnibus (Dual Expander) (courtesy of pimoroni.com)

You may be wondering what modules you can use with this board. Well, it turns out Pimoroni offers several. Two of those we can use for the projects in this book are the Pico Display Pack (https://shop.pimoroni.com/products/pico-display-pack) and the Pico Wireless Pack (https://shop.pimoroni.com/products/pico-wireless-pack).

The Pico Display Pack has a 1.14" LCD screen with four buttons and an RGB LED mounted with female headers so you can attach it directly to the bottom of your Pico. Figure 1-16 shows the Pico Display Pack.
Figure 1-16

Pico Display Pack (courtesy of pimoroni.com)

The Pico Wireless Pack uses an ESP32 chip to provide 2.4GHz wireless connections for your Pico. It also includes a micro-SD drive for file storage as well as an RGB LED and a programmable button. It is also mounted with female headers so you can attach it directly to the bottom of your Pico. Figure 1-17 shows the Pico Wireless Pack.
Figure 1-17

Pico Wireless Pack (courtesy of pimoroni.com)


If you plan to complete the projects in Chapters 13 and 14 or want to explore the challenge exercises, you should plan on purchasing the Pimoroni Omnibus (Dual Extender), Display Pack, and Wireless Pack.

The last board is the Grove Shield for Pi Pico (www.seeedstudio.com/Grove-Shield-for-Pi-Pico-v1-0-p-4846.html). This board is the premier board for using the Grove component system from Seeed Studio. The board features ten Grove connectors, a dual row of GPIO headers to allow access to all pins while the Pico is installed, and a 3.3V/5V power switch, which is needed to support some Grove modules. The board costs about $4.50 and is available from Seeed Studio and other online vendors. It does not come with any bumpers, so you may want to invest in some to attach to the bottom to keep from scratching your workspace/desktop area. Figure 1-18 shows the Grove Shield for the Raspberry Pico.
Figure 1-18

Grove Shield for the Raspberry Pi Pico (courtesy of seeedstudio.com)

Seeed Studio also sells a Grove starting kit for the Pico for about $48 (www.seeedstudio.com/Grove-Starter-Kit-for-Raspberry-Pi-Pico-p-4851.html), which includes the shield and 12 Grove modules and assorted electronics. If you want to use the Grove system exclusively, this starter kit is a must.


If you plan to complete the projects in Chapters 9 through 12 or want to explore the challenge exercises, you should plan on purchasing the Grove Shield for the Raspberry Pi Pico.

Now that we’ve discovered some nice accessories to use with the Pico, let’s jump into our first tour of how to use it starting with preparing our PC.

Preparing Your Computer

Fortunately, there isn’t much you need to do to configure your computer to work with the Pico. At the barest, you will need to download the MicroPython boot image, which we will see how to do in the next section.

It is highly recommended that you install Python on your computer to help learn how to work with the language. Why? Because MicroPython is a subset of Python and many of the early examples you will see will run on both your PC and the Pico. Thus, it is wise to install Python to help you learn how to write MicroPython. If you don’t know how to get started installing Python on your PC, don’t worry. We will visit this topic in Chapter 2.

Installing MicroPython on the Pico

Now we’re at the meat of our example. Here, we will install MicroPython on our Pico and get it ready for programming. There are two ways to accomplish this: a manual method and an automated process using Thonny. Let’s look at both methods. You can choose the one that works best for you.

Manual Install

The process is very simple. First, you download the bootloader file, then place your Pico into USB drive mode, insert it into your PC, then copy the file onto the drive, remove the Pico, and reinsert it. Simple! Let’s see it in more detail.


Do not connect your Pico to your computer yet. You will need to plug it in and unplug it at specific steps in the process. If you’ve already plugged in the cable, it won’t hurt anything, but you will need to disconnect it before your begin.

Begin by visiting https://micropython.org/download/rp2-pico/rp2-pico-latest.uf2 and download the latest UF2 bootloader file. Make sure you let the download complete before you continue.

Next, locate the BOOTSEL switch on your Pico. You will need to press this button and hold it while you connect it to your PC. Figure 1-19 shows the location of the BOOTSEL switch.
Figure 1-19

Locating the BOOTSEL switch

Next, connect your USB cable to your Pico and press the BOOTSEL and hold it when you insert the other end of the USB cable to your PC. Wait about three to five seconds and then release the button. It will mount as a drive with the name RPI-RP2. On Windows, you will hear the tone to indicate a new USB device was detected. On Linux and macOS, you will see a new icon appear for the drive.

Be very careful when connecting and disconnecting the USB cable on your Pico boards, especially those with the micro-USB connector. These are very fragile and can be broken easily if the cable is pulled at an angle or twisted. The same is true when using the Pico on a breadboard or host adapter like those shown earlier. Be sure to remove the Pico by grasping it on the sides away from the USB connector.


The USB connector on the Pico is fragile. Be sure to insert and remove the USB cable directly and never pull the cable at an angle to remove it.

Next, locate the UF2 file you downloaded and simply drag and drop it onto your Pico (shown as a drive on your PC). When the file copy is finished, the Pico will reboot. You can tell by watching the LED on the Pico, and the drive on your PC should disappear. If this does not happen, you can unplug the Pico and plug it back in to get it to boot into MicroPython.

Using Thonny

There is also an automated method to install MicroPython on your PC. If you have worked with the Raspberry Pi and Python, chances are you’ve run across a nice, small Python integrated development environment (IDE) named Thonny. Thonny is available for most platforms including Linux, Windows, and macOS at https://thonny.org/. Simply download the installer for your platform and install it.

After you have installed Thonny and start it for the first time, on some platforms, you will be asked to choose a language and initial settings. The choices for settings include Standard and Raspberry Pi. The Raspberry Pi settings are simplistic, and you won’t see the menu (but you can turn it on by switching the mode). So, you should select the Standard option as shown in Figure 1-20.
Figure 1-20

Choose initial settings (Thonny)


To perform this process, your Pico should not be connected to your PC. If it is, disconnect it before you continue.

Using Thonny, you can develop Python and MicroPython code and even run the code to test it. The editor is tailored for writing Python code and has many useful tools to help you with your coding. Better still, it does all of this using a simple, uncluttered user interface that is elegant in its simplicity.

But it’s not just a fancy editor! You can also connect to your Raspberry Pi Pico to write code and run it. In fact, you can use Thonny to load MicroPython on your Pico. Let’s see how to do that. First, launch Thonny without the Pico connected to your computer. Figure 1-21 shows the Thonny IDE on Windows.
Figure 1-21

Thonny IDE (Windows 10)

Notice at the top of the window is a tabbed editor area where you can work on one or more Python files. Below that is the Shell area that you can use to execute your Python code. Here, we see a very simple print statement and its execution. On the right is an area for the documentation and help links. You can close both if you want some more room for the editor.

Notice also in the lower right-hand corner the text Python 3.7.9. This is actually an actionable area (think button) that lets you change the base Python interpreter. We will use that in a moment.

Next, locate the BOOTSEL switch on your Pico. You will need to press this button and hold it while you connect it to your PC. Figure 1-19 shows the location of the BOOTSEL switch. Next, connect your USB cable to your Pico and press the BOOTSEL and hold it when you insert the other end of the USB cable to your PC.

Go back to Thonny and click the Python version. Figure 1-22 shows what the menu should look like.
Figure 1-22

Choose a Python interpreter (Thonny)

Next, click MicroPython (Raspberry Pi Pico). A dialog box will prompt you to install the latest version of the MicroPython firmware on your Pico. When ready, click Install in the dialog that appears as shown in Figure 1-23.
Figure 1-23

Install MicroPython (Thonny)


If the dialog doesn’t appear, ensure you have plugged in your Pico with the BOOTSEL pressed. It is OK to try it again.

When the installation is complete, you can click Close as shown in Figure 1-24. Now we’re ready to begin programming our Pico.
Figure 1-24

MicroPython install complete (Thonny)

Your Pico will reboot, and when it is booted, you will see the MicroPython header in the Shell window as shown in Figure 1-25. Just for fun, type help() in the >>> prompt and press enter. This is the basic help for the MicroPython interpreter. We’ll see more about how to use this in the next section.
Figure 1-25

Connected to the Pico (Thonny)

It is possible on some platforms for the Pico to change COM ports when it is rebooted. If you cannot connect to the Pico with Thonny at this step, try disconnecting and reconnecting the Pico. You can also click the red Stop button on the toolbar to stop and restart the Pico connection. Then, in the ToolsOptions… menu on the Interpreter tab, select the COM port for the Pico as shown in Figure 1-26 and then click OK.
Figure 1-26

Selecting the COM port for the Pico (Thonny – Windows 10)

It is also possible the interpreter for the MicroPython Pico will not show up if there is an error communicating with the Pico. In that case, open the options dialog again and choose the MicroPython (Raspberry Pi Pico) in the Interpreter drop-down box as shown in Figure 1-27.
Figure 1-27

Selecting the Python interpreter (Thonny)

Now that our Pico is loaded with the MicroPython boot image, let’s see how to connect to it and run some code!

Connecting to the Pico

Now that you have your Pico running MicroPython, now what do you do? Now you need to open a communication link to the MicroPython interpreter. The MicroPython interpreter is called a read-evaluate-print loop (REPL) and is often referred to with that acronym. You can connect to your Pico to execute the REPL feature using either a serial communication utility or a development environment with the same feature. Let’s see how to use the communication utility first.

Using the REPL Console with a Serial Communication Utility

If you are using Windows 10, you can use any serial communication utility you’d like. One of the most common is PuTTY (www.putty.org/). It is rather aged but works well. If you want to use PuTTY, go ahead and download and install it now.

Once installed, you will be referencing the Pico connection via the COM port. To find the COM port that your Windows computer is using for the Pico, open the Device Manager and expand the Ports (COM & LPT) section. You should see a USB device similar to what is shown in Figure 1-28.
Figure 1-28

Locating the COM port (Windows 10)

If you have multiple devices connected, you may need to disconnect the Pico, refresh the device manager, then reconnect the Pico. The COM port that disappears when you disconnect and reappears when you reconnect the Pico is the one you need to use.

Notice the COM port (COM3). We will need that to tell PuTTY which port to use. Now, open PuTTY and select the Serial for the Connection type and change the Serial line to COM3 (the port shown in your device manager) as shown in Figure 1-29. Click Open to start the terminal.
Figure 1-29

Connecting to the Pico with PuTTY (Windows 10)

When the terminal opens, you may not see anything at first. If so, you can press ENTER a few times and you should see the >>> prompt. You can then enter MicroPython statements and have them execute as demonstrated in Figure 1-30.
Figure 1-30

PuTTY terminal (Windows 10)

Starting the REPL Console (macOS and Linux)

To connect using macOS or Linux, you need to locate the correct device. I demonstrate this with the following command that lists the devices on my macOS system. Do this after you’ve connected the USB cable to the Pico.
% ls /dev/tty.*
/dev/tty.Bluetooth-Incoming-Port     /dev/tty.usbmodem14401
Once you see the correct USB device, you can enter the following command to open a screen (terminal) to execute the REPL:
% screen /dev/tty.usbmodem14401
Once again, you may need to press ENTER a few times to get the >>> prompt. Once you do, enter the following statement, and see the results:
>>> print("Hello from macOS!")
Hello from macOS!

There is one oddity with the REPL console. The quit() doesn’t work. To exit the console for some Pico boards, you will need to reset the board or kill the connection.

Connecting to the Pico with Thonny

If you followed the instructions in the Thonny section earlier, you have what you need to connect to your Pico via Thonny. Recall, we need only connect our Pico to our PC and then open Thonny and change the Python interpreter. If you have not done that, you should go back and follow the preceding steps to choose the MicroPython (Raspberry Pi Pico).

Once connected, the REPL will appear in the Shell tab as shown in Figure 1-31. You can enter the statement print("Hello from Thonny!") at the >>> prompt and press ENTER. You should see the results shown in the figure.
Figure 1-31

Connecting to the Pico with Thonny

If everything worked and you saw the message printed, congratulations! You’ve just written your first MicroPython code, and you’re ready to dive into more MicroPython coding. Yippee!


There is little doubt that the Raspberry Pi Pico will open a new avenue for Raspberry Pi enthusiasts. The fact that we now have a Raspberry Pi–based microcontroller available at a very low cost and programmable with MicroPython means anyone can start to build electronics projects without the need for lengthy study or a steep learning curve. The subsequent chapters in this book will guide you to becoming proficient in building electronics projects with the Pico.

In this opening chapter, we have discovered what the Pico is, the hardware features available on the board, and we took a look at some of the other RP2040-based microcontroller boards available from other vendors. We also saw some recommended accessories to help make your experience with the Pico better by adding convenience features such as Grove and Qwiic connectors and a fully labeled GPIO header. However, your journey has only begun.

In the next chapter, we will learn more about MicroPython including how to get started programming your Pico.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.