瀏覽代碼

correccion de errores README

dacowars 1 月之前
父節點
當前提交
b5843cf355
共有 1 個文件被更改,包括 20 次插入21 次删除
  1. 20 21
      components/dht22/README.md

+ 20 - 21
components/dht22/README.md

@@ -21,7 +21,7 @@ Agrega la siguiente dependencia en tu archivo `idf_component.yml`:
 ```yaml
 dependencies:
   dht22:
-    git: https://github.com/TU_USUARIO/TU_REPOSITORIO.git
+    git: https://dacogogs.duckdns.org/dacowars/libreria_dht22.git
     version: "*"
 ```
 
@@ -45,30 +45,33 @@ idf.py menuconfig
 #include <stdio.h>
 #include "freertos/FreeRTOS.h"
 #include "freertos/task.h"
+#include "driver/gpio.h"
+#include "esp_rom_sys.h"
 #include "esp_log.h"
 #include "dht22.h"
 
+
 static const char *TAG = "DHT22";
 
+
 void app_main(void)
 {
-    float temperature = 0.0;
-    float humidity = 0.0;
-    esp_err_t ret;
-
-    ESP_LOGI(TAG, "Iniciando sensor DHT22...");
-
+    float temperature;
+    float humidity;
+    esp_err_t err = dht_attach_pin();
+    if (err != ESP_OK) {
+        ESP_LOGE(TAG, "Failed to attach DHT pin: %s", esp_err_to_name(err));
+        vTaskDelay(pdMS_TO_TICKS(5000)); // Wait for 5 seconds before retrying
+        return;
+    }
+    vTaskDelay(pdMS_TO_TICKS(2000)); // Wait for 2 seconds before starting the main loop
     while (1) {
-        ret = dht_read(&temperature, &humidity);
-
-        if (ret == ESP_OK) {
-            ESP_LOGI(TAG, "Temperatura: %.1f °C | Humedad: %.1f %%", temperature, humidity);
+        if (dht_read(&temperature, &humidity) == ESP_OK) {
+            ESP_LOGI(TAG, "Temperature: %.1f°C, Humidity: %.1f%%", temperature, humidity);
         } else {
-            ESP_LOGE(TAG, "Error al leer el sensor: %s", esp_err_to_name(ret));
+            ESP_LOGE(TAG, "Failed to read from DHT22 sensor");
         }
-
-        // El DHT22 requiere al menos 2 segundos entre lecturas
-        vTaskDelay(pdMS_TO_TICKS(2500));
+        vTaskDelay(pdMS_TO_TICKS(5000)); // Wait for 5 seconds before the next reading
     }
 }
 ```
@@ -78,14 +81,10 @@ void app_main(void)
 | DHT22 Pin | ESP32 Pin | Descripción |
 |-----------|-----------|-------------|
 | VCC       | 3.3V      | Alimentación |
-| GND       | GND       | Tierra |
+| GND       | GND       | Masa |
 | DATA      | GPIO4 (o el GPIO configurado) | Datos |
 
-- Recomendado: añadir una resistencia pull-up de 4.7kΩ a 10kΩ entre VCC y DATA.
-
-## Ejemplo completo
-
-Se incluye un ejemplo funcional en la carpeta `examples/dht22_example`.
+- Comprobar: resistencia pull-up entre VCC y DATA, recomendado de 4.7kΩ a 10kΩ.
 
 ## Licencia