Arduino Nano Gnss Software Serial

929 views Asked by At

I want to connect Arduino nano and GNSS (SIMCom’s SIM33ELA standalone GNSS module).

First I wrote a program for rx/tx, which is worked well, but now I want to use Software Serial and I got something wrong data.

#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);              
      }*/
        
}

Any Idea?

Pictures about results:

Wrong data with Software serial

Good data with Serial

1

There are 1 answers

0
slash-dev On

Mostly, don't read one character into a double floating-point variable. Just do this:

void loop()
{
  if (mySerial.available()) {
    char c = mySerial.read();
    Serial.write( c );
  }
}

You should also use AltSoftSerial on those two pins. SoftwareSerial is very inefficient, because it disables interrupts for long periods of time. It cannot transmit and receive at the same time. In fact, the Arduino can do nothing else while a character is transmitted or received.

For a GPS library, you could try NeoGPS. It's the only Arduino library that can parse the sentences from the newest devices. It's also smaller, faster, more reliable and more accurate than all other libraries.