Getting Started with the Raspberry Pi Pico — Part 2 of the Pico Series…

Welcome to Part two of my RPi Pico Series. You can buy yours from Cytron Technologies.
In this post, we will look at some more of the features of the board, as well as how to get started using this development board. I will focus on MicroPython in this post, and cover C/C++ in the next post.

But before we do that, lets run over some of the specifications of the board first…
The Python Stuff will be at the end of this post…

Board Specifications

Raspberry Pi Pico is a low-cost, high-performance microcontroller board with flexible digital interfaces. Key features include:

  • RP2040 microcontroller chip designed by Raspberry Pi in the United Kingdom
  • Dual-core Arm Cortex M0+ processor, flexible clock running up to 133 MHz
  • 264KB of SRAM, and 2MB of on-board Flash memory
  • Castellated module allows soldering direct to carrier boards
  • USB 1.1 with device and host support
  • Low-power sleep and dormant modes
  • Drag-and-drop programming using mass storage over USB
  • 26 × multi-function GPIO pins
  • 2 × SPI, 2 × I2C, 2 × UART, 3 × 12-bit ADC, 16 × controllable PWM channels
  • Accurate clock and timer on-chip
  • Temperature sensor
  • Accelerated floating-point libraries on-chip
  • 8 × Programmable I/O (PIO) state machines for custom peripheral support

Utilities

What is on your Pico?

If you have forgotten what has been programmed into your Raspberry Pi Pico, and the program was built using our Pico C/C++ SDK, it will usually have a name and other useful information embedded into the binary. You can use the Picotool command line utility to find out these details. Full instructions on how to use Picotool to do this are available in the ‘getting started‘ documentation.

Pico Github Repo

Debugging using another Raspberry Pi Pico

It is possible to use one Raspberry Pi Pico to debug another Pico. This is possible via picoprobe, an application that allows a Pico to act as a USB → SWD and UART converter. This makes it easy to use a Pico on non-Raspberry Pi platforms such as Windows, Mac, and Linux computers where you don’t have GPIOs to connect directly to your Pico. Full instructions on how to use Picoprobe to do this are available in the ‘getting started‘ documentation.

PicoProbe Github Repo

Resetting Flash memory

Pico’s BOOTSEL mode lives in read-only memory inside the RP2040 chip, and can’t be overwritten accidentally. No matter what, if you hold down the BOOTSEL button when you plug in your Pico, it will appear as a drive onto which you can drag a new UF2 file. There is no way to brick the board through software. However, there are some circumstances where you might want to make sure your Flash memory is empty. You can do this by dragging and dropping a special UF2 binary onto your Pico when it is in mass storage mode.

The Code for the flash eraser is available below


/**
 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
 *
 * SPDX-License-Iden
/**
 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

// Obliterate the contents of flash. This is a silly thing to do if you are
// trying to run this program from flash, so you should really load and run
// directly from SRAM. You can enable RAM-only builds for all targets by doing:
//
// cmake -DPICO_NO_FLASH=1 ..
//
// in your build directory. We've also forced no-flash builds for this app in
// particular by adding:
//
// pico_set_binary_type(flash_nuke no_flash)
//
// To the CMakeLists.txt app for this file. Just to be sure, we can check the
// define:
#if !PICO_NO_FLASH
#error "This example must be built to run from SRAM!"
#endif

#include "pico/stdlib.h"
#include "hardware/flash.h"
#include "pico/bootrom.h"

int main() {
    flash_range_erase(0, PICO_FLASH_SIZE_BYTES);
    // Leave an eyecatcher pattern in the first page of flash so picotool can
    // more easily check the size:
    static const uint8_t eyecatcher[FLASH_PAGE_SIZE] = "NUKE";
    flash_range_program(0, eyecatcher, FLASH_PAGE_SIZE);

    // Flash LED for success
    gpio_init(PICO_DEFAULT_LED_PIN);
    gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
    for (int i = 0; i < 3; ++i) {
        gpio_put(PICO_DEFAULT_LED_PIN, 1);
        sleep_ms(100);
        gpio_put(PICO_DEFAULT_LED_PIN, 0);
        sleep_ms(100);
    }

    // Pop back up as an MSD drive
    reset_usb_boot(0, 0);
}tifier: BSD-3-Clause
 */

