I am using an Arduino Nano in combination with a NEO 6m GPS module. The GPS module is sending data, consisting of a few hundred chars, every second. Since I am communicating with my PC over the integrated serial RX and TX pins of the Arduino, I cannot use them for the sensor without being able to display anything sent from the Arduino on my PC. I am using the SoftwareSerial library to mark two digital pins as my new RX and TX to communicate with the GPS sensor.
The problem is that I have to actively listen to the RX pin at the moment the data is incoming, because otherwise data will be lost, since it's too much to be placed into the serial buffer completely. But on the other hand: I don't want to actively wait for the digital pin to receive data, so I would be in time to read it. It would be best handled with an interrupt every time the digital RX pin starts to receive data. But I read that SoftwareSerial is not compatible with this kind of interrupt, since it has a built-in interrupt itself everytime new data arrives to save it onto the buffer.
This is what I have tried:
#include <SoftwareSerial.h>
String serialString;
// The serial connection to the GPS module
SoftwareSerial ss(4, 3);
String serialString;
void setup() {
Serial.begin(9600);
ss.begin(9600);
//Interrupts when a transmission begin in the RX-Pin is recognized
attachInterrupt(digitalPinToInterrupt(4), readGpsSerialData, CHANGE);
}
void loop() {
//processing data that takes too long to check frequently enough if data is being transmitted at the moment
Serial.println("In Loop");
delay(1000);
}
//Read all the incomming data once transmission started
void readGpsSerialData() {
String serialString = "";
while (ss.available() > 0) {
char serialChar = ss.read();
serialString += serialChar;
}
lastGpsString = serialString;
Serial.print("Data from Interrupt: ");Serial.println(lastGpsString);
}
I think the problem is that my interrupt activates, not just once when the transmission starts, but every time the RX digital value changes (so a lot of times in the transmission). A data RDY value would be nice for this interrupt trigger but the GPS module does not have one.