Raspberry Pi Pico W example

This example application runs out of the box on the Raspberry Pi Pico W.

It uses the on board WiFi peripheral to send data to Drogue Cloud. The firmware can be updated remotely using Drogue Ajour.

Prerequisites

Hardware

Software

  • To build the example, you need to have rustup.

  • To flash the example using a debug probe, you need probe-run installed (cargo install probe-run).

  • To flash the example using the UF2 bootloader on the pico, you need the mergehex utility to merge the application and bootloader into a single file. Use the elf2uf2 utility to convert the elf file into a .uf2 file that you can copy to the pico USB drive.

  • A Drogue Cloud instance. See drogue-cloud for how to run that, or use the sandbox (requires TLS).

Configuring

Credentials for your local WiFi network will come from these entries in ~/.drogue/config.toml:

wifi-ssid = "..."
wifi-password = "..."

HTTP authentication will come from these entries in ~/.drogue/config.toml:

username = "..."
password = "..."

For Drogue Cloud, the username/password is stored in this form: device_id@application.

The example config.toml file for connecting to public Drogue cloud sandbox application could look like this:

hostname = "http.sandbox.drogue.cloud" # Replace with your own Drogue Cloud instance if you are not using the sandbox
port = "443"
wifi-ssid = "..."                      # The WiFi network SSID
wifi-password = "..."                  # The WiFi network pre-shared key
username = "device1@wifi-workshop"
password = "mysecretpassword"

Running with debug probe

Procedure
  1. Download the WiFi firmware from https://github.com/embassy-rs/cyw43/tree/master/firmware, and flash them with probe-rs-cli:

    probe-rs-cli download 43439A0.bin --format bin --chip RP2040 --base-address 0x10100000
    probe-rs-cli download 43439A0.clm_blob --format bin --chip RP2040 --base-address 0x10140000
  2. Flash the bootloader:

    cargo flash --manifest-path ../boot/Cargo.toml --release --chip RP2040
  3. Run the application:

    cargo run --release

    Once flashed, the device will attempt to join the WiFi network and send telemetry data to Drogue Cloud every 30 seconds.

Running with UF2 image

Procedure
  1. Download the WiFi firmware from https://github.com/embassy-rs/cyw43/tree/master/firmware, and modify main.rs to include it:

    // let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 224190) };
    // let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) };
    let fw = include_bytes!("../firmware/43439A0.bin");
    let clm = include_bytes!("../firmware/43439A0_clm.bin");
  2. Build the bootloader:

    cargo build --manifest-path ../boot/Cargo.toml --release
  3. Build the firmware:

    cargo build --release
  4. Merge the files:

    cp ../boot/target/thumbv6m-none-eabi/release/rp-bootloader boot.elf
    cp target/thumbv6m-none-eabi/release/rp2040-pico-w app.elf
    mergehex -m boot.elf app.elf -o firmware.hex
  5. Clone the uf2conv repo and run the conversion tool:

    /path/to/uf2conv.py -f 0xe48bff56 -c firmware.hex -o firmware.uf2
  6. Hold the Pico W button while powering up the board, and copy the uf2 file to the USB partition

    cp firmware.uf2 /mount/point/of/usb/drive

    Once flashed, the device will attempt to join the WiFi network and send telemetry data to Drogue Cloud every 30 seconds.

  7. You can monitor the logs using a terminal emulator on the Pico W TTY

    minicom -D /dev/ttyACM0

Troubleshooting

If you’re experiencing problems, try setting the VID:PID values to that of your probe (you can find that from lsusb once your board is powered).

<ENV> cargo run <ARGS> -- --probe <VID>:<PID>