mirror of
https://github.com/rzajac/esp-drv.git
synced 2025-07-25 05:31:05 +03:00
Update documentation and fix small issues.
This commit is contained in:
31
examples/dht22/CMakeLists.txt
Normal file
31
examples/dht22/CMakeLists.txt
Normal file
@ -0,0 +1,31 @@
|
||||
# Copyright 2017 Rafal Zajac <rzajac@gmail.com>.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
find_package(esp_sdo REQUIRED)
|
||||
find_package(esp_util REQUIRED)
|
||||
|
||||
add_executable(dht22_ex main.c ${ESP_USER_CONFIG})
|
||||
|
||||
target_include_directories(dht22_ex PUBLIC
|
||||
${ESP_USER_CONFIG_DIR}
|
||||
${esp_sdo_INCLUDE_DIRS}
|
||||
${esp_util_INCLUDE_DIRS})
|
||||
|
||||
target_link_libraries(dht22_ex
|
||||
${esp_sdo_LIBRARIES}
|
||||
${esp_util_LIBRARIES}
|
||||
esp_dht22)
|
||||
|
||||
esp_gen_exec_targets(dht22_ex)
|
12
examples/dht22/README.md
Normal file
12
examples/dht22/README.md
Normal file
@ -0,0 +1,12 @@
|
||||
## DHT22 example.
|
||||
|
||||
Demonstrates how to get temperature and humidity from DHT22 sensor.
|
||||
|
||||
## Flashing
|
||||
|
||||
```
|
||||
$ cd build
|
||||
$ cmake ..
|
||||
$ make dht22_ex_flash
|
||||
$ miniterm.py /dev/ttyUSB0 74880
|
||||
```
|
66
examples/dht22/main.c
Normal file
66
examples/dht22/main.c
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2017 Rafal Zajac <rzajac@gmail.com>.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License. You may obtain
|
||||
* a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
#include <esp_gpio.h>
|
||||
#include <esp_dht22.h>
|
||||
#include <esp_sdo.h>
|
||||
#include <esp_util.h>
|
||||
#include <user_interface.h>
|
||||
#include <mem.h>
|
||||
|
||||
os_timer_t timer;
|
||||
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
sys_init_done(void* arg)
|
||||
{
|
||||
esp_dht22_err err;
|
||||
esp_dht22_dev *dev = esp_dht22_new_dev(GPIO2);
|
||||
|
||||
// Get temperature.
|
||||
err = esp_dht22_get(dev);
|
||||
if (err != ESP_DHT22_OK) {
|
||||
os_free(dev);
|
||||
os_printf("DHT22 error code: %d\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
os_printf("Temp: %s\n", esp_util_ftoa(dev->temp, 3));
|
||||
os_printf("Hum: %s\n", esp_util_ftoa(dev->hum, 3));
|
||||
os_printf("--------------------\n");
|
||||
os_free(dev);
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
user_init()
|
||||
{
|
||||
// No need for wifi for this example.
|
||||
wifi_station_disconnect();
|
||||
wifi_set_opmode_current(NULL_MODE);
|
||||
|
||||
//system_init_done_cb(sys_init_done);
|
||||
stdout_init(BIT_RATE_74880);
|
||||
|
||||
// Initialize DHT22 on GPIO 2.
|
||||
esp_dht22_init(GPIO2);
|
||||
|
||||
// Wait before running main code.
|
||||
os_printf("Initialized.\n");
|
||||
os_timer_disarm(&timer);
|
||||
os_timer_setfn(&timer, sys_init_done, NULL);
|
||||
os_timer_arm(&timer, 1500, true);
|
||||
}
|
Reference in New Issue
Block a user