Top Related Projects
Espressif IoT Development Framework. Official development framework for Espressif SoCs.
The Official Arduino AVR core
Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
Arm Mbed OS is a platform operating system designed for the internet of things
MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems
Quick Overview
The Raspberry Pi Pico SDK is the official C/C++ development kit for the Raspberry Pi Pico microcontroller board. It provides a comprehensive set of libraries, tools, and examples to facilitate software development for the RP2040 microcontroller, which is the heart of the Raspberry Pi Pico.
Pros
- Comprehensive and well-documented API for RP2040 peripherals
- Includes a wide range of examples and demo projects
- Supports both C and C++ programming languages
- Regular updates and active community support
Cons
- Steep learning curve for beginners in embedded programming
- Limited to Raspberry Pi Pico and RP2040-based boards
- Requires additional tools for debugging and flashing
- Some advanced features may require in-depth understanding of the RP2040 architecture
Code Examples
- Blinking an LED:
#include "pico/stdlib.h"
int main() {
const uint LED_PIN = 25;
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
while (true) {
gpio_put(LED_PIN, 1);
sleep_ms(500);
gpio_put(LED_PIN, 0);
sleep_ms(500);
}
}
- Reading an analog value:
#include "pico/stdlib.h"
#include "hardware/adc.h"
int main() {
adc_init();
adc_gpio_init(26);
adc_select_input(0);
while (true) {
uint16_t result = adc_read();
printf("Raw value: %d\n", result);
sleep_ms(500);
}
}
- Using PIO for fast GPIO:
#include "pico/stdlib.h"
#include "hardware/pio.h"
#include "hardware/clocks.h"
#include "blink.pio.h"
int main() {
PIO pio = pio0;
uint offset = pio_add_program(pio, &blink_program);
uint sm = pio_claim_unused_sm(pio, true);
blink_program_init(pio, sm, offset, 25);
while (true) {
pio_sm_put_blocking(pio, sm, 1000);
}
}
Getting Started
-
Install the Pico SDK:
git clone https://github.com/raspberrypi/pico-sdk.git cd pico-sdk git submodule update --init
-
Set up environment variables:
export PICO_SDK_PATH=/path/to/pico-sdk
-
Create a new project:
mkdir my_project && cd my_project cmake -B build -S .
-
Build and flash your project:
cd build make picotool load -f my_project.uf2
Competitor Comparisons
Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Pros of esp-idf
- More comprehensive ecosystem with extensive libraries and tools
- Better support for wireless connectivity (Wi-Fi, Bluetooth)
- Larger community and more extensive documentation
Cons of esp-idf
- Steeper learning curve due to complexity
- Higher power consumption compared to Pico SDK
- Larger code footprint and resource requirements
Code Comparison
pico-sdk example:
#include "pico/stdlib.h"
int main() {
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
while (true) {
gpio_put(LED_PIN, 1);
sleep_ms(500);
gpio_put(LED_PIN, 0);
sleep_ms(500);
}
}
esp-idf example:
#include "driver/gpio.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
void app_main() {
gpio_pad_select_gpio(LED_PIN);
gpio_set_direction(LED_PIN, GPIO_MODE_OUTPUT);
while (1) {
gpio_set_level(LED_PIN, 1);
vTaskDelay(500 / portTICK_PERIOD_MS);
gpio_set_level(LED_PIN, 0);
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
The esp-idf example shows the use of FreeRTOS, which is not present in the pico-sdk. This illustrates the more complex, but feature-rich nature of esp-idf compared to the simpler pico-sdk.
The Official Arduino AVR core
Pros of ArduinoCore-avr
- Extensive community support and vast library ecosystem
- Simpler learning curve for beginners
- Cross-platform compatibility (Windows, macOS, Linux)
Cons of ArduinoCore-avr
- Limited processing power and memory compared to Pico SDK
- Less flexibility for advanced users and complex projects
- Slower development cycle for core updates
Code Comparison
ArduinoCore-avr:
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
Pico SDK:
#include "pico/stdlib.h"
int main() {
const uint LED_PIN = 25;
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
while (true) {
gpio_put(LED_PIN, 1);
sleep_ms(1000);
gpio_put(LED_PIN, 0);
sleep_ms(1000);
}
}
The ArduinoCore-avr code is more abstracted and user-friendly, while the Pico SDK code offers more direct hardware control but requires more low-level understanding. ArduinoCore-avr uses a setup() and loop() structure, whereas Pico SDK uses a traditional main() function with an infinite loop.
Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
Pros of Zephyr
- Supports a wide range of hardware platforms and architectures
- Offers a comprehensive RTOS with advanced features like power management and networking
- Has a larger community and ecosystem, with more third-party contributions
Cons of Zephyr
- Steeper learning curve due to its complexity and extensive feature set
- Potentially higher resource overhead compared to the lightweight Pico SDK
- May require more configuration and setup for simple projects
Code Comparison
Zephyr example (LED blink):
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#define LED_PIN DT_GPIO_PIN(DT_ALIAS(led0), gpios)
#define LED_PORT DT_GPIO_LABEL(DT_ALIAS(led0), gpios)
void main(void) {
const struct device *dev = device_get_binding(LED_PORT);
gpio_pin_configure(dev, LED_PIN, GPIO_OUTPUT_ACTIVE);
while (1) {
gpio_pin_toggle(dev, LED_PIN);
k_msleep(1000);
}
}
Pico SDK example (LED blink):
#include "pico/stdlib.h"
int main() {
const uint LED_PIN = 25;
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
while (true) {
gpio_put(LED_PIN, 1);
sleep_ms(500);
gpio_put(LED_PIN, 0);
sleep_ms(500);
}
}
Arm Mbed OS is a platform operating system designed for the internet of things
Pros of mbed-os
- Broader hardware support, covering a wide range of ARM-based microcontrollers
- More comprehensive RTOS features, including thread management and inter-thread communication
- Extensive libraries and middleware for various peripherals and communication protocols
Cons of mbed-os
- Steeper learning curve due to its more complex architecture and feature set
- Potentially higher resource usage, which may impact performance on resource-constrained devices
- Less optimized for the specific hardware of the Raspberry Pi Pico
Code Comparison
mbed-os example:
#include "mbed.h"
DigitalOut led(LED1);
int main() {
while (1) {
led = !led;
ThisThread::sleep_for(500ms);
}
}
pico-sdk example:
#include "pico/stdlib.h"
int main() {
const uint LED_PIN = 25;
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
while (1) {
gpio_put(LED_PIN, 1);
sleep_ms(500);
gpio_put(LED_PIN, 0);
sleep_ms(500);
}
}
MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems
Pros of MicroPython
- Easier to learn and use, especially for beginners
- Faster development and prototyping
- Extensive library support and community-driven ecosystem
Cons of MicroPython
- Lower performance compared to C/C++
- Higher memory usage
- Limited access to low-level hardware features
Code Comparison
MicroPython:
from machine import Pin
import time
led = Pin(25, Pin.OUT)
while True:
led.toggle()
time.sleep(1)
Pico SDK (C):
#include "pico/stdlib.h"
int main() {
gpio_init(25);
gpio_set_dir(25, GPIO_OUT);
while (true) {
gpio_put(25, 1);
sleep_ms(1000);
gpio_put(25, 0);
sleep_ms(1000);
}
}
The MicroPython code is more concise and readable, while the Pico SDK code offers more direct hardware control and potentially better performance. MicroPython abstracts away many low-level details, making it easier for beginners to get started, but may sacrifice some efficiency. The Pico SDK provides greater flexibility and optimization possibilities at the cost of increased complexity.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Raspberry Pi Pico SDK
The Raspberry Pi Pico SDK (henceforth the SDK) provides the headers, libraries and build system necessary to write programs for the RP-series microcontroller-based devices such as the Raspberry Pi Pico or Raspberry Pi Pico 2 in C, C++ or assembly language.
The SDK is designed to provide an API and programming environment that is familiar both to non-embedded C developers and embedded C developers alike.
A single program runs on the device at a time and starts with a conventional main()
method. Standard C/C++ libraries are supported along with
C-level libraries/APIs for accessing all of the RP-series microcontroller's hardware including PIO (Programmable IO).
Additionally, the SDK provides higher level libraries for dealing with timers, synchronization, Wi-Fi and Bluetooth networking, USB and multicore programming. These libraries should be comprehensive enough that your application code rarely, if at all, needs to access hardware registers directly. However, if you do need or prefer to access the raw hardware registers, you will also find complete and fully-commented register definition headers in the SDK. There's no need to look up addresses in the datasheet.
The SDK can be used to build anything from simple applications, fully-fledged runtime environments such as MicroPython, to low level software such as the RP-series microcontroller's on-chip bootrom itself.
The design goal for entire SDK is to be simple but powerful.
Additional libraries/APIs that are not yet ready for inclusion in the SDK can be found in pico-extras.
Documentation
See Getting Started with the Raspberry Pi Pico-Series for information on how to setup your hardware, IDE/environment and how to build and debug software for the Raspberry Pi Pico and other RP-series microcontroller based devices.
See Connecting to the Internet with Raspberry Pi Pico W to learn more about writing applications for your Raspberry Pi Pico W that connect to the internet.
See Raspberry Pi Pico-Series C/C++ SDK to learn more about programming using the SDK, to explore more advanced features, and for complete PDF-based API documentation.
See Online Raspberry Pi Pico SDK API docs for HTML-based API documentation.
Example code
See pico-examples for example code you can build.
Getting the latest SDK code
The master branch of pico-sdk
on GitHub contains the
latest stable release of the SDK. If you need or want to test upcoming features, you can try the
develop branch instead.
Quick-start your own project
Using Visual Studio Code
You can install the Raspberry Pi Pico Visual Studio Code extension in VS Code.
Unix command line
These instructions are extremely terse, and Linux-based only. For detailed steps, instructions for other platforms, and just in general, we recommend you see Raspberry Pi Pico-Series C/C++ SDK
-
Install CMake (at least version 3.13), and a GCC cross compiler
sudo apt install cmake gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib
-
Set up your project to point to use the Raspberry Pi Pico SDK
-
Either by cloning the SDK locally (most common) :
-
git clone
this Raspberry Pi Pico SDK repository -
Copy pico_sdk_import.cmake from the SDK into your project directory
-
Set
PICO_SDK_PATH
to the SDK location in your environment, or pass it (-DPICO_SDK_PATH=
) to cmake later. -
Setup a
CMakeLists.txt
like:cmake_minimum_required(VERSION 3.13...3.27) # initialize the SDK based on PICO_SDK_PATH # note: this must happen before project() include(pico_sdk_import.cmake) project(my_project) # initialize the Raspberry Pi Pico SDK pico_sdk_init() # rest of your project
-
-
Or with the Raspberry Pi Pico SDK as a submodule :
-
Clone the SDK as a submodule called
pico-sdk
-
Setup a
CMakeLists.txt
like:cmake_minimum_required(VERSION 3.13...3.27) # initialize pico-sdk from submodule # note: this must happen before project() include(pico-sdk/pico_sdk_init.cmake) project(my_project) # initialize the Raspberry Pi Pico SDK pico_sdk_init() # rest of your project
-
-
Or with automatic download from GitHub :
-
Copy pico_sdk_import.cmake from the SDK into your project directory
-
Setup a
CMakeLists.txt
like:cmake_minimum_required(VERSION 3.13) # initialize pico-sdk from GIT # (note this can come from environment, CMake cache etc) set(PICO_SDK_FETCH_FROM_GIT on) # pico_sdk_import.cmake is a single file copied from this SDK # note: this must happen before project() include(pico_sdk_import.cmake) project(my_project) # initialize the Raspberry Pi Pico SDK pico_sdk_init() # rest of your project
-
-
Or by cloning the SDK locally, but without copying
pico_sdk_import.cmake
:-
git clone
this Raspberry Pi Pico SDK repository -
Setup a
CMakeLists.txt
like:cmake_minimum_required(VERSION 3.13) # initialize the SDK directly include(/path/to/pico-sdk/pico_sdk_init.cmake) project(my_project) # initialize the Raspberry Pi Pico SDK pico_sdk_init() # rest of your project
-
-
-
Write your code (see pico-examples or the Raspberry Pi Pico-Series C/C++ SDK documentation for more information)
About the simplest you can do is a single source file (e.g. hello_world.c)
#include <stdio.h> #include "pico/stdlib.h" int main() { stdio_init_all(); printf("Hello, world!\n"); return 0; }
And add the following to your
CMakeLists.txt
:add_executable(hello_world hello_world.c ) # Add pico_stdlib library which aggregates commonly used features target_link_libraries(hello_world pico_stdlib) # create map/bin/hex/uf2 file in addition to ELF. pico_add_extra_outputs(hello_world)
Note this example uses the default UART for stdout; if you want to use the default USB see the hello-usb example.
-
Setup a CMake build directory. For example, if not using an IDE:
$ mkdir build $ cd build $ cmake ..
When building for a board other than the Raspberry Pi Pico, you should pass
-DPICO_BOARD=board_name
to thecmake
command above, e.g.cmake -DPICO_BOARD=pico2 ..
orcmake -DPICO_BOARD=pico_w ..
to configure the SDK and build options accordingly for that particular board.Specifying
PICO_BOARD=<booardname>
sets up various compiler defines (e.g. default pin numbers for UART and other hardware) and in certain cases also enables the use of additional libraries (e.g. wireless support when building forPICO_BOARD=pico_w
) which cannot be built without a board which provides the requisite hardware functionality.For a list of boards defined in the SDK itself, look in this directory which has a header for each named board.
-
Make your target from the build directory you created.
$ make hello_world
-
You now have
hello_world.elf
to load via a debugger, orhello_world.uf2
that can be installed and run on your Raspberry Pi Pico-series device via drag and drop.
RISC-V support on RP2350
See Raspberry Pi Pico-series C/C++ SDK for information on setting up a build environment for RISC-V on RP2350.
Top Related Projects
Espressif IoT Development Framework. Official development framework for Espressif SoCs.
The Official Arduino AVR core
Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
Arm Mbed OS is a platform operating system designed for the internet of things
MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot