From a34d68c1a5f2d3b18cc7bb483df5b02bc57184a3 Mon Sep 17 00:00:00 2001 From: zrll_ <46812903+zrll12@users.noreply.github.com> Date: Wed, 17 Apr 2024 23:43:22 +0800 Subject: [PATCH 1/2] Fix "I2c(AckCheckFailed)" error --- advanced/i2c-sensor-reading/examples/part_1.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/advanced/i2c-sensor-reading/examples/part_1.rs b/advanced/i2c-sensor-reading/examples/part_1.rs index 4a3f7194..658a5b71 100644 --- a/advanced/i2c-sensor-reading/examples/part_1.rs +++ b/advanced/i2c-sensor-reading/examples/part_1.rs @@ -34,15 +34,15 @@ fn main() -> Result<()> { loop { // 5. This loop initiates measurements, reads values and prints humidity in % and Temperature in °C. - sht.start_measurement(PowerMode::NormalMode).unwrap(); - FreeRtos.delay_ms(100u32); - let measurement = sht.get_measurement_result().unwrap(); - - println!( - "TEMP: {:.2} °C | HUM: {:.2} %", - measurement.temperature.as_degrees_celsius(), - measurement.humidity.as_percent(), - ); + if let Ok(measurement) = sht.get_measurement_result() { + println!( + "TEMP: {:.2} °C | HUM: {:.2} %", + measurement.temperature.as_degrees_celsius(), + measurement.humidity.as_percent(), + ); + + sht.start_measurement(PowerMode::NormalMode).unwrap(); + } FreeRtos.delay_ms(500u32); } From 624aa6be05f45707bd7d8b513ea23cc2b535e22d Mon Sep 17 00:00:00 2001 From: zrll_ <46812903+zrll12@users.noreply.github.com> Date: Thu, 18 Apr 2024 17:44:33 +0800 Subject: [PATCH 2/2] Fix not starting measurements --- advanced/i2c-sensor-reading/examples/part_1.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/advanced/i2c-sensor-reading/examples/part_1.rs b/advanced/i2c-sensor-reading/examples/part_1.rs index 658a5b71..109464aa 100644 --- a/advanced/i2c-sensor-reading/examples/part_1.rs +++ b/advanced/i2c-sensor-reading/examples/part_1.rs @@ -32,8 +32,11 @@ fn main() -> Result<()> { let device_id = sht.device_identifier().unwrap(); println!("Device ID SHTC3: {:#02x}", device_id); + // 5. Start measurements + sht.start_measurement(PowerMode::NormalMode).unwrap(); + loop { - // 5. This loop initiates measurements, reads values and prints humidity in % and Temperature in °C. + // 6. This loop initiates measurements, reads values and prints humidity in % and Temperature in °C. if let Ok(measurement) = sht.get_measurement_result() { println!( "TEMP: {:.2} °C | HUM: {:.2} %",