https://github.com/maspetsberger/rust-esp32-bme280
Measuring temperature, humidity, and pressure with an BME280 on an ESP32 in Rust.
https://github.com/maspetsberger/rust-esp32-bme280
bme280 embedded esp32 esp32c3 humidity-sensor i2c i2c-sensors pressure-sensor rust-lang temperature-sensor
Last synced: 3 months ago
JSON representation
Measuring temperature, humidity, and pressure with an BME280 on an ESP32 in Rust.
- Host: GitHub
- URL: https://github.com/maspetsberger/rust-esp32-bme280
- Owner: maspetsberger
- Created: 2022-04-04T20:23:37.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-04-04T22:15:44.000Z (about 3 years ago)
- Last Synced: 2025-02-12T23:38:23.639Z (4 months ago)
- Topics: bme280, embedded, esp32, esp32c3, humidity-sensor, i2c, i2c-sensors, pressure-sensor, rust-lang, temperature-sensor
- Language: Rust
- Homepage:
- Size: 4.88 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Rust on ESP32 with BME280 sensor
This repository holds a minimal example for reading the BME280 sensor on an ESP32 using Rust instead of the C++/Arduino.
## Components used in this example
* [Waveshare ESP32-C3](https://www.waveshare.com/wiki/ESP-C3-32S-Kit)
* Bosch BME280 sensor on a breakout-board (can't remember which one exactly)Unlike the other ESP32 chips, which are built on the Xtensa architecture, the ESP32-C3 is using a RISC-V instruction set. Therefore, the latest Rust nightly chain on llvm can build binaries directly for the ESP32-C3. The specific Waveshare chip listed above does have only 2MB flash, so it does need some customization here and there.
I am not sure what the default I2C pins are on the board I used, so I ended up to manually configure GPIO 8 and 9 for SDA and SCL respectively. According to the docu you could use any GPIO for this. The BME's VIN and GND is connected to the board's `3V3` and `GND` respectively.
## How to build
The example was derived from the [esp-idf-template](https://github.com/esp-rs/esp-idf-template), it holds general build instructions for the various ESP32 chips and how to get the rust nightly chain for RISC-V, or the Xtensa llvm fork for all others.
Specifically for ESP32-C3:
1. `cargo build` (or `cargo build --release`...)
1. `espflash ./target/risv32imc-esp-espidf/debug/rust-esp32-bme280` (or `.../release/...` or `cargo flash`)
1. `espmonitor /dev/ttyUSB0` (or whatever usb port the board is connected to)Note, the Waveshare ESP32-C3 board only has 2MB flash on board. The 1.3.0 release of [espflash](https://github.com/esp-rs/espflash) is not yet compatible with this, but the latest master is.
## Output
```
> espmonitor /dev/ttyUSB0
...
I (290) cpu_start: Starting scheduler.
starting...
creating I2C bus...
I (298) gpio: GPIO[8]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (308) gpio: GPIO[9]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
creating BME280...
initializing BME280...
starting measurements...
Relative Humidity = 52.61 %, Temperature = 23.30 °C, Pressure = 974.11 hPa
Relative Humidity = 52.59 %, Temperature = 23.30 °C, Pressure = 974.11 hPa
Relative Humidity = 52.60 %, Temperature = 23.30 °C, Pressure = 974.10 hPa
Relative Humidity = 52.60 %, Temperature = 23.30 °C, Pressure = 974.10 hPa
...
```## Noteworthy
I stumbled over the following issues throughout development:
* `E (259) spi_flash: Detected size(2048k) smaller than the size in the binary image header(4096k). Probe failed.`
* Outdated version of `espflash` is used. Either use a more recent version (or master), or switch to `esptool.py`
* `initializing BME280... Guru Meditation Error: Core 0 panic'ed (Illegal instruction). Exception was unhandled.`
* Double check the SDA and SCL pins, they might need to be swapped in the code.
* `esp-idf-hal` provides several `Delay` providers, they all seem to work.