How to setup Raspberry Pi Pico 2 W on Windows/MacOS/Linux
Published: December 28, 2024
This guide will show you how to set up PICO SDK on Windows,MacOS,Linux and with diffrent configurations.
1. Prepare Your Host Machine
•Download and Extract the Required Files
- First, you’ll need to download the necessary toolchain and Raspberry Pi Pico SDK:
- Linux
wget https://github.com/raspberrypi/pico-sdk/archive/refs/tags/1.2.0.tar.gz
tar -xvzf 1.2.0.tar.gz
mv pico-sdk ~/pico-sdk
Download the ZIP version from Raspberry Pi Pico SDK GitHub.
• Install the Compiler
- Linux
To set up the C++ development environment for Raspberry Pi Pico on Linux, install the required dependencies and toolchain by following these commands:
sudo apt update
sudo apt install gcc-arm-none-eabi libnewlib-arm-none-eabi cmake build-essential
For Windows, you’ll need to set up MSYS2, which provides a Unix-like development environment:
- Install MSYS2.
- Open MSYS2 and update package databases:
pacman -Syu
pacman -S mingw-w64-x86_64-gcc
pacman -S make
On macOS, you need Homebrew to install the toolchain:
brew install arm-none-eabi-gcc cmake libusb
2. Set up the Raspberry Pi Pico SDK
• Create Environment for PICO SDK
- Now, clone or extract the Raspberry Pi Pico SDK to the desired location on all systems:
git clone https://github.com/raspberrypi/pico-sdk.git
Make sure the PICO_SDK_PATH environment variable is set on all systems.
echo "export PICO_SDK_PATH=~/pico-sdk" >> ~/.bashrc
source ~/.bashrc
• Create a C++ Project
- Example for a Hello World program:
- Create a folder for the project:
mkdir -p ~/pico-project
- CMakeLists.txt
- main.cpp
cmake_minimum_required(VERSION 3.13)
# set the project name
project(hello-pico CXX)
# initialize the Raspberry Pi Pico SDK
pico_sdk_init()
# add the executable
add_executable(hello-pico main.cpp)
# create map/bin/hex file etc.
pico_add_extra_outputs(hello-pico)
# link the pico_stdlib
target_link_libraries(hello-pico pico_stdlib)
#include "pico/stdlib.h"
int main() {
// initialize chosen serial port
stdio_init_all();
while (true) {
printf("Hello, Raspberry Pi Pico 2 W!\n");
sleep_ms(1000);
}
}
5. Build and Flash Your Program
• For Linux/macOS
- 1. Navigate to your project directory:
cd ~/pico-project
mkdir build
cd build
cmake ..
make
picotool load ../../build/hello-pico.uf2
• For Windows
- 1. Using MSYS2 (if on Windows):
Open MSYS2 shell and follow the same steps as above. After building the project, flash it onto your Pico device.
6. Verifying the Program
• For Linux/macOS:
- After flashing your Raspberry Pi Pico, you should see it printing “Hello, Raspberry Pi Pico 2 W!” every second via the serial terminal connected to your device.
- Use the following command to check the output on /dev/ttyACM0 (might differ):
screen /dev/ttyACM0 115200
• For Windows:
- Open the serial monitor using software like PuTTY or the Arduino IDE’s serial monitor and connect to the appropriate COM port at 115200 baud.