Arduino RP2040 Connect Nano Setup

This is to document the setup instructions for flashing an Arduino RP2040 Connect Nano from a RPi4 using the command line tool ‘picotool’ and the pico-sdk. Not only to publish but for my own reference 😀

As a side note, I am using a RPi4 as a host because I like the Linux interface and would prefer it for situations of CI and things that may come in future projects.

Helpful Links

Getting the tools

These are to be executed on the RPi4 over SSH:

  1. Install picotool
    • See here for instructions
    • Make sure that running ‘picotool’ doesn’t give you a ‘cannot be found’ sort of error.
  2. Get the pico-sdk
    • See here for instructions

Setting up the project

With the tools downloaded and installed we should be ready to get started creating our project directories.

mkdir blink
cd blink
touch blink.c
touch CMakeLists.txt
# Insert the data below into your CMakeLists.txt files with vim here
cp ~/pico/pico-examples/pico_sdk_import.cmake ./ 
mkdir build
cd build
cmake -D"PICO_BOARD=arduino_nano_rp2040_connect" ..

In CMakeLists.txt add:

cmake_minimum_required(VERSION 3.12)

include(pico_sdk_import.cmake)

project(blink)

pico_sdk_init()

add_executable(blink
    blink.c
)

pico_add_extra_outputs(blink)

target_link_libraries(blink pico_stdlib)

And in your blink.c file:

#include "pico/stdlib.h"
#include "pico/binary_info.h"

const uint LED_PIN = PICO_DEFAULT_LED_PIN;

int main() {

    bi_decl(bi_program_description("First Blink"));
    bi_decl(bi_1pin_with_name(LED_PIN, "On-board LED"));

    gpio_init(LED_PIN);
    gpio_set_dir(LED_PIN, GPIO_OUT);
    while (1) {
        gpio_put(LED_PIN, 0);
        sleep_ms(250);
        gpio_put(LED_PIN, 1);
        sleep_ms(1000);
    }
}

Now with both those files populated execute the following from your build directory:

make

After the program has been compiled you should see in your build folder a blink.uf2 file, this is what we will use for flashing the board.

Flashing the Board

Your board should be setup as follows:

Notice the wire on the RP2040 Nano Connect, when you press the reset button on the board this will put the board in a state that allows flashing.

Once you have pressed the reset and entered the flashing state the wire must be disconnected before flashing. Once disconnected run the following from your build folder:

sudo picotool load ./blink.uf2

Once this flashes you should be able to hit the reset button once again to reboot and run the code we just flashed to the board. If all went well the integrated LED on the board should now be flashing!

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.