我无法通过蓝牙连接在Tera Term和Arduino Mega之间进行通信。我的目标是能够设置Mega,以便以后可以使用它与C++应用程序交换文本命令。使用我在这个站点上找到的代码,我可以使用Arduino IDE Serial Monitor将文本发送到Tera Term终端,但我不能将文本从Tera Term终端发送到Arduino。它永远不会识别从终端发送的文本。我使用的蓝牙模块是SparkFun的bluetooth Mate Gold。该代码的目的是检测传入的字符,然后激活LED。我的代码如下所示:
#include <SoftwareSerial.h>
int bluetoothTx = 15;
int bluetoothRx = 14;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup() {
pinMode(13, OUTPUT);
//Setup usb serial connection to computer
Serial.begin(9600);
//Setup Bluetooth serial connection to android
bluetooth.begin(115200);
bluetooth.print("$$$");
delay(100);
bluetooth.println("U,9600,N");
bluetooth.begin(9600);
}
void loop() {
//Read from bluetooth and write to usb serial
if(bluetooth.available()) {
char toSend = (char)bluetooth.read();
Serial.print(toSend);
flashLED();
}
//Read from usb serial to bluetooth
if(Serial.available()) {
char toSend = (char)Serial.read();
bluetooth.print(toSend);
flashLED();
}
}
void flashLED() {
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
}在Tera Term中唯一起作用的似乎是使用“$$$”进入命令模式。这样,我就可以运行诸如“D”这样的命令。我不确定为什么我不能从Tera Term向Arduino发送字符并让它们被读取。如有任何建议,欢迎光临。
发布于 2015-08-06 03:20:34
我刚刚构建了同样的东西,在配置模块之前,我必须添加500ms的延迟。我在接收数据时也遇到了问题,因为我使用的引脚不支持PCINT中断。
delay(500);
bluetooth.begin(115200);
bluetooth.print("$");
bluetooth.print("$");
bluetooth.print("$");
delay(100);
bluetooth.println("U,9600,N");
bluetooth.begin(9600);https://stackoverflow.com/questions/28131851
复制相似问题