我无法在串行监视器中运行AT命令。 (均设置NL& CR + 9600波特) 我按照本教程here。
设备:
这是我连线的方式:
我想提一下,在此之前我连线多次没有电阻但不超过3-4分钟。
这是我使用的代码:
// Basic Bluetooth test sketch 5a for the Arduino Mega.
// AT mode using button switch
// HC-05 with EN pin and button switch
//
// Uses serial with the host computer and serial1 for communication with the Bluetooth module
//
// Pins
// BT VCC to Arduino 5V out. Disconnect before running the sketch
// BT GND to Arduino GND
// BT RX (through a voltage divider) to Arduino TX1 (pin 18)
// BT TX to Arduino RX1 (no need voltage divider) (pin 19)
//
// When a command is entered in to the serial monitor on the computer
// the Arduino will relay it to the Bluetooth module and display the result.
//
char serialByte = '0';
const byte LEDPIN = 13;
void setup()
{
pinMode(LEDPIN, OUTPUT);
// communication with the host computer
Serial.begin(9600);
Serial.println("Do not power the BT module");
Serial.println(" ");
Serial.println("On the BT module, press the button switch (keep pressed, and at the same time power the BT module");
Serial.println("The LED on the BT module should now flash on/off every 2 seconds");
Serial.println("Can now release the button switch on the BT module");
Serial.println(" ");
Serial.println("After entering AT mode, type 1 and hit send");
Serial.println(" ");
// wait for the user to type "1" in the serial monitor
while (serialByte !='1')
{
if ( Serial1.available() ) { serialByte = Serial1.read(); }
}
// communication with the BT module on serial1
Serial1.begin(38400);
// LED to show we have started the serial channels
digitalWrite(LEDPIN, HIGH);
Serial.println(" ");
Serial.println("AT mode.");
Serial.println("Remember to to set Both NL & CR in the serial monitor.");
Serial.println("The HC-05 accepts commands in both upper case and lower case");
Serial.println(" ");
}
void loop()
{
// listen for communication from the BT module and then write it to the serial monitor
if ( Serial1.available() ) { Serial.write( Serial1.read() ); }
// listen for user input and send it to the HC-05
if ( Serial.available() ) { Serial1.write( Serial.read() ); }
}
LED上的闪光灯应每2秒1秒变为开/关 1秒钟关闭。这表示AT模式。你现在可以发布了 按钮开关。
即使LED像所描述的那样闪烁(引自上文) 我在串行监视器中输入1没有得到任何响应。
这就是我的串行监视器在运行所有内容之后的样子:
答案 0 :(得分:0)
<强>解决方案强>
连接:
我使用了这段代码:
#include <SoftwareSerial.h>
#define RxD 10
#define TxD 11
SoftwareSerial BTSerial(RxD, TxD);
void setup(){
// replace BAUDRATE as suggested
BTSerial.begin(BAUDRATE);
Serial.begin(9600);
BTSerial.print("AT\r\n");
}
void loop(){
if (BTSerial.available())
Serial.write(BTSerial.read());
if (Serial.available())
BTSerial.write(Serial.read());
}
按照上面的教程中的说明设置AT模式后。
我尝试使用BAUDRATE
从9600到460800运行代码:
对我来说9600是我HC-05的正确波特率。