在线时间4854 小时
UID3309825
ST金币0
蝴蝶豆17
注册时间2016-9-4
论坛元老
- 最后登录
- 2020-12-9
|
a0a.1 32b0c
本帖最后由 anywill 于 2017-12-6 20:52 编辑
ARM®mbed OS入门开发 Nucleo F401RE mbed 与 HC-06 蓝牙模块通信
首先,把nucleo固件更新到最新,
其次,必须装好虚拟串口驱动
蓝牙模块如下
Bluetooth HC-06 | Nucleo ST F401RE | RXD | TX | TXD | RX |
| 必须注意nucleo 默认的TX/Do and RX/D1 焊桥并没有连接,
大家参考此帖子连接即可
也可使用D10 and D2 pins . 此例程讲解通过手机和 PC terminal控制nucleo开发板小灯
#include "mbed.h"
Serial bt(D8,D2);//蓝牙在nucleo上的接口
Serial pc(USBTX,USBRX);//虚拟串口
DigitalOut myled(D13);//板载小灯
int main() {
bt.baud(9600);
//prints data on mobile
bt.printf("Connection Established");
//print data on pc terminal
pc.printf("Connection Established");
while(1) {
//For reading and writing data from/to bluetooth HC-06
//check if bluetooth is readable and execute commands to toggle LED
if (bt.readable()) {
char input_key= bt.putc(bt.getc());
//tutn on LED if "y" is entered
if(input_key == 'y') {
myled = 1;
bt.printf("LED is ON");
}
//tutn on LED if "n" is entered
if(input_key == 'n') {
myled = 0;
bt.printf("LED is OFF");
}
}
//For reading and writing data from/to pc terminal
//check if pc is readable and execute commands to toggle LED
if (pc.readable()) {
char input_key= pc.putc(pc.getc());
if(input_key == 'y') {
myled = 1;
pc.printf("LED is ON");
}
if(input_key == 'n') {
myled = 0;
pc.printf("LED is OFF");
}
}
}
}
在安卓手机安装 蓝牙串口助手Bluetooth SPP Manager app, 在PC安装串口调试软件HTerm software
手机与Bluetooth HC-06配对 默认密码是1234
在HTerm 设置 COM port编号和 baud rate 为 9600 点击连接
在app输入Y/N点击发送即可 控制LED
|
评分
-
查看全部评分
|