This repo contains:
- pico-sdk from https://github.com/raspberrypi/pico-sdk
- picotool from https://github.com/raspberrypi/picotool
- Toolchain compiler arm-none-eabi 9.3.1 from https://developer.arm.com/-/media/files/downloads/gnu-rm/9-2020q2/gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2
- micro_ros_raspberrypi_pico_sdk from https://github.com/micro-ROS/micro_ros_raspberrypi_pico_sdk
This repository easily sets up the environment needed to program and build for Raspberry Pi Pico (especially regarding Micro-ROS and ROS2 Jazzy) by having all stated repos together in a single directory. It includes:
-
Two shell scripts:
- build_enviroment.sh – sets all required environment variables by injecting code into the
.bashrcfile and builds the required repos. - build.sh – cleans and builds individual Micro-ROS projects by removing the old build folder and calling
cmakewith the correct arguments.
- build_enviroment.sh – sets all required environment variables by injecting code into the
-
CMakeLists.txt example and helper_functions.cmake – contain important functions and lines to help organize and understand the building process easily and cleanly. (The building process of Micro-ROS on Pico is very messy and sometimes obscure.)
-
Multiple organized code folders, each acting as its own library (with
src,includefolders, and aCMakeLists.txt) to be modularly used in projects. These libraries vary from Micro-ROS management and wrapper classes to code that interacts with and manages sensor modules such as IMU and GPS. -
apps folder – where Micro-ROS projects can be created for clean organization. Projects do not necessarily have to be in this directory, but this is recommended.
The official micro_ros_raspberrypi_pico_sdk README also lists git and doxygen as dependencies. Additionally, docker is needed to run the micro-ROS agent.
sudo apt update
sudo apt install cmake python3 build-essential gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib pkg-config libusb-1.0-0-dev git doxygen docker.io
sudo systemctl enable dockerEdit the .bashrc file to include environment variables describing the locations of the different directories.
- Automatic: Run
build_enviroment.shin the root directory (recommended and you wont have to do steps #3 till #5). - Manual: Copy the block between the two
EOFmarkers from the script and update theMICROROS_PATHvariable to your repo root path.
Notes:
- Running
build_enviroment.shwill overwrite any manually added code between the markers. - Make the script executable:
chmod +x build_enviroment.sh
pico-sdk does not need explicit building with cmake or make, since it is compiled automatically when building your executable using its source and include folders.
picotool is used to control the Raspberry Pi Pico (load, reboot, etc.) and is important for Micro-ROS.
cd picotool
mkdir build
cd build
cmake ..
makeThe static library is precompiled in micro_ros_raspberrypi_pico_sdk/libmicroros. Building will create a demo to verify everything is working.
cd micro_ros_raspberrypi_pico_sdk
mkdir build
cd build
cmake ..
makeInside the pico_w_libraries directory:
- The example
CMakeLists.txtshould be read carefully, it can be copied inside every project directory and edited to suit your needs. - The first half and the absolute end of the file should barely be changed across projects.
- The middle sections can be adapted to your coding style.
- Understanding
helper_functions.cmakeand at least one library’sCMakeLists.txtis important.
All of this assumes familiarity with CMake.
- Copy
build.shinto the root directory of your Micro-ROS project folder.- Example:
multiple_sensor_publisher/build.sh
- Example:
build.shdeletes the oldbuildfolder (with confirmation), runscmakewith the toolchain compiler, then callsmake.
Important Notes:
- Deleting and rebuilding the
buildfolder often resolves old compile issues that otherwise wont be resolved. - Make
build.shexecutable:chmod +x build.sh
- The environment only needs to be built once unless the repo folder is moved.
- After building, the generated
.uf2file is needed to flash the Pi Pico. Location depends on yourCMakeLists.txt(example:build/bin). - Flashing:
flash_raspberrypi_pico 'path/to/your/file.uf2' - After the first environment build, source
.bashrcif building apps in the same shell:source ~/.bashrc
- Libraries may have dependencies on each other. Read their
CMakeLists.txtcarefully. - Open and read comments in both
build_enviroment.shandbuild.sh, they explain very important things in great detail.