// Obliterate the contents of flash. This is a silly thing to do if you are
// trying to run this program from flash, so you should really load and run
// directly from SRAM. You can enable RAM-only builds for all targets by doing:
//
// cmake -DPICO_NO_FLASH=1 ..
//
// in your build directory. We've also forced no-flash builds for this app in
// particular by adding:
//
// pico_set_binary_type(flash_nuke no_flash)
//
// To the CMakeLists.txt app for this file. Just to be sure, we can check the
// define:
#if !PICO_NO_FLASH
#error "This example must be built to run from SRAM!"
#endif

#include "pico/stdlib.h"
#include "hardware/flash.h"
#include "pico/bootrom.h"

int main() {
    flash_range_erase(0, PICO_FLASH_SIZE_BYTES);
    // Leave an eyecatcher pattern in the first page of flash so picotool can
    // more easily check the size:
    static const uint8_t eyecatcher[FLASH_PAGE_SIZE] = "NUKE";
    flash_range_program(0, eyecatcher, FLASH_PAGE_SIZE);

    // Flash LED for success
    gpio_init(PICO_DEFAULT_LED_PIN);
    gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
    for (int i = 0; i < 3; ++i) {
        gpio_put(PICO_DEFAULT_LED_PIN, 1);
        sleep_ms(100);
        gpio_put(PICO_DEFAULT_LED_PIN, 0);
        sleep_ms(100);
    }

    // Pop back up as an MSD drive
    reset_usb_boot(0, 0);
}

Getting Started with MicroPython on the RPi Pico

Drag and drop MicroPython

You can program your Pico by connecting it to a computer via USB, then dragging and dropping a file onto it, so we’ve put together a downloadable UF2 file to let you install MicroPython more easily. Following the procedure below, you can install MicroPython onto the Pico in a few seconds…

1. Download and unzip the UF2 file below into a folder on your computer.

2. Hold down the Bootsel button on the Pico, and connect it to a USB cable that was already connected to your computer. ( This means, connect ons side of the usb cable to the computer, but dont connect the Pico yet. then hold down BOOTSEL, and connect the cable to the pico)

3. Now, release the BootSEL button

4. After a few Seconds, you will have a new USB storage device on your computer, called RPI-RP2

5. Drag the UF2 file into this USB Storage device. The Pico will reboot… You have now installed MicroPython on your RPi Pico

Accessing the MicroPython REPL

You can now access REPL from a serial terminal, or a MicroPython IDE , like Thonny…
I will show you how to do it from the Linux Terminal below.

The Pico will show up as a USB device called ttyACM0
you can find it by issuing the ls /dev/tty* command

Start minicom or your preferred serial terminal emulator

Press enter a few times, and you should get a REPL prompt

You can now test MicroPython on your Pico, by typing the following commands:

The complete MicroPython SDK for the RPi Pico is available for download at the link below…

In the next part of this series, we will look at using the Thonny IDE, as well as C/C++ to program the Pico

Introducing the Raspberry Pi Pico

It is not often that we get the opportunity to be one of the first people to get our hands onto a new product, So when my friends at Cytron Technologies asked me if I would like to do a review on a new Raspberry Pi product last week, I was definitely interested. Details were few, as the product was still under an NDA, but at last, I got the datasheets and some details on Tuesday, enough to start writing about the new product before the big Launch on Thursday the 21st of January 2021…

So, what am I trying to say? Well, It seems that the Raspberry Pi Foundation has released a new product, and from first impressions, it seems to be a game-changer… Lets not get confused. I am not speaking about a full size Raspberry Pi Board, or the compute module… No, The Pi Foundation has released an RP2040 Microprocessor based development board, in the same form factor as an Arduino Nano.

