This is a part of a series. Make sure you read all the posts to get the full picture.
Part 1: Required softwares
Part 2: The first program
Part 3: Debugging

In the previous post we installed the necessary softwares to get started with embedded development on the Raspberry Pi Pico. This time let's make the "Hello world" of embedded development: blinking an LED.

Pico SDK

The Pico SDK is a software layer that lets you write code in a much simpler way than directly communicating with the microcontroller. Get the SDK by running these commands:

cd ~/Code
git clone -b master --recurse-submodules
https://github.com/raspberrypi/pico-sdk.git

You'll need to add the PICO_SDK_PATH variable to your profile so CMake can access it:

export PICO_SDK_PATH="$HOME/Code/pico-sdk" Pico SDK home First compile First we'll create a simple program that does nothing but it helps us understand what files are needed to compile a program. We need to create a new folder, copy the Pico SDK CMake file to it and create a CMakeLists.txt file to configure the board and link libraries from the SDK: 1. mkdir PicoTest to create a project PicoTest 2. cd PicoTest 3. cp ../pico-sdk/external/pico_sdk_import.cmake . 4. Create CMakeLists.txt — see listing below 5. touch source.h 6. echo '#include "source.h"' > source.c From within Visual Studio Code, open the folder PicoTest. When CMakeTools asks you if to configure project, say yes and select the kit GCC for arm-none-eabi x.y.z. If everything goes well there should be a build folder with a PicoTest.uf2 file in it. You could upload this file to a Pico board and it would run but obviously it wouldn't do anything. So next let's create a program that actually does something. The classic example program blinks the built-in LED on the Pico and this is what we're going to do. We'll create a new project but instead of manually going through the same steps as previously, let's use boilerplate script that creates the necessary files for us. 1. git clone git@github.com:peterzimon/pico-toolbox.git – this repo contains a couple of small useful tools. The script in the makepico folder is the one that creates the base project with all the extra files that's needed. It's heavily inspired by this repo. 2. Open your bash config and add makepico script to the path: export PATH="$PATH:\$HOME/Code/pico-toolbox/makepico"
3. Run makepico.sh blink – this creates a new folder called blink with all the necessary files. Note that by default it creates C++ files, if you want to use plain C you can run makepico.sh blink -c instead.

Open the folder in VSCode and when asked, select the GCC Arm kit.

If everything goes alrite the project should auto-build and you should see a build folder with a lot of files in it.

Copy and paste this to src/main.cpp:

Click on Build in the VSCode toolbar to re-build the code.

The simplest way to run a program on a Pico is to mount the board as an USB device and upload a u2f file to it:
2. Drag and drop build/blink.u2f to the Pico's root folder. The Pico should automatically unmount itself (resulting in a "Disk ejected improperly" error 😤) and the Pico's built-in LED should start blinking.