【问题标题】:Arduino connection with bluetooth hc-06Arduino与蓝牙hc-06的连接
【发布时间】:2014-01-27 13:17:46
【问题描述】:

大家好

我有一个小问题。我需要将 Arduino Mini Pro 与 HC-06 蓝牙连接。

输入/输出: Arduino HC-06

接地 ------------------ G(接地)

VCC --------- V

D0(TX)------------------2

D1(RX) -----------------3

我试过这个代码:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

void setup()
{
Serial.begin(9600);
Serial.println("Goodnight moon!");
//mySerial.begin(115200);    //if you change the baud and want to re-run this sketch, make sure this baud rate matches the new rate.
mySerial.begin(38400);
//mySerial.begin(9600);


delay(1000);
mySerial.print("AT");
delay(1000);
mySerial.print("AT+VERSION");
//delay(1000);
//mySerial.print("AT+PIN1234"); // Set pin to 1234  was 1342
//delay(1000);
//mySerial.print("AT+NAMEJY-MCU-HC06"); // Set the name to JY-MCU-HC06
delay(1000);
//mySerial.print("AT+BAUD8"); // Set baudrate to 115200
//mySerial.print("AT+BAUD4"); // Set baudrate to 9600
//mySerial.print("AT+BAUD7"); // Set baudrate to 57600
delay(1000);
}

void loop() // run over and over
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}

但是,我不能得到好的。你能帮助我吗? 谢谢。

【问题讨论】:

  • 当您使用 Arduino Mini Pro 时,您使用的是 vUSB 串行端口(又名 FTDI)。尝试将其连接到 HC06 并尝试通过串行端口与其通信。然后从那里去。

标签: bluetooth arduino


【解决方案1】:

正如 mpflaga 所说,调试这些模块的最佳和最简单的方法是直接用您的计算机连接到它们并通过终端程序(超级终端等)进行连接。

话虽如此,我猜模块可能以 9600 波特率运行,而不是 38400。 另外,我认为您的代码会更好地工作,例如:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

char myChar;

void setup()
{
    Serial.begin(9600);

    //mySerial.begin(38400);
    mySerial.begin(9600);

    mySerial.print("AT");
    delay(1000);
}

void loop() // run over and over
{
    while ( mySerial.available() )
    { 
        myChar = mySerial.read();
        Serial.print(myChar);
    }

    while ( Serial.available() )
    { 
        myChar = Serial.read();
        mySerial.print(myChar);
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-29
    • 2018-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-22
    • 1970-01-01
    相关资源
    最近更新 更多