本帖最后由 邦邦 于 2024-3-19 22:29 编辑
一、RD-03E资料链接
Rd-03 系列模组 | 安信可科技 (ai-thinker.com)
ESP32-C3系列模组专题 | 安信可科技 (ai-thinker.com)
二、模块简介
雷达采用高性能一发一收微带天线,包含极简化 24 GHz 雷达传感器硬件 Xen102 和智能算法固件 RM01,而智能算法固件 RM01 采用 FMCW 波形和 S3系列芯片专有的先进信号处理技术,可以实现精准的人体测距和运动/微动人体感应。
本应用在智能家居照明系统中使用,并加入matter协议控制,同时通过WEB配置一些应用参数。此灯安装在大门入户门前,使用ESP32-C3解析Rd-03E的串口数据,检测人体距离雷达的距离,根据距离不同来来调节此灯的灯度(距离越远越亮,达到灯光不伤眼),同时根据距离通过matter点亮入户玄关筒灯(距离近了就点亮)
三、硬件设计
1、改造某宝某多多的雷达灯,功能感应到人亮30S,灭再感应。
拆下不可靠的雷达,用PC817光光耦驱动。
2、ESP32C3与Rd-03E和LED灯的接线[color=rgba(0, 0, 0, 0.75)]Rd-03E |
| esp32c3 |
| 灯 | 5V |
| 3.3V |
| | GND | — — | GND | — — | LED指示灯-,照明灯光耦- | OT1 | — — | RX |
| | RX | — — | TX |
| |
| | IO18 | 照明灯光耦+ | LED照明灯 |
| | IO19 | — — | LED指示灯+ |
[color=rgba(0, 0, 0, 0.75)]
[color=rgba(0, 0, 0, 0.75)]3、固件烧录[color=rgba(0, 0, 0, 0.75)]
Rd-03E精准测距固件(固件号2268):点击下载
直接使用J-LINK烧录固件 连接 打开软件 选择GD32E230K8型号
将Rd-03E精准测距固件直接拖入J-Flash中。 Target -> Connect, 下载 “Target -> Production Programming” [color=rgba(0, 0, 0, 0.75)]4、通讯协议
这部分直接看开发资料里的手册,格式就是 AA AA byte1 byte2 byte3 55 55;
四、软件设计
- /* UART Events Example
- This example code is in the Public Domain (or CC0 licensed, at your option.)
- Unless required by applicable law or agreed to in writing, this
- software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
- CONDITIONS OF ANY KIND, either express or implied.
- */
- #include <stdio.h>
- #include <string.h>
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "freertos/queue.h"
- #include "driver/uart.h"
- #include "esp_log.h"
- static const char *TAG = "uart_events";
- /**
- * This example shows how to use the UART driver to handle special UART events.
- *
- * It also reads data from UART0 directly, and echoes it to console.
- *
- * - Port: UART0
- * - Receive (Rx) buffer: on
- * - Transmit (Tx) buffer: off
- * - Flow control: off
- * - Event queue: on
- * - Pin assignment: TxD (default), RxD (default)
- */
- #define EX_UART_NUM UART_NUM_0
- #define PATTERN_CHR_NUM (2) /*!< Set the number of consecutive and identical characters received by receiver which defines a UART pattern*/
- #define BUF_SIZE (1024)
- #define RD_BUF_SIZE (BUF_SIZE)
- static QueueHandle_t uart0_queue;
- void uart_event_task(void *pvParameters)
- {
- uart_event_t event;
- size_t buffered_size;
- uint8_t* dtmp = (uint8_t*) malloc(RD_BUF_SIZE);
- uint16_t range; //感应距离
- /* Configure parameters of an UART driver,
- * communication pins and install the driver */
- uart_config_t uart_config = {
- .baud_rate = 115200,
- .data_bits = UART_DATA_8_BITS,
- .parity = UART_PARITY_DISABLE,
- .stop_bits = UART_STOP_BITS_1,
- .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
- .source_clk = UART_SCLK_APB,
- };
- //Install UART driver, and get the queue.
- uart_driver_install(EX_UART_NUM, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart0_queue, 0);
- uart_param_config(EX_UART_NUM, &uart_config);
- //Set UART log level
- esp_log_level_set(TAG, ESP_LOG_INFO);
- //Set UART pins (using UART0 default pins ie no changes.)
- uart_set_pin(EX_UART_NUM, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
- //Set uart pattern detect function.
- uart_enable_pattern_det_baud_intr(EX_UART_NUM, 0xAA, PATTERN_CHR_NUM, 9, 0, 0);
- //Reset the pattern queue length to record at most 20 pattern positions.
- uart_pattern_queue_reset(EX_UART_NUM, 20);
- for(;;) {
- //Waiting for UART event.
- if(xQueueReceive(uart0_queue, (void * )&event, (portTickType)portMAX_DELAY)) {
- bzero(dtmp, RD_BUF_SIZE);
- ESP_LOGI(TAG, "uart[%d] event:", EX_UART_NUM);
- switch(event.type) {
- //Event of UART receving data
- /*We'd better handler data event fast, there would be much more data events than
- other types of events. If we take too much time on data event, the queue might
- be full.*/
- case UART_DATA:
- ESP_LOGI(TAG, "[UART DATA]: %d", event.size);
- uart_read_bytes(EX_UART_NUM, dtmp, event.size, portMAX_DELAY);
- ESP_LOGI(TAG, "[DATA EVT]:");
- uart_write_bytes(EX_UART_NUM, (const char*) dtmp, event.size);
- break;
- //Event of HW FIFO overflow detected
- case UART_FIFO_OVF:
- ESP_LOGI(TAG, "hw fifo overflow");
- // If fifo overflow happened, you should consider adding flow control for your application.
- // The ISR has already reset the rx FIFO,
- // As an example, we directly flush the rx buffer here in order to read more data.
- uart_flush_input(EX_UART_NUM);
- xQueueReset(uart0_queue);
- break;
- //Event of UART ring buffer full
- case UART_BUFFER_FULL:
- ESP_LOGI(TAG, "ring buffer full");
- // If buffer full happened, you should consider encreasing your buffer size
- // As an example, we directly flush the rx buffer here in order to read more data.
- uart_flush_input(EX_UART_NUM);
- xQueueReset(uart0_queue);
- break;
- //Event of UART RX break detected
- case UART_BREAK:
- ESP_LOGI(TAG, "uart rx break");
- break;
- //Event of UART parity check error
- case UART_PARITY_ERR:
- ESP_LOGI(TAG, "uart parity error");
- break;
- //Event of UART frame error
- case UART_FRAME_ERR:
- ESP_LOGI(TAG, "uart frame error");
- break;
- //UART_PATTERN_DET
- case UART_PATTERN_DET:
- uart_get_buffered_data_len(EX_UART_NUM, &buffered_size);
- int pos = uart_pattern_pop_pos(EX_UART_NUM);
- ESP_LOGI(TAG, "[UART PATTERN DETECTED] pos: %d, buffered size: %d", pos, buffered_size);
- if (pos == -1) {
- // There used to be a UART_PATTERN_DET event, but the pattern position queue is full so that it can not
- // record the position. We should set a larger queue size.
- // As an example, we directly flush the rx buffer here.
- uart_flush_input(EX_UART_NUM);
- } else {
- uart_read_bytes(EX_UART_NUM, dtmp, pos, 100 / portTICK_PERIOD_MS);
- uint8_t pat[PATTERN_CHR_NUM + 1];
- memset(pat, 0, sizeof(pat));
- uart_read_bytes(EX_UART_NUM, pat, PATTERN_CHR_NUM, 100 / portTICK_PERIOD_MS);
- ESP_LOGI(TAG, "read data: %s", dtmp);
- ESP_LOGI(TAG, "read pat : %s", pat);
- if((dtmp[0] == 0XAA)&&(dtmp[1] == 0XAA)&&(dtmp[5]==0X55)&&(dtmp[6]==0X55)){ //判断帧头帧尾
- if(dtmp[2] == 0X01||dtmp[2] == 0X02) //有无人检测
- {
- range=dtmp[4];
- range=(range<<8)|dtmp[3];//将小端格式下的距离数据如0X90 0X01转换成0X190
- if((range>0X0000)&&(range<=0X00C8)) //0-2米
- {
- sse_data[luminan] = 120;//调整本灯亮度
- //matter发送点亮玄关灯
- cmd_handle.command_id = OnOff::Commands::On::Id;//Toggle
- lock::chip_stack_lock(portMAX_DELAY);
- client::cluster_update(switch_endpoint_id, &cmd_handle);
- lock::chip_stack_unlock();
- }
- else if((range>0X00C8)&&(range<=0X0190)) //2-4米
- {
- sse_data[luminan] = 200;//调整本灯亮度
- }
- else if((range>0X0190)&&(range<=0X0258)) //4-6米
- {
- sse_data[luminan] = 250;//调整本灯亮度
- }
-
- }
- else if(dtmp[2] == 0X00) //无人
- {
- sse_data[luminan] = 0;//调整本灯亮度
- //matter发送关闭玄关灯
- /*玄关灯定时自动关闭,不需大门前灯关闭
- cmd_handle.command_id = OnOff::Commands::On::Id;//Toggle
- lock::chip_stack_lock(portMAX_DELAY);
- client::cluster_update(switch_endpoint_id, &cmd_handle);
- lock::chip_stack_unlock();
- */
- }
- }
- }
- break;
- //Others
- default:
- ESP_LOGI(TAG, "uart event type: %d", event.type);
- break;
- }
- }
- }
- free(dtmp);
- dtmp = NULL;
- vTaskDelete(NULL);
- }
复制代码
五、效果演示
组装好,装入灯内
演示视频:
https://www.bilibili.com/video/BV1Vm411o7f8/六、存在问题
学习步伐还不能停止,活到老学到老,努力学习PCB画板&制作.
七、源码地址和固件源码地址:https://github.com/bomingfeng 在linux下压缩的,要把tar改成7z.
|