Template and Examples in C/C++
for the Raspberry Pi Pico using the official SDK, via Docker.
- The official SDK is cloned into the Docker image, see Dockerfile for details
- Check out the examples in src/
- Utilize existing code for an own project or start with a basic example
- Having Docker in place, the projects can be built with a single command
Feature | Example | Info | Tested on boards |
---|---|---|---|
blink | src/main_blink.c | Hello world blink example | pico , pico_w |
debounce | src/main_debounce.c | Button debouncer | pico , pico_w |
ws2812 | src/main_ws2812.c | Basic ws2812 light controls | pico , pico_w |
A Docker installation and basic Docker knowledge is required.
- Build the Docker image:
docker build -t rpico .
- Build the examples via Docker with one of these commands. Replace
<pico_board>
with the desired board to build for, such aspico
orpico_w
.
# Bash
docker run --rm -v $(pwd):/code -w /code rpico /bin/bash ./build.bash <pico_board>
# Powershell
docker run --rm -v ${PWD}:/code -w /code rpico /bin/bash ./build.bash <pico_board>
- Drop any UF2 binary from
build_<pico_board>/
directory onto the Pico following the official documentation.
The above should suffice for simple building of the examples. Here are some more things to do.
Use this repository as a template for an own project:
- Fork or download this repository
- Delete unneeded source files from src/
- e.g. just keep
main_blink.c
to start with
- e.g. just keep
- Delete unneeded build targets from CMakeLists.txt
- Each
main_[...].c/.cpp
file in src/ has a corresponding block in CMakeLists.txt defining an executable target - e.g. just keep the block starting with
add_executable(blink ...
- Each
More control over the build command:
# Bash
docker run --rm -v $(pwd):/code -w /code rpico /bin/bash -c "mkdir -p build && cd build && cmake -DPICO_BOARD=pico .. && make"
# Powershell
docker run --rm -v ${PWD}:/code -w /code rpico /bin/bash -c "mkdir -p build && cd build && cmake -DPICO_BOARD=pico .. && make"
Start Docker container with an interactive shell:
# Bash
docker run --rm -it -v $(pwd):/code rpico
# Powershell
docker run --rm -it -v ${PWD}:/code rpico
- The source code in this repository is licensed under the MIT license (if not stated otherwise).
- Thirdparty components:
- src/ws2812.pio (license in file)