你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

ARM®mbed OS入门开发 物联网初步 Nucleo+mbed 与 HC-06 蓝牙模块通信

[复制链接]
anywill 提问时间:2016-10-24 08:54 /
本帖最后由 anywill 于 2017-12-6 20:52 编辑


ARM®mbed OS入门开发   Nucleo  F401RE mbed 与 HC-06 蓝牙模块通信

首先,把nucleo固件更新到最新,

其次,必须装好虚拟串口驱动

蓝牙模块如下

TB2d6OqbXXXXXc4XXXXXXXXXXXX-1092414970.jpg

hc06.jpg





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

微信图片_20171206205041.jpg

评分

参与人数 1 ST金币 +10 收起 理由
zero99 + 10

查看全部评分

收藏 1 评论7 发布时间:2016-10-24 08:54

举报

7个回答
zfz9232 回答时间:2016-10-24 09:06:07
markmarkmarkmark
anywill 回答时间:2016-10-24 09:10:28
串口调试软件HTerm software 在此
其他串口调试软件也可以

hterm.zip

下载

1.46 MB, 下载次数: 7, 下载积分: ST金币 -1

hooke 回答时间:2016-10-24 09:41:21
看到蓝牙进来顶下
hooke 回答时间:2016-10-24 09:42:56
看了lz的帖子我貌似找到我蓝牙调试失败的原因了,谢谢lz
assssdz 回答时间:2016-10-24 12:33:41
xyx365 回答时间:2016-10-28 19:00:32
谢谢分享学习一下
ashou 回答时间:2017-6-13 11:38:38
當程式內加入延遲如wait(0.1)時藍牙就不正常了,有什麼辦法,用中斷怎麼寫呢?
关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新和工艺
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版