From 55df258e965d10dc5af118ab8d7eee2a9e8a1e7c Mon Sep 17 00:00:00 2001 From: ZhongUncle <2020738339@qq.com> Date: Thu, 28 Mar 2024 23:39:12 +0800 Subject: [PATCH] fix dht.c error --- gpio/dht_sensor/dht.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gpio/dht_sensor/dht.c b/gpio/dht_sensor/dht.c index c9ce8748c..9163ea02b 100644 --- a/gpio/dht_sensor/dht.c +++ b/gpio/dht_sensor/dht.c @@ -48,8 +48,12 @@ void read_from_dht(dht_reading *result) { gpio_set_dir(DHT_PIN, GPIO_OUT); gpio_put(DHT_PIN, 0); - sleep_ms(20); + sleep_ms(18); + gpio_put(DHT_PIN,1); + sleep_us(40); + gpio_set_dir(DHT_PIN, GPIO_IN); + #ifdef LED_PIN gpio_put(LED_PIN, 1); @@ -66,7 +70,7 @@ void read_from_dht(dht_reading *result) { if ((i >= 4) && (i % 2 == 0)) { data[j / 8] <<= 1; - if (count > 16) data[j / 8] |= 1; + if (count > 35) data[j / 8] |= 1; j++; } }