发帖
9 0 0

【雷达灯控】安信可Rd-03E+ESP32C+磁吸灯+WEBConf+matterig

邦邦
论坛元老

10

主题

27

回帖

4347

积分

论坛元老

积分
4347
雷达灯控教程 1391 9 2024-3-19 22:22:57
本帖最后由 邦邦 于 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.jpg
1.jpg
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指示灯+
3.jpg

5.jpg [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烧录固件
连接
2.jpg
打开软件
无标题.jpg
选择GD32E230K8型号

1.jpg
Rd-03E精准测距固件直接拖入J-Flash中。
Target -> Connect,
3.jpg
下载 “Target -> Production Programming”
4.jpg
[color=rgba(0, 0, 0, 0.75)]4、通讯协议

                               
登录/注册后可看大图

这部分直接看开发资料里的手册,格式就是  AA   AA  byte1  byte2  byte3  55  55;
四、软件设计
R-C.jpg
  1. /* UART Events Example

  2.    This example code is in the Public Domain (or CC0 licensed, at your option.)

  3.    Unless required by applicable law or agreed to in writing, this
  4.    software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  5.    CONDITIONS OF ANY KIND, either express or implied.
  6. */
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include "freertos/FreeRTOS.h"
  10. #include "freertos/task.h"
  11. #include "freertos/queue.h"
  12. #include "driver/uart.h"
  13. #include "esp_log.h"

  14. static const char *TAG = "uart_events";

  15. /**
  16. * This example shows how to use the UART driver to handle special UART events.
  17. *
  18. * It also reads data from UART0 directly, and echoes it to console.
  19. *
  20. * - Port: UART0
  21. * - Receive (Rx) buffer: on
  22. * - Transmit (Tx) buffer: off
  23. * - Flow control: off
  24. * - Event queue: on
  25. * - Pin assignment: TxD (default), RxD (default)
  26. */

  27. #define EX_UART_NUM UART_NUM_0
  28. #define PATTERN_CHR_NUM    (2)         /*!< Set the number of consecutive and identical characters received by receiver which defines a UART pattern*/

  29. #define BUF_SIZE (1024)
  30. #define RD_BUF_SIZE (BUF_SIZE)
  31. static QueueHandle_t uart0_queue;

  32. void uart_event_task(void *pvParameters)
  33. {
  34.     uart_event_t event;
  35.     size_t buffered_size;
  36.     uint8_t* dtmp = (uint8_t*) malloc(RD_BUF_SIZE);

  37.     uint16_t range;          //感应距离

  38.     /* Configure parameters of an UART driver,
  39.      * communication pins and install the driver */
  40.     uart_config_t uart_config = {
  41.         .baud_rate = 115200,
  42.         .data_bits = UART_DATA_8_BITS,
  43.         .parity = UART_PARITY_DISABLE,
  44.         .stop_bits = UART_STOP_BITS_1,
  45.         .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
  46.         .source_clk = UART_SCLK_APB,
  47.     };
  48.     //Install UART driver, and get the queue.
  49.     uart_driver_install(EX_UART_NUM, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart0_queue, 0);
  50.     uart_param_config(EX_UART_NUM, &uart_config);

  51.     //Set UART log level
  52.     esp_log_level_set(TAG, ESP_LOG_INFO);
  53.     //Set UART pins (using UART0 default pins ie no changes.)
  54.     uart_set_pin(EX_UART_NUM, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);

  55.     //Set uart pattern detect function.
  56.     uart_enable_pattern_det_baud_intr(EX_UART_NUM, 0xAA, PATTERN_CHR_NUM, 9, 0, 0);
  57.     //Reset the pattern queue length to record at most 20 pattern positions.
  58.     uart_pattern_queue_reset(EX_UART_NUM, 20);

  59.     for(;;) {
  60.         //Waiting for UART event.
  61.         if(xQueueReceive(uart0_queue, (void * )&event, (portTickType)portMAX_DELAY)) {
  62.             bzero(dtmp, RD_BUF_SIZE);
  63.             ESP_LOGI(TAG, "uart[%d] event:", EX_UART_NUM);
  64.             switch(event.type) {
  65.                 //Event of UART receving data
  66.                 /*We'd better handler data event fast, there would be much more data events than
  67.                 other types of events. If we take too much time on data event, the queue might
  68.                 be full.*/
  69.                 case UART_DATA:
  70.                     ESP_LOGI(TAG, "[UART DATA]: %d", event.size);
  71.                     uart_read_bytes(EX_UART_NUM, dtmp, event.size, portMAX_DELAY);
  72.                     ESP_LOGI(TAG, "[DATA EVT]:");
  73.                     uart_write_bytes(EX_UART_NUM, (const char*) dtmp, event.size);
  74.                     break;
  75.                 //Event of HW FIFO overflow detected
  76.                 case UART_FIFO_OVF:
  77.                     ESP_LOGI(TAG, "hw fifo overflow");
  78.                     // If fifo overflow happened, you should consider adding flow control for your application.
  79.                     // The ISR has already reset the rx FIFO,
  80.                     // As an example, we directly flush the rx buffer here in order to read more data.
  81.                     uart_flush_input(EX_UART_NUM);
  82.                     xQueueReset(uart0_queue);
  83.                     break;
  84.                 //Event of UART ring buffer full
  85.                 case UART_BUFFER_FULL:
  86.                     ESP_LOGI(TAG, "ring buffer full");
  87.                     // If buffer full happened, you should consider encreasing your buffer size
  88.                     // As an example, we directly flush the rx buffer here in order to read more data.
  89.                     uart_flush_input(EX_UART_NUM);
  90.                     xQueueReset(uart0_queue);
  91.                     break;
  92.                 //Event of UART RX break detected
  93.                 case UART_BREAK:
  94.                     ESP_LOGI(TAG, "uart rx break");
  95.                     break;
  96.                 //Event of UART parity check error
  97.                 case UART_PARITY_ERR:
  98.                     ESP_LOGI(TAG, "uart parity error");
  99.                     break;
  100.                 //Event of UART frame error
  101.                 case UART_FRAME_ERR:
  102.                     ESP_LOGI(TAG, "uart frame error");
  103.                     break;
  104.                 //UART_PATTERN_DET
  105.                 case UART_PATTERN_DET:
  106.                     uart_get_buffered_data_len(EX_UART_NUM, &buffered_size);
  107.                     int pos = uart_pattern_pop_pos(EX_UART_NUM);
  108.                     ESP_LOGI(TAG, "[UART PATTERN DETECTED] pos: %d, buffered size: %d", pos, buffered_size);
  109.                     if (pos == -1) {
  110.                         // There used to be a UART_PATTERN_DET event, but the pattern position queue is full so that it can not
  111.                         // record the position. We should set a larger queue size.
  112.                         // As an example, we directly flush the rx buffer here.
  113.                         uart_flush_input(EX_UART_NUM);
  114.                     } else {
  115.                         uart_read_bytes(EX_UART_NUM, dtmp, pos, 100 / portTICK_PERIOD_MS);
  116.                         uint8_t pat[PATTERN_CHR_NUM + 1];
  117.                         memset(pat, 0, sizeof(pat));
  118.                         uart_read_bytes(EX_UART_NUM, pat, PATTERN_CHR_NUM, 100 / portTICK_PERIOD_MS);
  119.                         ESP_LOGI(TAG, "read data: %s", dtmp);
  120.                         ESP_LOGI(TAG, "read pat : %s", pat);



  121.                                 if((dtmp[0] == 0XAA)&&(dtmp[1] == 0XAA)&&(dtmp[5]==0X55)&&(dtmp[6]==0X55)){ //判断帧头帧尾
  122.                             if(dtmp[2] == 0X01||dtmp[2] == 0X02)   //有无人检测
  123.                             {
  124.                                 range=dtmp[4];
  125.                                 range=(range<<8)|dtmp[3];//将小端格式下的距离数据如0X90 0X01转换成0X190

  126.                                 if((range>0X0000)&&(range<=0X00C8))    //0-2米
  127.                                 {
  128.                                     sse_data[luminan] = 120;//调整本灯亮度

  129.                                     //matter发送点亮玄关灯
  130.                                     cmd_handle.command_id = OnOff::Commands::On::Id;//Toggle
  131.                                     lock::chip_stack_lock(portMAX_DELAY);
  132.                                     client::cluster_update(switch_endpoint_id, &cmd_handle);
  133.                                     lock::chip_stack_unlock();
  134.                                 }
  135.                                 else if((range>0X00C8)&&(range<=0X0190))    //2-4米
  136.                                 {
  137.                                     sse_data[luminan] = 200;//调整本灯亮度
  138.                                 }
  139.                                 else if((range>0X0190)&&(range<=0X0258))   //4-6米
  140.                                 {
  141.                                     sse_data[luminan] = 250;//调整本灯亮度
  142.                                 }
  143.                         
  144.                             }
  145.                             else if(dtmp[2] == 0X00)    //无人
  146.                             {
  147.                                 sse_data[luminan] = 0;//调整本灯亮度

  148.                                 //matter发送关闭玄关灯
  149.                                 /*玄关灯定时自动关闭,不需大门前灯关闭
  150.                                 cmd_handle.command_id = OnOff::Commands::On::Id;//Toggle
  151.                                 lock::chip_stack_lock(portMAX_DELAY);
  152.                                 client::cluster_update(switch_endpoint_id, &cmd_handle);
  153.                                 lock::chip_stack_unlock();
  154.                                 */
  155.                             }
  156.                         }


  157.                     }
  158.                     break;
  159.                 //Others
  160.                 default:
  161.                     ESP_LOGI(TAG, "uart event type: %d", event.type);
  162.                     break;
  163.             }
  164.         }
  165.     }
  166.     free(dtmp);
  167.     dtmp = NULL;
  168.     vTaskDelete(NULL);
  169. }

复制代码

五、效果演示
6.jpg
7.jpg
8.jpg
组装好,装入灯内
1.jpg
2.jpg
演示视频:
https://www.bilibili.com/video/BV1Vm411o7f8/六、存在问题
学习步伐还不能停止,活到老学到老,努力学习PCB画板&制作.
七、源码地址和固件

源码地址:https://github.com/bomingfeng

在linux下压缩的,要把tar改成7z.
上传的附件: Rd03eGateLightMatter.tar (455.25 KB, 下载次数: 1)













──── 0人觉得很赞 ────
2.jpg
1.jpg
2.jpg

使用道具 举报

2024-3-20 08:39:46
2024-3-20 08:41:19
不错不错,写的比较详细!
2024-3-20 09:02:47
终于发现一个线比我还乱的哈哈哈哈
2024-3-20 09:11:46
2024-3-20 09:16:59
这灯上有光耦呀
2024-3-20 10:47:34
电压怎么处理的
2024-3-20 11:07:34
2024-3-20 17:20:32
本帖最后由 邦邦 于 2024-3-20 17:22 编辑
lazy 发表于 2024-3-20 10:47
电压怎么处理的

灯用光耦隔离。rd-03e模块与esp32 c3直联串口。模块原理图,有一个降压3.3的。共地就好了
2024-3-21 14:12:44
您需要登录后才可以回帖 立即登录
高级模式
返回
统计信息
  • 会员数: 28486 个
  • 话题数: 40601 篇