Anxinke's new radar module Rd-03 with STM32 makes a simple human body induction radar light tutorial

-

foreword

Anxinke's latest radar module Rd-03 has been released. In order to facilitate the use of this module, this tutorial will use STM32F103C8T6 with Rd-03 to make a simple human detection radar light.

1. Rd-03 pin description

Rd-03 has five pins in total, the following is the pin function definition table:

serial number pin illustrate
1 3.3V input power
2 GND grounding
3 OT1 UART_TX
4 RX UART_RX
5 OT2 Detection result output, output high level when sensing, output low level when not sensing

2. STM32F103C8T6 uses CubeMX with HAL library configuration

Open CubeMX, select STM32F103C8T6, check the serial port and check the interrupt enable. Select serial port 1, then PA9 is TX, and PA10 is RX. Here PA12 is selected as GPIO output to control LED lights.
Please add a picture description

3. Wiring between STM32 and Rd-03

According to the serial port pins generated by CubeMX and the pins of Rd-03, the pin wiring is as follows

STM32 Rd-03
3.3V ------- 3.3V
GND ------- GND
PA9 ------- UART_RX
PA10 ------- UART_TX

Note that the LED light needs to be connected to the PA12 pin and share the ground with the STM32

4. STM32 uses Rd-03

Rd-03 has a built-in MCU to process data, using serial driver, it will print "OFF" and "ON range distance" in the running mode. Therefore, STM32 only needs to judge the ON and OFF characters in the serial port callback function. Define several global variables.

uint8_t RX_BUF[64]={
    
    0};  //缓存数组
uint8_t RX_count=0;      //计数位
uint8_t RX_temp;         //缓存字符
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)//回调函数,检测到雷达发送一帧数据时进行处理
{
    
    
  if(huart == &huart1){
    
    
    RX_BUF[RX_count++] = RX_temp;//将缓存字符存入缓存数组中
    if(RX_BUF[RX_count-1] == 0X0A){
    
    
      // RX_count = 1;
      if(0==(memcmp(&RX_BUF,"ON",strlen("ON"))))        //字符串比较,雷达检测到有人时开灯
      {
    
    
        LED_ON;//宏定义,使能PA12
      }
      if(0==(memcmp(&RX_BUF,"OFF",strlen("OFF"))))      //字符串比较,雷达检测到无人时关灯
      {
    
    
        LED_OFF;//宏定义,关闭PA12
      }
      HAL_UART_Transmit(&huart1,(uint8_t *)&RX_BUF,RX_count,0xFFFF);//将缓存数组中的数据从串口发送出去
      while(HAL_UART_GetState(&huart1)==HAL_UART_STATE_BUSY_TX);//判缓存数组是否发送完毕
      memset(RX_BUF,0x00,sizeof(RX_temp));
      RX_count = 0;
    }  

    HAL_UART_Receive_IT(&huart1,&RX_temp,1);
  }
}

Of course, you can also write related functions to configure the parameters of Rd-03 according to the serial port protocol, such as the maximum detection threshold distance and detection delay time, etc. You can also use the host computer software to adjust the parameters and write them into Rd-03 through TTL, and then connect to STM32 for use. In this tutorial, for the convenience of everyone, a function is written according to the protocol of Rd-03, which can initialize the drive of Rd-03 by inputting two parameters. The function name is as follows. Call this function to configure the corresponding parameters before entering the whileie loop. Modify one parameter at a time, if all five parameters need to be modified, it needs to be called five times. The source code address is attached at the end of the textbook.

//parameter为调试的参数名
//roiMin,roiMax,activeFrameNum,inactiveFrameNum,delay五个可填写
//分别对应最小探测距离门、最远探测距离门、检测到目标最小帧数、目标消失最小帧数、目标消失延迟时间
//data为输入的参数,最远探测距离门范围为0-15
void RD_03_Write_cmd(uint8_t parameter,uint8_t data);

STM32 with Rd-03 to make radar light effect:
Please add a picture description

5. Use the host computer to modify the parameters of Rd-03

Use TTL to connect Rd-03, you can use the host computer to modify the parameters of Rd-03.
Download the corresponding information on the Anxinke page, including the developed tools and corresponding documentation: Rd-03 module

First select the corresponding port number, the baud rate is 115200, and click to connect the device. The parameters on the right can be modified, such as the maximum threshold distance, one threshold distance is 70cm, and the maximum is 15 threshold distances, which is 10.5 meters. The target disappearing delay time is the time for continuous high level output after the target is detected, and the unit is second. After entering the parameters, click Write Sensor Settings to complete the configuration.
insert image description here

6. The Rd-03 module makes radar lights independently

As mentioned earlier, Rd-03 has an independent OT2 pin to output high and low levels, so you only need to use the host computer to configure the corresponding parameters first, write the configured information into the radar module, and connect the OT2 pin to the LED The positive pole of the lamp is connected and the GND and the module share the same ground. Use TTL power supply.
Rd-03 module connected radar light effect

Source address: https://docs.ai-thinker.com/_media/axk-stm32_rd-03-stm32_rd-03-.zip

Summarize

Official Website: https://www.ai-thinker.com
Development DOCS: https://docs.ai-thinker.com
Official Forum: http://bbs.ai-thinker.com
Technical Support: [email protected]

Guess you like

Origin blog.csdn.net/Boantong_/article/details/131102214