Using the RaspberryPi Pico SDK (for the RP2040) =============================================== Prerequisite ***************** Follow the Raspberry Pi Foundation's `"Getting Started with Pico" document `_ to setup a proper development environment on your host PC (the machine that will build your project). Either set an environment variable named ``PICO_SDK_PATH`` that points to your local clone of the pico-sdk or put the pico-sdk next to the RF24Revamped folder or next to the folder containing your project using the RF24Revamped library: .. code-block:: text path/to/github/repos/ pico-sdk/ RF24Revamped/ my_rf24_project/ Alternatively, the RF24Revamped repository can be included into your project's "lib" folder as copies or git submodules. For more detail, see the below instructions to incorporate RF24Revamped library into your project. Building the RF24Revamped examples for the Pico SDK *************************************************** 1. Create a "build" directory in the RF24Revamped repository's root directory and navigate to it: .. code-block:: shell cd RF24Revamped mkdir build cd build 2. Configure CMake for your desired build type and specific RP2040-based board .. code-block:: shell cmake ../examples_pico -DCMAKE_BUILD_TYPE=Release -DPICO_BOARD=pico The supported RP2040-based boards are listed in header files in the Pico SDK repository's `pico-sdk/src/boards/include/boards/\.h files `_. If the ``-DPICO_BOARD`` option is not specified, then the Pico SDK will default to building for the Raspberry Pi Pico board. 3. Build the examples using the CMakeLists.txt file located in the RF24Revamped/examples_pico directory. .. code-block:: shell cmake --build . --config Release Notice we specified the build type again using the ``--config`` option. .. note:: If you see an error stating ``'PICO_DEFAULT_SPI_SCK_PIN' was not declared in this scope``, then it means the board you selected with the `-DPICO_BOARD` option (in step 2) does not have a default set of SPI pins defined for it. To workaround this error, see the below instructions to use different pins for the SPI bus. Incorporating RF24Revamped libs into your project ************************************************* In order to use the RF24Revamped libraries in your RP2040 based project: 1. Make a copy of the RF24Revamped library (and optionally RF24Network and RF24Mesh libraries) in a "lib" directory located in your project's root directory. .. code-block:: text path/to/my/project/ lib/ RF24Revamped/ src/ CMakeLists.txt ... Alternatively you can add the RF24Revamped repository as `git submodules `_. 2. Include their CMakeLists.txt files from the RF24Revamped library in your project's top-level CMakeLists.txt file (usually located in the "src" directory). The following snippet assumes that your project's "src" directory is on the same level as the previously mentioned "lib" directory. .. code-block:: cmake include(../lib/RF24Revamped/CMakeLists.txt) 3. In the same CMakeLists.txt file from step 2, add the RF24Revamped library into the ``target_link_libraries`` configuration: .. code-block:: cmake target_link_libraries(${CMAKE_PROJECT_NAME} # ... Your project's other libraries ... RF24Revamped ) If you are using tinyUSB, this line (or similar) should already exist: .. code-block:: cmake target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}) 4. Finally, remember to include the necessary RF24Revamped* library's header files in your project's source code where applicable. .. code-block:: cpp #include Using different pins for the SPI bus ************************************ Initially (without modification), the SPI bus uses the default pins defined in the Pico SDK repository's `pico-sdk/src/boards/include/boards/\.h files `_. However, the some boards do not define the necessary pins to use as defaults. This can be rememdied using either project source code or build-time configuration. .. note:: There is no support for software driven SPI on RP2040 based boards at this time. If someone is so inclined to implement this using the Pico SDK's PIO (Programable Input Output) feature, please submit an issue or pull request to the `RF24 repository `_. .. warning:: Before deciding what pins to use for the SPI bus, review the `GPIO pins' "Function Select Table" in the Pico SDK documentation `_. There are essentially 2 SPI buses with multiple pin options for each. Project Source code option -------------------------- This option is the most reliable and flexible. It involves calling `SPI.begin()` and then passing the ``SPI`` object to `RF24Revamped::begin(_SPI*) `_. .. code-block:: cpp #include RF24Revamped radio(7, 8); // pin numbers connected to the radio's CE and CSN pins (respectively) int main() { // again please review the GPIO pins' "Function Select Table" in the Pico SDK docs SPI.begin(spi0, 2, 3, 4); // must use spi0 or spi1 as 1st parameter if (!radio.begin(&SPI)) { printf("Radio hardware is not responding!\n"); } // continue with program as normal ... } Build-time configuration option ------------------------------- To specify the default SPI pins used at build time, you can use either: 1. declare these pins in the CMakeLists.txt file .. code-block:: cmake target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC PICO_DEFAULT_SPI=0 # can only be 0 or 1 (as in `spi0` or `spi1`) PUBLIC PICO_DEFAULT_SPI_SCK_PIN=2 # depends on which SPI bus (0 or 1) is being used PUBLIC PICO_DEFAULT_SPI_TX_PIN=3 # depends on which SPI bus (0 or 1) is being used PUBLIC PICO_DEFAULT_SPI_RX_PIN=4 # depends on which SPI bus (0 or 1) is being used ) 2. additional command line arguments .. code-block:: shell cmake --build . --config Release -DPICO_DEFAULT_SPI=0 -DPICO_DEFAULT_SPI_SCK_PIN=2 -DPICO_DEFAULT_SPI_TX_PIN=3 -DPICO_DEFAULT_SPI_RX_PIN=4