@agustfricke
Raspberry pi

Blink the Onboard LED

Blink the onboard LED on your Raspberry Pi Pico

Create Project Folder

mkdir ~/blink_me
cd ~/blink_me
touch CMakeLists.txt

CMake Configuration

Create CMakeLists.txt with the following content:

CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)

project(blink_me)
pico_sdk_init()

add_executable(blink_me
    main.c
)

pico_add_extra_outputs(blink_me)
target_link_libraries(blink_me pico_stdlib)

Create Main Program

Create main.c:

main.c
#include "pico/stdlib.h"

int main() {
    const uint LED_PIN = 25;  
    
    // Initialize
    stdio_init_all();
    gpio_init(LED_PIN);
    gpio_set_dir(LED_PIN, GPIO_OUT);
    
    while (true) {
        gpio_put(LED_PIN, 1);  // Turn LED on
        sleep_ms(1000);
        gpio_put(LED_PIN, 0);  // Turn LED off
        sleep_ms(1000);
    }
}

Build the Project

mkdir build
cd build
cmake ..
make

This will generate a .uf2 file in the build directory.

Connect Raspberry Pi Pico

  1. Disconnect the Pico from USB.
  2. Hold down the BOOTSEL button (small button on the Pico).
  3. While holding BOOTSEL, connect the USB cable.
  4. Release the BOOTSEL button after connecting.

You can monitor USB events in real time:

sudo dmesg -w

Check the connected device:

sudo fdisk -l

Look for a line like:

Disk model: RP2

The device is usually listed as /dev/sda1 (not /dev/sda):

Device     Boot Start    End Sectors  Size Id Type
/dev/sda1           1 262143  262143  128M  e W95 FAT16 (LBA)

Mount the Pico

Create a mount point:

sudo mkdir -p /mnt/pico

Mount the Pico:

sudo mount /dev/sda1 /mnt/pico

Verify:

ls -la /mnt/pico/

You should see files like INDEX.HTM and INFO_UF2.TXT.

Copy the .uf2 File to the Pico

Navigate to your project folder:

cd ~/blink_me

If not built yet:

mkdir -p build
cd build
cmake ..
make
cd ..

Copy the firmware:

sudo cp build/*.uf2 /mnt/pico/

The Pico will automatically reboot and start running your program.