The Raspberry Pi Pico is an easy development board to get started with. Flashing a binary is as simple as dragging a file onto it like a flash drive while it is in BOOTSEL mode. As a result, the board doesn't need to be connected while you are coding or building.
This how-to will show you how to set up a development environment using either Visual Studio Code or CLion on macOS. Both IDEs will require configuring CMake, which is what is used to build the code.
Install the Toolchain
Run the following commands from the terminal
brew install cmake
brew tap ArmMbed/homebrew-formulae
brew install arm-none-eabi-gcc
Clone the Repositories
Run the following commands from a folder of your choice to clone the pico-sdk repository
git clone -b master https://github.com/raspberrypi/pico-sdk.git
cd pico-sdk
git submodule update --init
Next, run the following command to get the full path of the pico-sdk
pwd
Next, copy the path and export it as PICO_SDK_PATH environment variable in your ~/.bash_profile
You will need to restart your terminal for the environment variable to work. Alternatively, you can run the following command
source ~/.bash_profile
Next, fetch the examples by running the following commands from your terminal
cd ..
git clone -b master https://github.com/raspberrypi/pico-examples.git
Configure an IDE
You will need an IDE to make development practical. Whatever IDE you choose, you will need to configure CMake.
CLion
Using CLion, open up the pico-examples folder. Be sure to confirm that you trust cmake. You will be met with an error asking you to configure PICO_SDK_PATH. Follow the steps below to accomplish that.
Click on the CLion menu name
Click on Preferences
Open up the Build, Execution, Deployment section
Click on CMake
On the right on the screen, in the Debug profile, fill out the Environment field with the appropriate value of your pico-sdk path as shown in the example below.
You will notice that I added a Release profile. You may choose to do so as well. If your settings are correct you will see an output similar to the following at the bottom of the IDE.
You are now ready to run a build using one of two methods:
You can build all of the artifacts by using the Build menu.
You can build one artifact by selecting it from the dropdown in the middle of the toolbar.
I will proceed to build the blink artifact. You could take a look at the folder named blink within the pico-examples folder. It is made up of two files: a code file and a make file.
To start the build, click on the icon that looks like a hammer to the left of the dropdown. You will see some scrolling text in the build window. You should see a message with "Build Finished" when this completes.
The resulting binary file will be in a folder called blink within a folder called cmake-build-debug (because my build used a debug profile).
At this point, you have a .uf2 file that you can flash onto your pico.
Visual Studio Code
VSCode is a pretty popular IDE. If you happen to be using it then follow these steps to set it up to work with CMake.
First, navigate to your pico-examples folder, then run the following commands
mkdir .vscode
cd .vscode
touch settings.json
Next, open up settings.json with your favorite editor and populate it with the following.
{ "cmake.environment": { "PICO_SDK_PATH":"../../pico-sdk" } }
Next, open the pico-examples folder in VSCode.
Next, install the CMake Tools extension by clicking the Extensions icon and searching for "CMake Tools". Click on the Install button for the CMake Tools extension from Microsoft.
When done, the IDE will ask whether you would like to configure the project to work with CMake.
Click on Yes, and a menu will be presented at the top. Select the GCC compiler from Arm.
Next, click on the settings icon (wheel) under the profile icon on the left side of the screen, and choose settings.
Next, expand Extensions and click on CMake Tools.
Next, locate Cmake:Generator
Fill in the text field with "Unix Makefiles" as shown in the image below.
That's all you need to do. However, it's also advisable to install the C/C++ extension from Microsoft.
The VSCode configuration will add a folder called build to your pico-examples. All of your build outputs will be contained there.
The bottom toolbar will give you buttons for choosing your build option (debug or release) as well as running the build.
The following screen shows the output of building the target called blink.
You are now ready to copy the .uf2 file onto the pico board.
Flashing the Pico
My pico comes with a lovely cable with a power button on it. This makes it easier to put the board into BOOTSEL mode for accessing it as a flash storage device.
Proceed with the following steps to copy the file onto the pico board.
Open a Finder window
Navigate to any of the build folders within the pico-examples folder
Navigate to the blink folder (assuming you are using my example)
Locate the .uf2 file but don't do anything yet
Hold down the Boot button while connecting the pico to the computer (if you have a power button then this would be the time to turn it on).
Keep holding the Boot button until the pico appears as a drive in your finder window. This takes approximately 3 seconds.
Release the Boot button
copy the uf2 file across to the pico board
The above sequence will cause the board to reboot after flashing the firmware. You should now see the board blinking.
You will get an alert from your OS telling you to eject the device before disconnecting it. There isn't a way of doing that and it's fine because that is the only file you needed to copy across.
Using Arduino IDE
The Arduino IDE provides support for Raspberry Pi Pico along with other RP2040 boards such as the Arduino Nano RP2040 Connect.
If you make use of the Arduino IDE, you will not drag your file across manually. Instead, the IDE will flash the board for you. You also have the benefit of writing your code in Arduino format and making use of their libraries.
Install Board Files
Follow these steps to install the board package.
Open up the Arduino IDE
Go to Tools -> Board -> Boards Manager
Search for "RP2040"
Install the "Arduino Mbed OS RP2040 Boards" package
Select the Pico Board
Use these steps to set the board as the target in the IDE.
Go to Tools -> Board -> Arduino Mbed OS RP2040 Boards
Select Raspberry Pi Pico
Open An Example Sketch
Follow these steps to open the example sketch.
Navigate to File -> Examples -> Basics
Select Blink
Flash the Sketch
Follow these steps to flash the example sketch onto the pico board.
Verify the sketch using the checkmark on the toolbar
Go to Tools -> Port and confirm that the only thing there is an incoming Bluetooth.
Disconnect the pico board if it's connected to your computer (or turn off the cable switch)
Hold down the Boot button and connect the board (or turn on the cable switch).
Go to Tools -> Port and confirm that you now have a new port. Select this.
Upload the sketch using the button on the toolbar.
The board should now reboot and you should see the onboard LED flashing.
Comments