我想连接Arduino nano和GNSS(SIMCom的SIM33ELA独立GNSS模块) .
首先我为rx / tx编写了一个程序,它运行良好,但现在我想使用Software Serial,我得到了错误的数据 .
#include <SoftwareSerial.h>
char incomingByte; // for incoming serial data
double tbs;
SoftwareSerial mySerial(8, 9); // RX, TX
void setup() {
Serial.begin(115200);
while (!Serial) {
}
mySerial.begin(115200);
while (!mySerial) {
}
}
void loop() {
if (mySerial.available()) {
tbs = mySerial.read();
incomingByte = (char)tbs;
Serial.print(incomingByte);
}
/*if (Serial.available() > 0) {
incomingByte = Serial.read();
Serial.print(incomingByte);
}*/
}
任何的想法?
关于结果的图片:
1 回答
大多数情况下,不要将一个字符读入
double
浮点变量 . 这样做:您还应该在这两个引脚上使用AltSoftSerial . SoftwareSerial的效率非常低,因为它会长时间禁用中断 . 它不能同时发送和接收 . 事实上,Arduino在传输或接收角色时无能为力 .
对于GPS库,您可以尝试NeoGPS . 它's the only Arduino library that can parse the sentences from the newest devices. It'也比所有其他库更小,更快,更可靠,更准确 .