聚丰项目 > 基于RISC-V的多功能遥控器设计
基于中科蓝讯AB32VG1开发套件,设计实现一种能够远程遥控多种无线设备的遥控装置。 本项目准备利用AB32VG1板载的蓝牙功能,实现对多种蓝牙设备远程控制,除此之外,还可以利用板载丰富的IO扩展资源实现其他的无线遥控方案。
归心上路
分享归心上路
团队成员
归心上路 软件工程师
- AB32VG1开发套件
- 摇杆扩展板
- ssd1306 1.3寸 OLED硬件整体框架如下如所示:
本项目使用的硬件资源包括 AB32VG1 开发平台,摇杆扩展版(包含一个joystick摇杆和四个按键)、SSD1306 OLED ,使用板载的支持的蓝牙实现无线通信功能。
本次项目实验软件部分均是在RT-Thread Studio中进行开发设计,相关软件包均能通过软件仓库获取到。
## RT-Thread系统使用情况 和
本次项目实验中使hi用到的软件包如下,包括ssd1306 oled驱动包和bluetrum_sdk 包。使用到的组件包括串口、GPIO和软件模拟IIC组件。
## 程序模块说明
- 摇杆驱动程序设计
摇杆主要使用的是ADC来进行驱动,通过读取摇杆中的电位器的电压值,来判断当前摇杆的状态。驱动示例代码如下。
static int adc_vol_sample(int argc, char *argv[]) { rt_adc_device_t adc_dev; rt_uint32_t value, vol; rt_err_t ret = RT_EOK; /* 查找设备 */ adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME); if (adc_dev == RT_NULL) { rt_kprintf("adc sample run failed! can't find %s device!\n", ADC_DEV_NAME); return RT_ERROR; } /* 使能设备 */ ret = rt_adc_enable(adc_dev, ADC_DEV_CHANNEL_1); /* 读取采样值 */ value = rt_adc_read(adc_dev, ADC_DEV_CHANNEL_1); rt_kprintf("the value is :%d \n", value); /* 转换为对应电压值 */ vol = value * REFER_VOLTAGE / CONVERT_BITS; rt_kprintf("the voltage is :%d.%02d \n", vol / 100, vol % 100); /* 关闭通道 */ ret = rt_adc_disable(adc_dev, ADC_DEV_CHANNEL_1); return ret; }
- OLED驱动程序
void ssd_1306_draw() { ssd1306_Init(); ssd1306_Fill(BLACK); ssd1306_DrawCircle(32, 32, 25,WHITE); // 32 32 ssd1306_Line(32, 7, 32, 57, WHITE); ssd1306_Line(7, 32, 57, 32, WHITE); ssd1306_fillCircle(32,32,2,WHITE); /* A */ ssd1306_DrawCircle(88, 30, 12,WHITE); /* B */ ssd1306_DrawCircle(115, 24, 12,WHITE); /* joystick */ ssd1306_Line(70, 50, 120, 50, WHITE); ssd1306_fillCircle(95,50,3,WHITE); ssd1306_Line(70, 60, 120, 60, WHITE); ssd1306_fillCircle(95,60,3,WHITE); ssd1306_UpdateScreen(); }
- 屏幕图形绘制程序设计
- 遥控器应用界面设计
static void ctl_test() { rt_adc_device_t adc_dev; rt_uint32_t value, vol; rt_uint16_t x_x, x_y; rt_uint16_t joystick_x, joystick_y; rt_uint16_t joystick_y_max; rt_err_t ret = RT_EOK; rt_kprintf(" %s\n",__FUNCTION__); rt_kprintf("ssd1306_Init ... \n"); ssd1306_Init(); ssd1306_Fill(BLACK); ssd1306_DrawCircle(32, 32, 25,WHITE); // 32 32 ssd1306_Line(32, 7, 32, 57, WHITE); ssd1306_Line(7, 32, 57, 32, WHITE); ssd1306_fillCircle(32,32,2,WHITE); /* A */ ssd1306_DrawCircle(88, 30, 12,WHITE); /* B */ ssd1306_DrawCircle(115, 24, 12,WHITE); /* joystick */ ssd1306_Line(70, 50, 120, 50, WHITE); ssd1306_fillCircle(95,50,3,WHITE); ssd1306_Line(70, 60, 120, 60, WHITE); ssd1306_fillCircle(95,60,3,WHITE); ssd1306_UpdateScreen(); /* 查找设备 */ adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME); if (adc_dev == RT_NULL) { rt_kprintf("adc sample run failed! can't find %s device!\n", ADC_DEV_NAME); return RT_ERROR; } /* 使能设备 */ ret = rt_adc_enable(adc_dev, ADC_DEV_CHANNEL_1); ret = rt_adc_enable(adc_dev, ADC_DEV_CHANNEL_2); while(1) { /* 读取采样值 */ value = rt_adc_read(adc_dev, ADC_DEV_CHANNEL_1); // rt_kprintf("PB2_ADC4 adc0 :%d \n", value); /* 转换为对应电压值 */ vol = value * REFER_VOLTAGE / CONVERT_BITS; // rt_kprintf("adc0 the voltage is :%d.%02d \n", vol / 100, vol % 100); // rt_kprintf("\r\n"); x_x = 70+ value * 50/CONVERT_BITS; joystick_x = 7 + value*50/CONVERT_BITS; /* 读取采样值 */ value = rt_adc_read(adc_dev, ADC_DEV_CHANNEL_2); // rt_kprintf("PB1_ADC3 adc1 :%d \n", value); /* 转换为对应电压值 */ vol = value * REFER_VOLTAGE / CONVERT_BITS; // rt_kprintf("adc1 the voltage is :%d.%02d \n", vol / 100, vol % 100); x_y = 70+ value * 50/CONVERT_BITS; joystick_y = 57 - value*50 /CONVERT_BITS; ssd1306_fillCircle(32, 32, 37,BLACK); ssd1306_DrawCircle(32, 32, 25,WHITE); // 32 32 ssd1306_Line(32, 7, 32, 57, WHITE); ssd1306_Line(7, 32, 57, 32, WHITE); // 求坐标 将 圆点的轴坐标固定到圆周内部 joystick_y_max = sqrt(25*25-((joystick_x-32)*(joystick_x-32))); if(joystick_y>32) { if(joystick_y-32 >= joystick_y_max) joystick_y=joystick_y_max+32; } else if(joystick_y<32) { if(32-joystick_y >=joystick_y_max) joystick_y=32-joystick_y_max; } ssd1306_fillCircle(joystick_x,joystick_y,2,WHITE); // oled show // 局部清屏 ssd1306_fillRect(60, 46, 125, 66,BLACK); ssd1306_Line(70, 50, 120, 50, WHITE); ssd1306_Line(70, 60, 120, 60, WHITE); ssd1306_fillCircle(x_x,50,3,WHITE); ssd1306_fillCircle(x_y,60,3,WHITE); ssd1306_UpdateScreen(); rt_thread_mdelay(5); } /* 关闭通道 */ ret = rt_adc_disable(adc_dev, ADC_DEV_CHANNEL_1); ret = rt_adc_disable(adc_dev, ADC_DEV_CHANNEL_2); } /* 导出到 msh 命令列表中 */ //MSH_CMD_EXPORT(adc_oled, adc voltage loop); INIT_APP_EXPORT(adc_oled);
- 代码仓库
ab32vg1-remote-control: rtt大赛作品 基于RISC-V的多功能遥控器设计 (gitee.com)
演示效果已经上传B站,如果后续有更新,会同步更新视频内容。