Skip to content

Commit 48a8d7c

Browse files
Added cmake file to be able to use the component with platformio
1 parent 572cdc3 commit 48a8d7c

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
idf_component_register(
2+
SRCS "dht11.c"
3+
INCLUDE_DIRS "include"
4+
)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Esp-idf driver for DHT11 temperature and humidity sensor
44
## Install
55
Use Platformio to install this [link](https://platformio.org/lib/show/5817/ESP32-DHT11)<br/>
66
or <br/>
7+
Clone this repo inside your-platformio-project/components folder
8+
or <br/>
79
Clone this repo inside [esp]/esp-idf/components folder
810

911
## How to use

examples/simple_read.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,37 @@
66
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
77
CONDITIONS OF ANY KIND, either express or implied.
88
*/
9-
#include "freertos/FreeRTOS.h"
10-
#include "freertos/task.h"
11-
#include "driver/gpio.h"
12-
#include "sdkconfig.h"
13-
14-
#include "waiter.h"
9+
#include <freertos/FreeRTOS.h>
10+
#include <freertos/task.h>
11+
#include "esp_log.h"
1512
#include "dht11.h"
1613

17-
void app_main()
14+
static void _tag_handler(uint8_t *pu08SerialNumber);
15+
16+
#define TAG "APP_MAIN"
17+
18+
void dht11_test(void *pvParameters)
1819
{
19-
DHT11_init(GPIO_NUM_4);
20+
DHT11_init(GPIO_NUM_4);
2021

21-
while(1) {
22-
printf("Temperature is %d \n", DHT11_read().temperature);
23-
printf("Humidity is %d\n", DHT11_read().humidity);
24-
printf("Status code is %d\n", DHT11_read().status);
25-
waitSeconds(1);
22+
while(1)
23+
{
24+
if(0 == DHT11_read().status)
25+
{
26+
ESP_LOGI(TAG,
27+
"Temperature: %d °C\tHumidity: %d %%",
28+
DHT11_read().temperature,
29+
DHT11_read().humidity);
30+
}
31+
else
32+
{
33+
ESP_LOGW(TAG, "Cannot read from sensor");
2634
}
35+
vTaskDelay(3000 / portTICK_PERIOD_MS);
36+
}
37+
}
38+
39+
void app_main(void)
40+
{
41+
xTaskCreate(dht11_test, "dht11_test", configMINIMAL_STACK_SIZE * 3, NULL, 5, NULL);
2742
}

0 commit comments

Comments
 (0)