Kaynağa Gözat

implementada librería dht22

dacowars 1 ay önce
ebeveyn
işleme
8202da4cbc
5 değiştirilmiş dosya ile 72 ekleme ve 3 silme
  1. 6 1
      .vscode/settings.json
  2. 19 0
      dependencies.lock
  3. 2 1
      main/CMakeLists.txt
  4. 20 0
      main/idf_component.yml
  5. 25 1
      main/main.c

+ 6 - 1
.vscode/settings.json

@@ -1,4 +1,9 @@
 {
   "C_Cpp.intelliSenseEngine": "default",
-  "idf.currentSetup": "/Users/daniel/.espressif/v5.5.3/esp-idf"
+  "idf.currentSetup": "/Users/daniel/.espressif/v5.5.3/esp-idf",
+  "idf.openOcdConfigs": [
+    "board/esp32-wrover-kit-3.3v.cfg"
+  ],
+  "idf.flashType": "UART",
+  "idf.port": "/dev/tty.usbserial-110"
 }

+ 19 - 0
dependencies.lock

@@ -0,0 +1,19 @@
+dependencies:
+  dht22:
+    component_hash: 4ab7279fd6ef1c60deb1dc2cc9f223c9c76db0be3ef42d117fdfc79afcaff86c
+    dependencies: []
+    source:
+      git: https://dacogogs.duckdns.org/dacowars/libreria_dht22.git
+      path: .
+      type: git
+    version: 662c42ad08d6365ab6978c392dad28eac84f13b0
+  idf:
+    source:
+      type: idf
+    version: 5.5.3
+direct_dependencies:
+- dht22
+- idf
+manifest_hash: 77a7ff9c66a977995d56ae221a7ec236e98e9e62649155598a6b8f6e1d86d2d1
+target: esp32
+version: 2.0.0

+ 2 - 1
main/CMakeLists.txt

@@ -1,2 +1,3 @@
 idf_component_register(SRCS "main.c"
-                    INCLUDE_DIRS ".")
+                    INCLUDE_DIRS "."
+                    REQUIRES driver dht22)

+ 20 - 0
main/idf_component.yml

@@ -0,0 +1,20 @@
+## IDF Component Manager Manifest File
+dependencies:
+  ## Required IDF version
+  idf:
+    version: ">=4.1.0"
+  # # Put list of dependencies here
+  # # For components maintained by Espressif:
+  # component: "~1.0.0"
+  # # For 3rd party components:
+  # username/component: ">=1.0.0,<2.0.0"
+  # username2/component2:
+  #   version: "~1.0.0"
+  #   # For transient dependencies `public` flag can be set.
+  #   # `public` flag doesn't have an effect dependencies of the `main` component.
+  #   # All dependencies of `main` are public by default.
+  #   public: true
+  
+  dht22:
+    git: https://dacogogs.duckdns.org/dacowars/libreria_dht22.git
+    version: "*"

+ 25 - 1
main/main.c

@@ -1,6 +1,30 @@
 #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"
+
+const char *DHT_TAG = "DHT22";
 
 void app_main(void)
 {
-
+    float temperature;
+    float humidity;
+    esp_err_t err = dht_attach_pin();
+    if (err != ESP_OK) {
+        ESP_LOGE(DHT_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) {
+        if (dht_read(&temperature, &humidity) == ESP_OK) {
+            ESP_LOGI(DHT_TAG, "Temperature: %.1f°C, Humidity: %.1f%%", temperature, humidity);
+        } else {
+            ESP_LOGE(DHT_TAG, "Failed to read from DHT22 sensor");
+        }
+        vTaskDelay(pdMS_TO_TICKS(5000)); // Wait for 5 seconds before the next reading
+    }
 }