我正在尝试从MacOS设备通过HM-10模块(BLE)将数据发送到Arduino,并遵循此guide。至于我的线路,我做了以下工作:我有HM-10上的RX引脚钩到Arduino上的TX;TX引脚上的HM-10到Arduino上的RX;VCC上的HM-10到Arduino上的3.3V;HM-10上的GND连接到Arduino上的GND。
我使用了以下代码:
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(0, 1); //RX|TX
void setup(){
Serial.begin(9600);
BTSerial.begin(9600); // default baud rate
Serial.println("AT commands: ");
}
void loop(){
//Read from the HM-10 and print in Serial Moniter
if(BTSerial.available()) {
Serial.write(BTSerial.read());
}
//Read from the Serial Moniter and print to the HM-10
if(Serial.available()) {
BTSerial.write(Serial.read());
}
}当我发送AT+NAME?时,我应该收到OK+NAME:HMSoft,但我一直收到一个奇怪字符的字符串:AV⸮5⸮。此外,这些命令似乎都没有任何效果。
我做错了什么,以至于我无法从我的计算机与HM-10进行交互?
发布于 2017-09-05 22:45:16
SoftwareSerial BTSerial(0, 1); //RX|TX您正在使用硬件串行引脚进行软件串行。然后你同时使用这两种方法,这会破坏数据。
将软件串行引脚移动到不同的引脚,如2和3。
https://stackoverflow.com/questions/46045462
复制相似问题