I am quite enthusiastic about the new Raspberry Pico. However I find the C SDK not very friendly and I prefer to have something as simple as the Arduino API. I did not want to wait for the official Arduino support – so I started my own project.

So the question is, can we use any Standard Arduino Libraries with this and the answer is yes we can!

We just need to use a little bit of cmake magic for this. For the example I am using my Spektrum Satellite Arduino Library:

Download the Library From Github

cmake has some ExternalProject functionality. Unfortunately it is executed on build and assumes that the project is a cmake project which contains a CMakeList.txt as well – which is not the case for most of the existing Arduino libraries. Fortunately there is also a command which is executed on configuration: FetchContent

With the following code we can execute a “git clone” command in order to get the library into the current build directory:

include(FetchContent)

FetchContent_Declare( spektrum_satellite 
    GIT_REPOSITORY https://github.com/pschatzmann/SpektrumSatellite.git
    GIT_TAG  master
)
FetchContent_MakeAvailable(spektrum_satellite)

Of cause you can skip this step if you have the source code already anywhere on your system.

Include Header Files

Next we need to make sure that the compiler finds the new header files. We just include the source code of the downloaded library with include_directories:

# Define include directories
include_directories(
    "${spektrum_satellite_SOURCE_DIR}/src/"
    ...
)

Define .cpp Files

Finally – if the Arduino Project is not header only and contains .c or .cpp source files – we need to make them known. So first we collect them in a variable with the help of the file(GLOB) command. In our case we use LIB_SRC. To keep things consistent we also get the all the source files from the current source directory into the variable CURRENT_SRC. This covers the current Arduino sketch:

file(GLOB LIB_SRC "${spektrum_satellite_SOURCE_DIR}/src/*.cpp")
file(GLOB CURRENT_SRC  ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp )

Now we are ready to add all source files to the add_executable:

add_executable(example_sketch ${CURRENT_SRC} ${LIB_SRC} )

Buiding the Project

We just process the same steps as always from the sketch directory:

mkdir build
cd build 
cmake ..
make

The full example can be found on Github.

Categories: ArduinoPico

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *