master
commit
f48be4ee03
@ -0,0 +1,4 @@
|
||||
{
|
||||
"idf.flashType": "UART",
|
||||
"idf.portWin": "COM4"
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
# For more information about build system see
|
||||
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
|
||||
# The following five lines of boilerplate have to be in your project's
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(dht11)
|
||||
@ -0,0 +1,35 @@
|
||||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- |
|
||||
|
||||
# _Sample project_
|
||||
|
||||
(See the README.md file in the upper level 'examples' directory for more information about examples.)
|
||||
|
||||
This is the simplest buildable example. The example is used by command `idf.py create-project`
|
||||
that copies the project to user specified path and set it's name. For more information follow the [docs page](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html#start-a-new-project)
|
||||
|
||||
|
||||
|
||||
## How to use example
|
||||
We encourage the users to use the example as a template for the new projects.
|
||||
A recommended way is to follow the instructions on a [docs page](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html#start-a-new-project).
|
||||
|
||||
## Example folder contents
|
||||
|
||||
The project **sample_project** contains one source file in C language [main.c](main/main.c). The file is located in folder [main](main).
|
||||
|
||||
ESP-IDF projects are built using CMake. The project build configuration is contained in `CMakeLists.txt`
|
||||
files that provide set of directives and instructions describing the project's source files and targets
|
||||
(executable, library, or both).
|
||||
|
||||
Below is short explanation of remaining files in the project folder.
|
||||
|
||||
```
|
||||
├── CMakeLists.txt
|
||||
├── main
|
||||
│ ├── CMakeLists.txt
|
||||
│ └── main.c
|
||||
└── README.md This is the file you are currently reading
|
||||
```
|
||||
Additionally, the sample project contains Makefile and component.mk files, used for the legacy Make based build system.
|
||||
They are not used or needed when building with CMake and idf.py.
|
||||
@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "main.c" "dht11.c"
|
||||
INCLUDE_DIRS ".")
|
||||
@ -0,0 +1,165 @@
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <nvs_flash.h>
|
||||
#include <driver/rmt_rx.h>
|
||||
#include <driver/rmt_tx.h>
|
||||
#include <soc/rmt_reg.h>
|
||||
#include "esp_log.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp32/rom/ets_sys.h"
|
||||
|
||||
#define TAG "DHT11"
|
||||
|
||||
uint8_t DHT11_PIN = -1;
|
||||
|
||||
//rmt接收通道句柄
|
||||
static rmt_channel_handle_t rx_chan_handle = NULL;
|
||||
|
||||
//数据接收队列
|
||||
static QueueHandle_t rx_receive_queue = NULL;
|
||||
|
||||
// 将RMT读取到的脉冲数据处理为温度和湿度
|
||||
static int parse_items(rmt_symbol_word_t *item, int item_num, int *humidity, int *temp_x10);
|
||||
|
||||
//接收完成回调函数
|
||||
static bool IRAM_ATTR example_rmt_rx_done_callback(rmt_channel_handle_t channel, const rmt_rx_done_event_data_t *edata, void *user_data)
|
||||
{
|
||||
BaseType_t high_task_wakeup = pdFALSE;
|
||||
QueueHandle_t rx_receive_queue = (QueueHandle_t)user_data;
|
||||
// send the received RMT symbols to the parser task
|
||||
xQueueSendFromISR(rx_receive_queue, edata, &high_task_wakeup);
|
||||
return high_task_wakeup == pdTRUE;
|
||||
}
|
||||
|
||||
/** DHT11初始化
|
||||
* @param dht11_pin GPIO引脚
|
||||
* @return 无
|
||||
*/
|
||||
void DHT11_Init(uint8_t dht11_pin)
|
||||
{
|
||||
DHT11_PIN = dht11_pin;
|
||||
|
||||
rmt_rx_channel_config_t rx_chan_config = {
|
||||
.clk_src = RMT_CLK_SRC_APB, // 选择时钟源
|
||||
.resolution_hz = 1000 * 1000, // 1 MHz 滴答分辨率,即 1 滴答 = 1 µs
|
||||
.mem_block_symbols = 64, // 内存块大小,即 64 * 4 = 256 字节
|
||||
.gpio_num = dht11_pin, // GPIO 编号
|
||||
.flags.invert_in = false, // 不反转输入信号
|
||||
.flags.with_dma = false, // 不需要 DMA 后端(ESP32S3才有)
|
||||
};
|
||||
//创建rmt接收通道
|
||||
ESP_ERROR_CHECK(rmt_new_rx_channel(&rx_chan_config, &rx_chan_handle));
|
||||
|
||||
//新建接收数据队列
|
||||
rx_receive_queue = xQueueCreate(20, sizeof(rmt_rx_done_event_data_t));
|
||||
assert(rx_receive_queue);
|
||||
|
||||
//注册接收完成回调函数
|
||||
ESP_LOGI(TAG, "register RX done callback");
|
||||
rmt_rx_event_callbacks_t cbs = {
|
||||
.on_recv_done = example_rmt_rx_done_callback,
|
||||
};
|
||||
ESP_ERROR_CHECK(rmt_rx_register_event_callbacks(rx_chan_handle, &cbs, rx_receive_queue));
|
||||
|
||||
//使能RMT接收通道
|
||||
ESP_ERROR_CHECK(rmt_enable(rx_chan_handle));
|
||||
}
|
||||
|
||||
// 将RMT读取到的脉冲数据处理为温度和湿度(rmt_symbol_word_t称为RMT符号)
|
||||
static int parse_items(rmt_symbol_word_t *item, int item_num, int *humidity, int *temp_x10)
|
||||
{
|
||||
int i = 0;
|
||||
unsigned int rh = 0, temp = 0, checksum = 0;
|
||||
if (item_num < 41){ // 检查是否有足够的脉冲数
|
||||
//ESP_LOGI(TAG, "item_num < 41 %d",item_num);
|
||||
return 0;
|
||||
}
|
||||
if(item_num > 41)
|
||||
item++; // 跳过开始信号脉冲
|
||||
|
||||
for (i = 0; i < 16; i++, item++) // 提取湿度数据
|
||||
{
|
||||
uint16_t duration = 0;
|
||||
if(item->level0)
|
||||
duration = item->duration0;
|
||||
else
|
||||
duration = item->duration1;
|
||||
rh = (rh << 1) + (duration < 35 ? 0 : 1);
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < 16; i++, item++) // 提取温度数据
|
||||
{
|
||||
uint16_t duration = 0;
|
||||
if(item->level0)
|
||||
duration = item->duration0;
|
||||
else
|
||||
duration = item->duration1;
|
||||
temp = (temp << 1) + (duration < 35 ? 0 : 1);
|
||||
}
|
||||
|
||||
for (i = 0; i < 8; i++, item++){ // 提取校验数据
|
||||
|
||||
uint16_t duration = 0;
|
||||
if(item->level0)
|
||||
duration = item->duration0;
|
||||
else
|
||||
duration = item->duration1;
|
||||
checksum = (checksum << 1) + (duration < 35 ? 0 : 1);
|
||||
}
|
||||
// 检查校验
|
||||
if ((((temp >> 8) + temp + (rh >> 8) + rh) & 0xFF) != checksum){
|
||||
ESP_LOGI(TAG, "Checksum failure %4X %4X %2X\n", temp, rh, checksum);
|
||||
return 0;
|
||||
}
|
||||
// 返回数据
|
||||
|
||||
rh = rh >> 8;
|
||||
temp = (temp >> 8) * 10 + (temp & 0xFF);
|
||||
|
||||
//判断数据合法性
|
||||
if(rh <= 100)
|
||||
*humidity = rh;
|
||||
if(temp <= 600)
|
||||
*temp_x10 = temp;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/** 获取DHT11数据
|
||||
* @param temp_x10 温度值
|
||||
* @return 无
|
||||
*/
|
||||
int DHT11_StartGet(int *temp_x10, int *humidity)
|
||||
{
|
||||
//发送20ms开始信号脉冲启动DHT11单总线
|
||||
gpio_set_direction(DHT11_PIN, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level(DHT11_PIN, 1);
|
||||
ets_delay_us(1000);
|
||||
gpio_set_level(DHT11_PIN, 0);
|
||||
ets_delay_us(20000);
|
||||
//拉高20us
|
||||
gpio_set_level(DHT11_PIN, 1);
|
||||
ets_delay_us(20);
|
||||
//信号线设置为输入准备接收数据
|
||||
gpio_set_direction(DHT11_PIN, GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(DHT11_PIN,GPIO_PULLUP_ONLY);
|
||||
|
||||
//启动RMT接收器以获取数据
|
||||
rmt_receive_config_t receive_config = {
|
||||
.signal_range_min_ns = 100, //最小脉冲宽度(0.1us),信号长度小于这个值,视为干扰
|
||||
.signal_range_max_ns = 1000*1000, //最大脉冲宽度(1000us),信号长度大于这个值,视为结束信号
|
||||
};
|
||||
|
||||
static rmt_symbol_word_t raw_symbols[128]; //接收缓存
|
||||
static rmt_rx_done_event_data_t rx_data; //实际接收到的数据
|
||||
ESP_ERROR_CHECK(rmt_receive(rx_chan_handle, raw_symbols, sizeof(raw_symbols), &receive_config));
|
||||
|
||||
// wait for RX done signal
|
||||
if (xQueueReceive(rx_receive_queue, &rx_data, pdMS_TO_TICKS(1000)) == pdTRUE) {
|
||||
// parse the receive symbols and print the result
|
||||
return parse_items(rx_data.received_symbols, rx_data.num_symbols,humidity, temp_x10);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
#ifndef _DHT11_H_
|
||||
#define _DHT11_H_
|
||||
#include <stdint.h>
|
||||
|
||||
/** DHT11初始化
|
||||
* @param dht11_pin GPIO引脚
|
||||
* @return 无
|
||||
*/
|
||||
void DHT11_Init(uint8_t dht11_pin);
|
||||
|
||||
/** 获取DHT11数据
|
||||
* @param temp_x10 温度值X10
|
||||
* @param humidity 湿度值
|
||||
* @return 无
|
||||
*/
|
||||
int DHT11_StartGet(int *temp_x10, int *humidity);
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,38 @@
|
||||
#include <string.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <nvs_flash.h>
|
||||
#include <driver/rmt_rx.h>
|
||||
#include <driver/rmt_tx.h>
|
||||
#include <soc/rmt_reg.h>
|
||||
#include "driver/gpio.h"
|
||||
#include <esp_log.h>
|
||||
#include <freertos/queue.h>
|
||||
#include "esp32/rom/ets_sys.h"
|
||||
#include "dht11.h"
|
||||
|
||||
#define DHT11_GPIO 15 // DHT11引脚定义
|
||||
const static char *TAG = "DHT11_Demo";
|
||||
|
||||
// 温度 湿度变量
|
||||
int temp = 0,hum = 0;
|
||||
|
||||
// 主函数
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
|
||||
ESP_LOGI(TAG, "[APP] APP Is Start!~\r\n");
|
||||
ESP_LOGI(TAG, "[APP] IDF Version is %d.%d.%d",ESP_IDF_VERSION_MAJOR,ESP_IDF_VERSION_MINOR,ESP_IDF_VERSION_PATCH);
|
||||
ESP_LOGI(TAG, "[APP] Free memory: %lu bytes", esp_get_free_heap_size());
|
||||
ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version());
|
||||
|
||||
DHT11_Init(DHT11_GPIO);
|
||||
while (1){
|
||||
if (DHT11_StartGet(&temp, &hum)){
|
||||
ESP_LOGI(TAG, "temp->%i.%i C hum->%i%%", temp / 10, temp % 10, hum);
|
||||
}
|
||||
vTaskDelay(10000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,23 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "ESP-IDF",
|
||||
"compilerPath": "${config:idf.toolsPathWin}\\tools\\xtensa-esp-elf\\esp-13.2.0_20230928\\xtensa-esp-elf\\bin\\xtensa-esp32-elf-gcc.exe",
|
||||
"compileCommands": "${config:idf.buildPath}/compile_commands.json",
|
||||
"includePath": [
|
||||
"${config:idf.espIdfPath}/components/**",
|
||||
"${config:idf.espIdfPathWin}/components/**",
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"browse": {
|
||||
"path": [
|
||||
"${config:idf.espIdfPath}/components",
|
||||
"${config:idf.espIdfPathWin}/components",
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
"limitSymbolsToIncludedHeaders": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "gdbtarget",
|
||||
"request": "attach",
|
||||
"name": "Eclipse CDT GDB Adapter"
|
||||
},
|
||||
{
|
||||
"type": "espidf",
|
||||
"name": "Launch",
|
||||
"request": "launch"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
{
|
||||
"C_Cpp.intelliSenseEngine": "default",
|
||||
"idf.portWin": "COM4",
|
||||
"idf.flashType": "UART",
|
||||
"files.associations": {
|
||||
"nvs_flash.h": "c",
|
||||
"esp_log.h": "c",
|
||||
"string.h": "c"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
# For more information about build system see
|
||||
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
|
||||
# The following five lines of boilerplate have to be in your project's
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(mqtt)
|
||||
@ -0,0 +1,35 @@
|
||||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- |
|
||||
|
||||
# _Sample project_
|
||||
|
||||
(See the README.md file in the upper level 'examples' directory for more information about examples.)
|
||||
|
||||
This is the simplest buildable example. The example is used by command `idf.py create-project`
|
||||
that copies the project to user specified path and set it's name. For more information follow the [docs page](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html#start-a-new-project)
|
||||
|
||||
|
||||
|
||||
## How to use example
|
||||
We encourage the users to use the example as a template for the new projects.
|
||||
A recommended way is to follow the instructions on a [docs page](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html#start-a-new-project).
|
||||
|
||||
## Example folder contents
|
||||
|
||||
The project **sample_project** contains one source file in C language [main.c](main/main.c). The file is located in folder [main](main).
|
||||
|
||||
ESP-IDF projects are built using CMake. The project build configuration is contained in `CMakeLists.txt`
|
||||
files that provide set of directives and instructions describing the project's source files and targets
|
||||
(executable, library, or both).
|
||||
|
||||
Below is short explanation of remaining files in the project folder.
|
||||
|
||||
```
|
||||
├── CMakeLists.txt
|
||||
├── main
|
||||
│ ├── CMakeLists.txt
|
||||
│ └── main.c
|
||||
└── README.md This is the file you are currently reading
|
||||
```
|
||||
Additionally, the sample project contains Makefile and component.mk files, used for the legacy Make based build system.
|
||||
They are not used or needed when building with CMake and idf.py.
|
||||
@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "dht11.c" "main.c" "simple_wifi_sta.c"
|
||||
INCLUDE_DIRS ".")
|
||||
@ -0,0 +1,165 @@
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <nvs_flash.h>
|
||||
#include <driver/rmt_rx.h>
|
||||
#include <driver/rmt_tx.h>
|
||||
#include <soc/rmt_reg.h>
|
||||
#include "esp_log.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp32/rom/ets_sys.h"
|
||||
|
||||
#define TAG "DHT11"
|
||||
|
||||
uint8_t DHT11_PIN = -1;
|
||||
|
||||
//rmt接收通道句柄
|
||||
static rmt_channel_handle_t rx_chan_handle = NULL;
|
||||
|
||||
//数据接收队列
|
||||
static QueueHandle_t rx_receive_queue = NULL;
|
||||
|
||||
// 将RMT读取到的脉冲数据处理为温度和湿度
|
||||
static int parse_items(rmt_symbol_word_t *item, int item_num, int *humidity, int *temp_x10);
|
||||
|
||||
//接收完成回调函数
|
||||
static bool IRAM_ATTR example_rmt_rx_done_callback(rmt_channel_handle_t channel, const rmt_rx_done_event_data_t *edata, void *user_data)
|
||||
{
|
||||
BaseType_t high_task_wakeup = pdFALSE;
|
||||
QueueHandle_t rx_receive_queue = (QueueHandle_t)user_data;
|
||||
// send the received RMT symbols to the parser task
|
||||
xQueueSendFromISR(rx_receive_queue, edata, &high_task_wakeup);
|
||||
return high_task_wakeup == pdTRUE;
|
||||
}
|
||||
|
||||
/** DHT11初始化
|
||||
* @param dht11_pin GPIO引脚
|
||||
* @return 无
|
||||
*/
|
||||
void DHT11_Init(uint8_t dht11_pin)
|
||||
{
|
||||
DHT11_PIN = dht11_pin;
|
||||
|
||||
rmt_rx_channel_config_t rx_chan_config = {
|
||||
.clk_src = RMT_CLK_SRC_APB, // 选择时钟源
|
||||
.resolution_hz = 1000 * 1000, // 1 MHz 滴答分辨率,即 1 滴答 = 1 µs
|
||||
.mem_block_symbols = 64, // 内存块大小,即 64 * 4 = 256 字节
|
||||
.gpio_num = dht11_pin, // GPIO 编号
|
||||
.flags.invert_in = false, // 不反转输入信号
|
||||
.flags.with_dma = false, // 不需要 DMA 后端(ESP32S3才有)
|
||||
};
|
||||
//创建rmt接收通道
|
||||
ESP_ERROR_CHECK(rmt_new_rx_channel(&rx_chan_config, &rx_chan_handle));
|
||||
|
||||
//新建接收数据队列
|
||||
rx_receive_queue = xQueueCreate(20, sizeof(rmt_rx_done_event_data_t));
|
||||
assert(rx_receive_queue);
|
||||
|
||||
//注册接收完成回调函数
|
||||
ESP_LOGI(TAG, "register RX done callback");
|
||||
rmt_rx_event_callbacks_t cbs = {
|
||||
.on_recv_done = example_rmt_rx_done_callback,
|
||||
};
|
||||
ESP_ERROR_CHECK(rmt_rx_register_event_callbacks(rx_chan_handle, &cbs, rx_receive_queue));
|
||||
|
||||
//使能RMT接收通道
|
||||
ESP_ERROR_CHECK(rmt_enable(rx_chan_handle));
|
||||
}
|
||||
|
||||
// 将RMT读取到的脉冲数据处理为温度和湿度(rmt_symbol_word_t称为RMT符号)
|
||||
static int parse_items(rmt_symbol_word_t *item, int item_num, int *humidity, int *temp_x10)
|
||||
{
|
||||
int i = 0;
|
||||
unsigned int rh = 0, temp = 0, checksum = 0;
|
||||
if (item_num < 41){ // 检查是否有足够的脉冲数
|
||||
//ESP_LOGI(TAG, "item_num < 41 %d",item_num);
|
||||
return 0;
|
||||
}
|
||||
if(item_num > 41)
|
||||
item++; // 跳过开始信号脉冲
|
||||
|
||||
for (i = 0; i < 16; i++, item++) // 提取湿度数据
|
||||
{
|
||||
uint16_t duration = 0;
|
||||
if(item->level0)
|
||||
duration = item->duration0;
|
||||
else
|
||||
duration = item->duration1;
|
||||
rh = (rh << 1) + (duration < 35 ? 0 : 1);
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < 16; i++, item++) // 提取温度数据
|
||||
{
|
||||
uint16_t duration = 0;
|
||||
if(item->level0)
|
||||
duration = item->duration0;
|
||||
else
|
||||
duration = item->duration1;
|
||||
temp = (temp << 1) + (duration < 35 ? 0 : 1);
|
||||
}
|
||||
|
||||
for (i = 0; i < 8; i++, item++){ // 提取校验数据
|
||||
|
||||
uint16_t duration = 0;
|
||||
if(item->level0)
|
||||
duration = item->duration0;
|
||||
else
|
||||
duration = item->duration1;
|
||||
checksum = (checksum << 1) + (duration < 35 ? 0 : 1);
|
||||
}
|
||||
// 检查校验
|
||||
if ((((temp >> 8) + temp + (rh >> 8) + rh) & 0xFF) != checksum){
|
||||
ESP_LOGI(TAG, "Checksum failure %4X %4X %2X\n", temp, rh, checksum);
|
||||
return 0;
|
||||
}
|
||||
// 返回数据
|
||||
|
||||
rh = rh >> 8;
|
||||
temp = (temp >> 8) * 10 + (temp & 0xFF);
|
||||
|
||||
//判断数据合法性
|
||||
if(rh <= 100)
|
||||
*humidity = rh;
|
||||
if(temp <= 600)
|
||||
*temp_x10 = temp;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/** 获取DHT11数据
|
||||
* @param temp_x10 温度值
|
||||
* @return 无
|
||||
*/
|
||||
int DHT11_StartGet(int *temp_x10, int *humidity)
|
||||
{
|
||||
//发送20ms开始信号脉冲启动DHT11单总线
|
||||
gpio_set_direction(DHT11_PIN, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level(DHT11_PIN, 1);
|
||||
ets_delay_us(1000);
|
||||
gpio_set_level(DHT11_PIN, 0);
|
||||
ets_delay_us(20000);
|
||||
//拉高20us
|
||||
gpio_set_level(DHT11_PIN, 1);
|
||||
ets_delay_us(20);
|
||||
//信号线设置为输入准备接收数据
|
||||
gpio_set_direction(DHT11_PIN, GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(DHT11_PIN,GPIO_PULLUP_ONLY);
|
||||
|
||||
//启动RMT接收器以获取数据
|
||||
rmt_receive_config_t receive_config = {
|
||||
.signal_range_min_ns = 100, //最小脉冲宽度(0.1us),信号长度小于这个值,视为干扰
|
||||
.signal_range_max_ns = 1000*1000, //最大脉冲宽度(1000us),信号长度大于这个值,视为结束信号
|
||||
};
|
||||
|
||||
static rmt_symbol_word_t raw_symbols[128]; //接收缓存
|
||||
static rmt_rx_done_event_data_t rx_data; //实际接收到的数据
|
||||
ESP_ERROR_CHECK(rmt_receive(rx_chan_handle, raw_symbols, sizeof(raw_symbols), &receive_config));
|
||||
|
||||
// wait for RX done signal
|
||||
if (xQueueReceive(rx_receive_queue, &rx_data, pdMS_TO_TICKS(1000)) == pdTRUE) {
|
||||
// parse the receive symbols and print the result
|
||||
return parse_items(rx_data.received_symbols, rx_data.num_symbols,humidity, temp_x10);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
#ifndef _DHT11_H_
|
||||
#define _DHT11_H_
|
||||
#include <stdint.h>
|
||||
|
||||
/** DHT11初始化
|
||||
* @param dht11_pin GPIO引脚
|
||||
* @return 无
|
||||
*/
|
||||
void DHT11_Init(uint8_t dht11_pin);
|
||||
|
||||
/** 获取DHT11数据
|
||||
* @param temp_x10 温度值X10
|
||||
* @param humidity 湿度值
|
||||
* @return 无
|
||||
*/
|
||||
int DHT11_StartGet(int *temp_x10, int *humidity);
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,19 @@
|
||||
#ifndef _WIFI_MANAGER_H_
|
||||
#define _WIFI_MANAGER_H_
|
||||
#include "esp_err.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
WIFI_DISCONNECTED, //wifi断开
|
||||
WIFI_CONNECTED, //wifi已连接
|
||||
}WIFI_EV_e;
|
||||
|
||||
typedef void(*wifi_event_cb)(WIFI_EV_e);
|
||||
|
||||
//WIFI STA初始化
|
||||
esp_err_t wifi_sta_init(wifi_event_cb f);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue