Skip to content

Latest commit

 

History

History
228 lines (169 loc) · 8.21 KB

README.md

File metadata and controls

228 lines (169 loc) · 8.21 KB

PiPicoClimate-rs

This project uses Raspberry Pi Pico W (rp2040) and a Pimoroni sensor board together with the embassy asynchronous embedded development framework for Rust to measure sensor data and send that data out via MQTT.

DISCLAIMER: Parts of this README.md are copied from here, an excellent repository to get started with Embassy and Rust on the Raspberry Pi Pico.

It includes all of the knurling-rs tooling (defmt, defmt-rtt, panic-probe, flip-link to enhance the embedded development process.

The default cargo runner is configured as probe-rs, so you can build, flash and run your firmware with output from the device via a probe-rs compatible debug probe with the command:

cargo run

If you want to use a different runner with your debugger (e.g., cargo-embed, probe-rs-debugger, etc.) or if you aren't using a debugger and want the runner to flash the firmware via USB (e.g., elf2uf2-rs, picotool, etc.) then see: Alternative Runners

Requirements

  • Ubuntu or Fedora Linux
  • Raspberry Pi Pico
  • Debug Probe (or another Raspberry Pi Pico)
  • Rust Toolchain (cargo, rustup)

Setup

System Setup

  1. Install Rust and cargo using rustup

    # Install `rustup` for Rust Toolchain
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  2. Install Cortex-M Target Toolchain Support for Rust

    # Install `thumbv6m-none-eabi` Target for `rp2040`
    rustup target add thumbv6m-none-eabi
  3. Install probe-rs

    Please see here for the most up-to-date installation instructions.

    # Install Linux Dependencies
    # For Ubuntu
    sudo apt install -y pkg-config libusb-1.0-0-dev libftdi1-dev libudev-dev libssl-dev
    sudo apt purge libusb-dev
    
    # For Fedora
    sudo dnf install libusbx-devel libftdi-devel libudev-devel openssl-devel
    
    
    # Install `probe-rs`
    cargo install probe-rs
    # Note: Try 'cargo install probe-rs --locked --features cli' if you encounter an error with the above command
    
    # Install `udev` Rules and Reload
    sudo curl https://probe.rs/files/69-probe-rs.rules -o /etc/udev/rules.d/69-probe-rs.rules
    sudo udevadm control --reload
    sudo udevadm trigger
    
    # (Optional and Ubuntu ONLY!) Add User to `plugdev` Group
    sudo usermod -aG plugdev $USER
  4. Install flip-link

    # Install `flip-link`
    cargo install flip-link
    ```cargo
    

Picoprobe Setup

You can use a second Raspberry Pi Pico (a Pico W is also fine) as a so called Picoprobe. This way you can flash your firmware without having to set the Pico inti bootloader mode everytime. To set this up, follow these steps:

  1. Download the Picoprobe firmware from here
  2. Boot the Raspberry Pi Pico that you intend to use as a Picoprobe in "Bootloader Mode" by holding the BOOTSEL button while plugging it in via USB
  3. Open the mounted Raspberry Pi Pico storage device in your file explorer
  4. Copy the picoprobe.uf2 onto the Raspberry Pi Pico
  5. Firmware will be flashed to the Raspberry Pi Pico and it will disconnect itself

Whenever you now plug in the Raspberry Pi Pico, it will automatically connect to your computer as a Picoprobe. You can now use it as a debug probe with probe-run. This is the recommended way to flash your firmware and is automatically configured in this project.

Hardware Setup

Connecting the Raspberry Pi Pico Debug Probe

The diagram below shows the wiring between Raspberry Pi Pico A (left) and Raspberry Pi Pico B (right), configuring Raspberry Pi Pico A as a debug probe.

Image description

The connections shown in the diagram above are listed below.

Pico A GND -> Pico B GND
Pico A GP2 -> Pico B SWCLK
Pico A GP3 -> Pico B SWDIO
Pico A GP4/UART1 TX -> Pico B GP1/UART0 RX
Pico A GP5/UART1 RX -> Pico B GP0/UART0 TX
Pico A VSYS -> Pico B VSYS

For more information on connecting the two Raspberry Pi Picos, the wiring between them and its connections, seethe section Appendix A > Wiring Loom in: Getting Started with Raspberry Pi Pico

Raspberry Pi Pico I/O expansion board

We are using this I/O expansion board from AliExpress, which allows us to connect the Pimoroni enviro plus sensor board to the Raspberry Pi Pico while still beeing able to access the Picos pins in order to flash the firmware via the connected Picoprobe.

Further details TBD.

Usage

Running

To run the firmware in debug mode:

cargo run

To run the firmware in release mode:

cargo run --release

NOTE: If you flash the firmware in release mode, the code will run upon boot of your Pico. So if you disconnect and reconnect the Pico, the firmware will run again. If you flash the firmware in debug mode, the code will only run when you start the firmware with cargo run, after disconnecting and reconnecting the Pico, the firmware will not run again.

Logging

To change the default defmt log level, see .cargo/config.toml:

[env]
DEFMT_LOG = "trace"

You can also set the log level inline:

DEFMT_LOG=debug cargo run
DEFMT_LOG=error cargo run --release

Appendix

Documentation

Resources

License

Licensed under MIT license LICENSE