Skip to content

Commit

Permalink
Restore docs values
Browse files Browse the repository at this point in the history
  • Loading branch information
weiying-chen committed Mar 7, 2024
1 parent ae7fc56 commit 6c369a9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
50 changes: 33 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,59 @@
# Rust ESP32-C3 BME280

Example of reading the BME280 sensor on an ESP32-C3 using Rust
Example of reading the HX711 24-bit analog-to-digital converter and a load cell sensor on an ESP32-C3 using Rust

## Hardware:

- ESP32-C3 microcontroller
- BME280 sensor
- [ESP32-C3](https://mm.digikey.com/Volume0/opasdata/d220001/medias/images/3824/ESP32-DEVKITM-1.jpg)
- [HX711](https://grobotronics.com/images/detailed/117/htb1fepyipxxxxx.xvxxq6xxfxxxe_grobo.jpg)
- [Load cell](https://cdn.sparkfun.com/assets/learn_tutorials/3/8/2/13329-01Crop.jpg)
- Breadboard
- Jump wires
- USB-A to Micro-B cable
- [Weighing acrylic](https://www.elecbee.com/image/catalog/Sensor-and-Detector-Module/ESP32-096-OLED-HX711-Digital-Load-Cell-1KG-Weight-Sensor-Board-Development-Tool-Kit-1410870-descriptionImage11.jpeg)

Step 1: attach the ESP32-C3 to the breadboard (with its headers).
Step 1: solder the load cell wires to the HX711:

Step 2: attach the BME280 to the breadboard (with its headers).
- Red to E+
- Black to E-
- White to A-
- Green to A+

Step 3: using the jump wires, connect the ESP32-C3 to the BME280:
Step 2 (optional): screw the weighing acrylics to the load sensor.

- 3V3 to VIN
Step 3 solder headers to the HX711's GND, DT, SCK, and VCC.

Step 4: attach the HX711 to the breadboard (with its headers).

Step 5: attach the ESP32-C3 to the breadboard (with its headers).

Step 6: using the jump wires, connect the ESP32-C3 to the HX711:

- 3V3 to VCC
- GND to GND
- GPIO 2 to SDA
- GPIO 3 to SCL
- GPIO 2 to DT
- GPIO 3 to SCK

Note: you can use any available GPIO pins for SDL and SCL, but remember to change the code accordingly.
Note: you can use any available GPIO pins for DT and SCK, but remember to change the code accordingly.

Step 4: connect the USB cable to your computer or laptop.
Step 7: using the USB cable, connect the ESP32-C3 to your computer or laptop.

The final setup should look like [this](https://i0.wp.com/randomnerdtutorials.com/wp-content/uploads/2022/03/ESP32-load-cell-diagram_bb.png?resize=828%2C382&quality=100&strip=all&ssl=1).

## Software:

Step 1: follow these [instructions](https://github.com/esp-rs/esp-idf-template?tab=readme-ov-file#prerequisites) to setup the development environment.

Step 2: Execute `cargo run` on the command line (to build, flash, and monitor). Note: on Linux, you may have to fix a permission [issue](https://github.com/esp-rs/espflash/blob/main/espflash/README.md#permissions-on-linux).
Step 2: execute `cargo run` on the command line (to build, flash, and monitor). Note: on Linux, you may have to fix a permission [issue](https://github.com/esp-rs/espflash/blob/main/espflash/README.md#permissions-on-linux).

Step 3: calibrate the load cell following [these](https://github.com/DaneSlattery/hx711?tab=readme-ov-file#calibration) instructions (you can ask ChatGPT to do the math).


If the universe conspires in your favor, you should see an output like this:
If the universe conspires in your favor, you should see an output like this (after applying pressure on the load sensor):

```bash
I (409) rust_esp32_bme280: Successfully initialized BME280 device
I (2529) rust_esp32_bme280: Relative Humidity = 69%
I (2529) rust_esp32_bme280: Temperature = 25°C
I (2529) rust_esp32_bme280: Pressure = 101698 Pa
I (78145) rust_esp32_hx711: Weight: 0 g
I (79145) rust_esp32_hx711: Weight: 45 g
```

Let me know if I skipped any step.
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ fn main() {
let mut load_sensor = HX711::new(sck, dt, delay);

load_sensor.tare(16);
load_sensor.set_scale(0.0028);
load_sensor.set_scale(1.0);

loop {
if load_sensor.is_ready() {
let reading = load_sensor.read_scaled().unwrap();
// let reading = load_sensor.read().unwrap(); // Use this one to calibrate the load cell
log::info!("Weight: {:.0} g", reading);
// log::info!("Weight: {} g", reading); // Use this to get all the decimals
}

FreeRtos::delay_ms(1000u32);
Expand Down

0 comments on commit 6c369a9

Please sign in to comment.