Raspberry Pi RP2040 is an ARM Cortex M0 based small microcontroller. It has 2 cores so robust to handle multitasking. It has PIO capability so the digital I/O has high accuracy for low level protocols such as SPI/I2C/UART. The Pico W board can talk to other devices without wire so easy to start IoT projects.
This repo is written with a particular combination in mind:
So this doc can be helpful for someone who would like to start with this setup.
Arduino CLI is a command line tool to manage Arduino components (board profiles, libraries, compilers, etc). The detail can be found from the official document (https://arduino.github.io/arduino-cli/0.31/installation/).
It can be installed by:
$ cd ~
$ mkdir -p Arduino/cli
$ curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
The executable binary will be installed under $HOME/Arduino/cli/bin, so add the path to PATH variable in bashrc or zshrc. Then restart terminal.
export PATH=$PATH:$HOME/Arduino/cli/bin
The arduino-cli command can be used to install basic configuration:
# Add arduino-pico index to Arduino board manager
$ arduino-cli config init --additional-urls \
https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
# Update Arduino core cache
$ arduino-cli core update-index
# List all the available boards - rpipicow should be in the list
$ arduino-cli board listall
...
Raspberry Pi Pico rp2040:rp2040:rpipico
Raspberry Pi Pico arduino:mbed_rp2040:pico
Raspberry Pi Pico W rp2040:rp2040:rpipicow
...
Although pico boards support UF2 (so firmware update can be done by drag and drop), it can be little cumbersome during development phase. Arduino-cli can put pico boards into bootloader mode when reset (so no need to press the boot button on the board). To allow that, the udev configuration should be applied prior to any sketch uploading.
$ arduino-cli core update-index
$ arduino-cli core install arduino:mbed_rp2040
$ cd ~/.arduino15/packages/arduino/hardware/mbed_rp2040/${VERSION}
$ sudo ./post_install.sh
Since Vscode is popular, no need to introduce how to install it. Still few extensions should be installed:
In terminal, a new Arduino project can be created. The command below will create a new directory with a sketch file.
$ arduino-cli sketch new Blink
$ cd Blink
$ cat Blink.ino
void setup() {
}
void loop() {
}
In the Blink directory, open Vscode:
$ code .
Once Vscode is opened, let's double check if pico package is installed. Open the command palette with Control + Shift + p and choose Arduino: Board Manager. Press the Refresh Package Indexes and search for pico if Raspberry Pi Pico/RP2040 is installed. If not, please press the install button.
Now, project specific items should be configured.
The sketch file can be updated - it is just an LED blinking example:
#include <Arduino.h>
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
digitalWrite(LED_BUILTIN, HIGH);
delay(300);
digitalWrite(LED_BUILTIN, LOW);
delay(300);
}
At this point, we cannot even compile the sketch because the board type is not specified yet. Open the command palette with Control + Shift + p and choose Arduino: Board Config. There will be Select your board dropdown - choose the pico or pico w in the list. The .vscode directory and arduino.json file will be automatically created.
The arduino.json file can be updated with these lines to specify the name of this sketch as well as output directoy:
{
...
"sketch": "Blink.ino",
"output": "./build",
...
}
Now, let's verify the sketch. Open the command palette with Control + Shift + p and choose Arduino: Verify. This command will do 2 things:
The includePath should look like the one in Blink/.vscode/c_cpp_properties.json, but the paths can be little different depend on the Arduino-pico version and the actual path in file system. There is this another doc, which explains how to get the correct header paths.
One thing shdouldn't be forgotten is, even if the includePath gets manually updated, Intellisense can overwrite the includePath. To prevent, add a new file settings.json under the .vscode directory with those lines.
{
"arduino.disableIntelliSenseAutoGen": true,
// "C_Cpp.errorSquiggles": "disabled" // Add this if redlines are too annoying.
}
Lastly, let's upload the sketch to the board. As it comes with UF2 as default, Arduino-cli cannot reset it by itself for the first time.
To get the board's bootloader activated:
Make sure the short cut! It is Control + Alt + u (not Control + Shift + p).
Once the uploading is done, the built in LED should blink.