本帖最后由 anywill 于 2017-12-6 20:52 编辑
大家参考此帖子连接即可 也可使用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 |
其他串口调试软件也可以
hterm.zip
2016-10-24 09:10 上传
点击文件名下载附件
下载积分: ST金币 -11.46 MB, 下载次数: 7, 下载积分: ST金币 -1