Go Down

Topic: GPS + Sonar sensor reading (Read 476 times) previous topic - next topic

takidj

Nov 24, 2013, 06:49 pm Last Edit: Nov 24, 2013, 06:51 pm by takidj Reason: 1
Hi,

My parts are the following:
1. Arduino Nano
2. Adafruit GPS breakout ver 3.
3. Airmar Transducer
4. Ciseco XRF wireless

I have connected the GPS to PIN 2,3 and the Transducer to 4,5 the Nano TX pin is going to the Ciseco XRF RX pin. Both sensors are working fine if I am reading the data seperately (with different codes):

The GPS NMEA code I recieve (baud rate 9600, update rate 1Hz - can be set up to 10Hz):
$GPGGA,172436.076,,,,,0,0,,,M,,M,,*4C
$GPGLL,,,,,172436.076,V,N*7E
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,1,1,01,04,,,27*79
$GPRMC,172436.076,V,,,,,0.00,0.00,241113,,,N*4D
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32

The Transducer NMEA code I recieve (baud rate 4800, update rate 1Hz):
???????$SDDPT,,*57
$SDDBT,,f,,M,,F*28
$YXMTW,?24.6,C*12
(??? is a special character, the transducers is waiting for the echo to come back)

But unfortunately I haven't found a soultion yet how can I recieve both data after each other. I mean one NMEA sentence from GPS, then one from the Transducer and so on. I have the follwing code which is not working as it doesn't forward the whole NMEA sentences just parts of the sentence. Can somebody help me solving the issue? I just want to recieve the RAW data from both sensors, everything else will be done on the laptop!

Code: [Select]

#include <SoftwareSerial.h>

SoftwareSerial GPS(3, 2);
SoftwareSerial SONAR(5, 4);

void setup()
{
  Serial.begin(115200);
 
 GPS.begin(9600);
 SONAR.begin(4800);
}

void loop()
{
 GPS.listen();
 Serial.println("Data from GPS:");
   while (GPS.available() > 0) {
   char inByte = GPS.read();
   Serial.write(inByte);
 }
 SONAR.listen();
 Serial.println("Data from SONAR:");
   while (SONAR.available() > 0) {
   char inByte = SONAR.read();
   Serial.write(inByte);
 }
}


And here is the data I get on the computer (it is a mass):
Data from GPS:
Data from SONAR:
*(QTª?57
$SDDBT,,f,,M,,F*28
$YXMTW,&&Data from GPS:
ÕÔU(¥(KLË,,,,,,,,,,,,,,*1E
$GPGSV,1,1,00*79
$GPRMC,174247.847,V,,,,,0.00,0.00,241113,,,N*41
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
Data frAQ±±RªºjRD4EEJ

I have tried to play with delays and many stuff but without any luck...

I would like to get something like this:
Data from GPS:
$GPGGA,172436.076,,,,,0,0,,,M,,M,,*4C
$GPGLL,,,,,172436.076,V,N*7E
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,1,1,01,04,,,27*79
$GPRMC,172436.076,V,,,,,0.00,0.00,241113,,,N*4D
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
Data from SONAR:
???????$SDDPT,,*57
$SDDBT,,f,,M,,F*28
$YXMTW,?24.6,C*12
Data from GPS:
...
And it should repeat until they have power.

Thanks for any help and assistance in advance!

PaulS

Data that the GPS sends while you are listening to the sonar will be discarded.
Data that the sonar sends while you are listening to the GPS will be discarded.

You really need a Mega.

takidj

What if if I would use the Nano RX pin to recieve the data from GPS and digital 2 to recieve from Transducer? (I do not want to send any data neither to GPS nor to Sonar sensor) Does that allow me to get all data without any loss?

lar3ry

Don't even think about messing with delays. One problem is that you are not gathering data properly.  The instructions in an Arduino happen incredibly quickly. You can bet that when GPS.available() > 0 or SONAR.available() > 0 is true, you will, in almost every case, have 1 byte available. Yes, there may occasionally be more, but not very often. You won't get the next character until the loop() comes around again. In the meantime, the other serial check may well have a byte, which will be sent out, mixed in with the first one.

You need to gather data from the GPS serial, concatenating it to a char array, then when a new line comes in, send that char array out Serial.

I don't know what ends the SONAR communication, but the same technique applies.

PaulS is right. You will need a mega for its multiple hardware serial ports, but unless you rewrite your data gathering, the mega won't stop the lines from intermixing.
There are 10 kinds of people in the world,
those who understand binary, and those who don't.

takidj

Another idea is first wait for the SONAR sensor starting string ($SDDPT) and collect a given ammount of charaters together (the length of one NMEA package) then open the GPS port and wait for the GPS sensor starting string ($GPRMC) and collect a given ammount of characters together (the length of the NMEA package).

I think I can reduce the data loss with adjusting the GPS to 10Hz and only recieve the needed data, not the whole standard NMEA package. While the sonar has 1Hz update rate I think between two sonar signals 1 GPS package can be gathered, so I will have 1 depth measurement for 1 GPS coordinate. In theory...

Can you recommend which library can be used for this or how can I solve this issue?

nikki

Hi takidj,
This sounds a bit like a similar problem I had. http://forum.arduino.cc/index.php?topic=145960.msg1097547

You could try giving the arduino some time to listen to each device following this sort of structure (adapted for each of your softserial instances):

Code: [Select]
XbeeSerial.listen();
  Serial.println("listening to xbee");
    for (unsigned long start = millis(); millis() - start < 3000;)
  {
    } 
  // get any incoming data from xbee:
  if (XbeeSerial.available() > 0) {
    Serial.print("Xbee data:  ");
    // read a byte
    inByte = XbeeSerial.read();
    Serial.println(inByte);
  }

Go Up