Hi,
i have messed around with the port.listen() to no avail.
Code
I started with a working program that read on a single port and logged the data to a SD card. I did the following.
Anticipating I would need a few functions to get the gps and depth data, I
- declared a void function getgps() and moved all the code from the original program that read and logged the gps data to that function
- called the function getups() from the main program
I run this and and it works just fine - logs the gps data
Wanting to make sure I could read the depth sounder ok I
3) connected the depth sounder to the pin the gps had been connected to
4) modified getgps to look for a NMEA depth string instead of a gps string
5) run this and it works just fine - logs the depth data
So, thinking if I declare two software serial ports, I will be good to go, I create a void function getdepth() which is identical to get gps except it looks for a depth NMEA string and it looks on a different serial port. I also modify getgps() so it is looking for GPS data again.
To create the second serial port i do the following
#if ARDUINO >= 100
SoftwareSerial gpsSerial = SoftwareSerial(2, 3);
SoftwareSerial depthSerial = SoftwareSerial(7, 8); // add a port for the depth sounder
#else
NewSoftSerial gpsSerial = NewSoftSerial(2, 3);
NewSoftSerial depthSerial = NewSoftSerial(7, 8); // add a port for the depth sounder
#endif
// Set the GPSRATE to the baud rate of the GPS module. Most are 4800
// but some are 38400 or other. Check the datasheet!
#define GPSRATE 4800
#define DEPTHRATE 4800 // added this for the depth sounder
a little farther along we "start" the serial ports
gpsSerial.begin(GPSRATE);
depthSerial.begin(DEPTHRATE);
and then in the main loop we call the void functions
getgps();
getdepth();
When I run this program I only get depth data
If I switch the order of the begin statements to
depthSerial.begin(DEPTHRATE);
gpsSerial.begin(GPSRATE);
I only get gps data.
I tried adding listen commands as follows
gpsSerial.listen();
getgps();
depthSerial.listen();
getdepth();
I get mostly nothing but occasionally I get an error message from wither getgps or getdepth that is related to a checksum failure or a buffersize problem.
If I tell it to wait after I start listening like this
gpsSerial.listen();
delay(10000);
getgps();
depthSerial.listen();
delay(10000);
getdepth();
i get nothing at all
pretty much stumped. appreciate any help!
Full code attached. Please note that for testing purposes, I am using two gps modules as my depth sounder is attached to the boat which is a little tricky to get in to the lab.
Peter
SD_GPSlogger_modified.ino (5.24 KB)