Raspberry Pi Pico Microcontroller Board

This will be an introduction post, and when I receive the device to play with, which will be soon, I will start with a short series on its features and capabilities… For now, lets look at some of the specifications

Front and Back view of the Raspberry Pi Pico

Features:

Raspberry Pi Pico has been designed to be a low cost yet flexible development platform for RP2040, with the following
key features:
• RP2040 microcontroller with 2MByte Flash
• Micro-USB B port for power and data (and for reprogramming the Flash)
• 40 pin 21×51 ‘DIP’ style 1mm thick PCB with 0.1″ through-hole pins also with edge castellations
◦ Exposes 26 multi-function 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
• Simple yet highly flexible power supply architecture
◦ Various options for easily powering the unit from micro-USB, external supplies or batteries
• High quality, low cost, high availability
• Comprehensive SDK, software examples and documentation
RP2040 key features: (Datasheet available for download at the bottom of this post)
• Dual-core cortex M0+ at up to 133MHz
◦ On-chip PLL allows variable core frequency
• 264K multi-bank high performance SRAM
• External Quad-SPI Flash with eXecute In Place (XIP)
• High performance full-crosspoint bus architecture
• On-board USB1.1 (device or host)
• 30 multi-function General Purpose IO (4 can be used for ADC)
◦ 1.8-3.3V IO Voltage (NOTE Pico IO voltage is fixed at 3.3V)
• 12-bit 500ksps Analogue to Digital Converter (ADC)
• Various digital peripherals
◦ 2x UART, 2x I2C, 2x SPI, up to 16 PWM channels
◦ 1x Timer with 4 alarms, 1x Real Time Counter
• Dual Programmable IO (PIO) peripherals
◦ Flexible, user-programmable high-speed IO
◦ Can emulate interfaces such as SD Card and VGA

Pico provides minimal (yet flexible) external circuitry to support the RP2040 chip (Flash, crystal, power supplies and
decoupling and USB connector). The majority of the RP2040 microcontroller pins are brought to the user IO pins on the left and right edge of the board. Four RP2040 IO are used for internal functions – driving an LED, on-board Switched Mode Power Supply (SMPS) power control and sensing the system voltages.
Pico has been designed to use either soldered 0.1″ pin-headers (it is one 0.1″ pitch wider than a standard 40-pin DIP package) or can be used as a surface mountable ‘module’, as the user IO pins are also castellated. There are SMT pads underneath the USB connector and BOOTSEL button, which allow these signals to be accessed if used as a reflow-soldered SMT module.

The Pico uses an on-board buck-boost SMPS which is able to generate the required 3.3 volts (to power RP2040 and external circuitry) from a wide range of input voltages (~1.8 to 5.5V). This allows significant flexibility in powering the unit from various sources such as a single Lithium-Ion cell, or 3 AA cells in series. Battery chargers can also be very easily integrated with the Pico powerchain.
Reprogramming the Pico Flash can be done using USB (simply drag and drop a file onto the Pico which appears as a mass storage device) or via the Serial Wire Debug (SWD) port. The SWD port can also be used to interactively debug code running on the RP2040.

Mechanical Specifications

The Raspberry Pi Pico is a single sided 51x21mm 1mm thick PCB with a micro-USB port overhanging the top edge and dual castellated/through-hole pins around the remaining edges. Pico is designed to be usable as a surface mount module as well as being in Dual Inline Package (DIP) type format, with the 40 main user pins on a 2.54mm (0.1″) pitch grid with 1mm holes and hence compatible with veroboard and breadboard. Pico also has 4x 2.1mm (+/- 0.05mm) drilled mounting holes to provide for mechanical fixing, see Figure 3.

Mechanical specifications for the Raspberry Pi Pico

Conclusion

I hope that this is enough details to get all of you interested and eager for more details…
In the next part of this series, I will focus on getting started with this new board, as well as do the official unboxing…
Please stay tuned for more details…