我正在尝试通过蓝牙在Arduino和Mac之间建立串行通信并遇到问题.
我的环境是这样的:
首先,我编写了如下所示的arduino,如本教程所示.
/***********************
Bluetooth test program
***********************/
int counter = 0;
int incomingByte;
void setup() {
Serial.begin(115200);
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// if it's a capital R, reset the counter
if (incomingByte == 'R') {
Serial.println("RESET");
counter=0;
}
}
Serial.println(counter);
counter++;
delay(250);
}
Run Code Online (Sandbox Code Playgroud)
当Arduino连接USB时,它工作得很好.(Arduino控制台接收数字序列,如1,2,3,4 ......带换行符.)
然后我用一些电线连接Arduino UNO和蓝牙伴侣,并成功与Mac配对. …