本帖最后由 沈夜 于 2024-4-9 22:43 编辑
学习经验总结
测距数据 格式
[15:05:17.579]收←◆AA AA 02 42 00 55 55
[15:05:17.628]收←◆AA AA 02 42 00 55 55
[15:05:17.678]收←◆AA AA 02 42 00 55 55
[15:05:17.728]收←◆AA AA 02 42 00 55 55
[15:05:17.779]收←◆AA AA 02 42 00 55 55
[15:05:17.829]收←◆AA AA 02 42 00 55 55
[15:05:17.878]收←◆AA AA 02 42 00 55 55
[15:05:17.929]收←◆AA AA 02 42 00 55 55
[15:05:17.978]收←◆AA AA 02 42 00 55 55
[15:05:18.029]收←◆AA AA 02 42 00 55 55
[15:05:18.078]收←◆AA AA 02 42 00 55 55
[15:05:18.128]收←◆AA AA 02 42 00 55 55
[15:05:18.178]收←◆AA AA 02 42 00 55 55
[15:05:18.228]收←◆AA AA 02 42 00 55 55
# 手势固件 格式
[15:06:57.528]收←◆AA 17 00 00 55
[15:06:57.578]收←◆AA 17 00 00 55
[15:06:57.627]收←◆AA 17 00 00 55
[15:06:57.677]收←◆AA 17 00 00 55
[15:06:57.728]收←◆AA 18 00 00 55
[15:06:57.777]收←◆AA 18 00 00 55
[15:06:57.827]收←◆AA 19 00 00 55
[15:06:57.877]收←◆AA 19 00 00 55
[15:06:57.927]收←◆AA 19 00 00 55
[15:06:57.977]收←◆AA 19 00 00 55
[15:06:58.027]收←◆AA 18 00 00 55
[15:06:58.078]收←◆AA 18 00 00 55
大家可以根据 默认收到的数据 选择上位机 和检测模块功能 是否正常。
相关资源
Rd-03E精准测距固件(固件号2268):点击下载
[ https://docs.ai-thinker.com/_media/rd-03e%E7%B2%BE%E5%87%86%E6%B5%8B%E8%B7%9D%E5%87%BA%E5%8E%82%E5%9B%BA%E4%BB%B6.rar
[ Rd-03E手势识别固件(固件号2269):点击下载
https://docs.ai-thinker.com/_media/rd-03e%E6%89%8B%E5%8A%BF%E8%AF%86%E5%88%AB%E5%87%BA%E5%8E%82%E5%9B%BA%E4%BB%B6.rar
Rd-03E精准测距上位机:Rd-03E精准测距上位机
https://docs.ai-thinker.com/_media/xenp102rm01_tool.zip
Rd-03E手势识别上位机:Rd-03E手势识别上位机
https://docs.ai-thinker.com/_media/xeng102sttool_v1.2.0.0_20230517_1_.zip
使用文档:
https://docs.ai-thinker.com/_media/rd-03e%E4%BD%BF%E7%94%A8%E6%96%87%E6%A1%A3.pdf
固件更新
型号选择 :GD32E230K8
选择 想使用的固件 即可下载。
有串口和dap 两种方式。
觉得使用方便 还是pwlike
<img src="https://bbs.ai-thinker.com/data/attachment/forum/202404/09/223739bzl2gwoyyiyqwiff.jpg" >
参考代码 m61 32s
#include "bflb_mtimer.h"
#include "board.h"
#include "bflb_uart.h"
#include "bflb_gpio.h"
#include "FreeRTOS.h"
#include "task.h"
#include "math.h"
#define DBG_TAG "MAIN"
#include "log.h"
// gpio 用来点亮led 初始化uart
struct bflb_device_s *gpio;
// uart串口读取 rd03e
struct bflb_device_s *rd03e;
// 缓存数据总数,默认Rd03E 数据,是7位舍去开头两个 AA AA
int BUFFER_LEN = 5;
// 换出数据缓存数组
uint8_t UART_RECEIVE_BUFFER[5];
void _rd03eTask(void* pvParameters){
// 当前数组下标
int index = 0;
// 读取数据状态标记
int flag = 0;
// 是否读取到数据末尾
int end = 0;
// led 灯状态
int led_state = 0;
while (1)
{
// 通过 uart 异步接收一个字符
int ch = bflb_uart_getchar(rd03e);
// 防止 数据读取完成不需要再读取,同时防止index越界
if(ch!=-1 && index < BUFFER_LEN){
if(flag == 2){
// 缓存数据
UART_RECEIVE_BUFFER[index++] = ch;
switch (end) {
case 0:
// 检测第一个 55
if(ch == 0x55){
end = 1;
}else{
end = 0;
}
break;
case 1:
// 检测第二个 55 结束
if(ch == 0x55){
end = 2;
}else{
end = 0;
}
break;
default:
break;
}
}else{
switch (flag){
case 0:
// 读取到第一个 AA 改变标记 1 读取第二个 AA 确定数据头
if(ch == 0xAA){
flag = 1;
}else{
flag = 0;
}
break;
case 1:
// 读取到第二个 AA 改变标记 2 准备读取数据
if(ch == 0xAA){
flag = 2;
memset(UART_RECEIVE_BUFFER,0 , sizeof(UART_RECEIVE_BUFFER));
index = 0;
}else{
flag = 0;
}
break;
default:
break;
}
}
}
// 读取到结束标记 处理数据
if(end == 2){
// 打印看下读取的数据
for (size_t i = 0; i < sizeof(UART_RECEIVE_BUFFER); i++) {
printf("0x%02x ", UART_RECEIVE_BUFFER[i]);
}
// 查看目标状态
if(UART_RECEIVE_BUFFER[0] == 0x00){
printf("无目标\\r\\n");
}else if(UART_RECEIVE_BUFFER[0] == 0x01){
printf("运动目标\\r\\n");
}else if(UART_RECEIVE_BUFFER[0] == 0x02){
printf("微动目标\\r\\n");
}
// 有目标检查距离亮灯灭灯操作
if(UART_RECEIVE_BUFFER[0] == 0x01 || UART_RECEIVE_BUFFER[0] == 0x02){
printf("有目标\\r\\n");
uint16_t distance = (UART_RECEIVE_BUFFER[2] << 8) | UART_RECEIVE_BUFFER[1];
printf("距离 :%d\\r\\n", distance);
// 距离在50-70cm之间亮灯
if(distance > 30 && distance < 50){
// 防止灯亮着还执行亮灯
if(led_state == 0){
led_state = 1;
// 亮灯
bflb_gpio_set(gpio, GPIO_PIN_14);
}
}else{
if(led_state == 1){
led_state = 0;
// 灭灯
bflb_gpio_reset(gpio, GPIO_PIN_14);
}
}
}
// 处理完数据 恢复状态
end = 0;
flag = 0;
index = 0;
}
vTaskDelay(1);
}
}
int main(void)
{
board_init();
// 初始化gpio
gpio = bflb_device_get_by_name("gpio");
// 初始化led针脚gpio
bflb_gpio_init(gpio, GPIO_PIN_14, GPIO_OUTPUT | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_0);
bflb_gpio_reset(gpio, GPIO_PIN_14);
// 初始化uart
rd03e = bflb_device_get_by_name("uart1");
// 初始化uart gpio
bflb_gpio_uart_init(gpio, GPIO_PIN_23, GPIO_UART_FUNC_UART1_TX);
bflb_gpio_uart_init(gpio, GPIO_PIN_24, GPIO_UART_FUNC_UART1_RX);
// 初始化uart配置参数
struct bflb_uart_config_s conf = {
.baudrate = 256000,
.data_bits = UART_DATA_BITS_8,
.stop_bits = UART_STOP_BITS_1,
.parity = UART_PARITY_NONE,
.flow_ctrl = UART_FLOWCTRL_NONE,
.rx_fifo_threshold = 7,
.tx_fifo_threshold = 7
};
bflb_uart_init(rd03e, &conf);
// 创建任务接收数据
xTaskCreate(_rd03eTask, (char*)"rd03e", 1024, NULL, 1, NULL);
vTaskStartScheduler();
while (1) {
}
}
<img src="https://bbs.ai-thinker.com/data/attachment/forum/202403/08/212718uuq9cj5j9zjcw50o.png" >
<img src="https://bbs.ai-thinker.com/data/attachment/forum/202404/09/224103dtpowkgkzfvop5r9.jpg" width="337" height="682">