Video Tutorial (Optional)
Watch first if you want to see the full macOS setup, build, and UF2 flashing process for a Raspberry Pi Pico W C++ project.
Project Overview
Raspberry Pi Pico W USB Serial C++: In this tutorial, you set up the Pico SDK on macOS, build a C++ “Hello, World!” program for the Raspberry Pi Pico W, and read the output over USB serial.
The Raspberry Pi Pico W is based on the RP2040 microcontroller with dual-core ARM Cortex-M0+ processors, flexible I/O, and built-in Wi-Fi. This guide walks through installing tools, initializing the Pico SDK, compiling, flashing a UF2, and verifying serial output using terminal tools.
- Time: 30 to 60 minutes (depending on downloads and installs)
- Skill level: Beginner
- What you will build: A Pico W C++ project that prints “Hello, World!” to a USB serial console
Parts List
From ShillehTek
- ShillehTek store - optional tools, components, and accessories for Pico projects
External
- Raspberry Pi Pico W
- Mac running macOS
- USB cable (data-capable) to connect the Pico W to your Mac
- Homebrew (package manager)
- Pico SDK (from GitHub)
- Terminal tools:
screen(built-in on many systems) orminicom(installable)
Note: This guide uses USB serial (stdio over USB). The Pico W must be connected via USB, and you will connect to a device like /dev/tty.usbmodemXXXX at 115200 baud.
Step-by-Step Guide
Step 1 - Set up the macOS build environment
Goal: Install the required tools and set up the Pico SDK so you can build Pico W projects in C++.
What to do: Install Homebrew (if you do not already have it), then install CMake and the ARM GCC toolchain.
Code:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install cmake gcc-arm-none-eabi
What to do: Clone the Pico SDK and initialize its submodules.
Code:
mkdir -p ~/pico
cd ~/pico
git clone -b master https://github.com/raspberrypi/pico-sdk.git
cd pico-sdk
git submodule update --init
What to do: Set the PICO_SDK_PATH environment variable in your shell configuration file (example shown for Zsh).
Code:
echo 'export PICO_SDK_PATH=~/pico/pico-sdk' >> ~/.zshrc
source ~/.zshrc
Expected result: You can run cmake, and your system has a working ARM toolchain and a local Pico SDK at ~/pico/pico-sdk.
Step 2 - Create a C++ Pico project (CMake + main.cpp)
Goal: Create a minimal Pico W C++ project that can print to USB serial.
What to do: Create a project directory.
Code:
mkdir -p ~/pico/my_project
cd ~/pico/my_project
What to do: Create a CMakeLists.txt file in the project directory.
Code:
cmake_minimum_required(VERSION 3.13)
# Include the Pico SDK initialization script
include($ENV{PICO_SDK_PATH}/pico_sdk_init.cmake)
project(my_project)
# Initialize the Pico SDK
pico_sdk_init()
# Add your executable and source files
add_executable(my_project
main.cpp
)
# Enable USB stdio and disable UART stdio
pico_enable_stdio_usb(my_project 1)
pico_enable_stdio_uart(my_project 0)
# Link the Pico SDK to your project
target_link_libraries(my_project pico_stdlib)
# Create map/bin/hex/uf2 files
pico_add_extra_outputs(my_project)
What to do: Create a main.cpp file that prints “Hello, World!” every second.
Code:
#include "pico/stdlib.h"
#include <cstdio> // Include the C standard IO functions
int main() {
stdio_init_all(); // Initialize standard IO
while (true) {
printf("Hello, World!\n");
sleep_ms(1000);
}
}
Expected result: Your project folder contains CMakeLists.txt and main.cpp, ready to configure and build.
Step 3 - Build and flash the UF2 to the Pico W
Goal: Compile the project and copy the generated .uf2 file to the Pico W.
What to do: Create and enter a build directory, then clean it if needed.
Code:
mkdir -p build
cd build
rm -rf *
What to do: Run CMake to generate build files, then build.
Code:
cmake ..
make
What to do: Flash the firmware to the Pico W.
- Unplug the Pico W from your Mac.
- Hold down the BOOTSEL button.
- While holding BOOTSEL, plug the Pico W back into your Mac. It should appear as a mass storage device named
RPI-RP2. - Copy the generated
.uf2file to the Pico.
Code:
cp my_project.uf2 /Volumes/RPI-RP2/
Expected result: After copying the UF2, the Pico W reboots and starts running the program, printing output over USB serial.
Step 4 - Verify USB serial output (screen or minicom)
Goal: Connect to the Pico W serial device and confirm you can see “Hello, World!” output.
What to do: If you hit the $TERM too long - sorry. error in screen, set TERM to vt100.
Code:
export TERM=vt100
What to do: List serial devices and identify the Pico W device (example: /dev/tty.usbmodemXXXX).
Code:
ls /dev/tty.*
What to do: Connect using screen at 115200 baud.
Code:
screen /dev/tty.usbmodemXXXX 115200
What to do: If you prefer minicom, install it with Homebrew and connect.
Code:
brew install minicom
minicom -b 115200 -o -D /dev/tty.usbmodemXXXX
Expected result: You see “Hello, World!” printed in the terminal every second.
Conclusion
You set up the Pico SDK toolchain on macOS, created a Raspberry Pi Pico W C++ project, built it with CMake, flashed it as a UF2, and verified “Hello, World!” output over USB serial using screen or minicom.
Want the exact parts and accessories for your next Pico build? Grab them from ShillehTek.com. If you want help customizing this workflow for a real product or a larger IoT firmware project, check out our IoT consulting services.
You can also follow along on our other platforms: YouTube 0 0Shilleh. Buy Me A Coffee UpWork. ShillehTek Amazon Store 0 0US ShillehTek Amazon Store 0 0Canada ShillehTek Amazon Store 0 0Japan