I have a GPS from Sensor-1 that I am currently trying to test for a larger project. All I want to do right now is see the data in my serial monitor to make sure I am receiving properly. I will post my code below, but I do not think that is my problem (granted I am very new to the arduino language, and relatively new to coding in general, but I modified it from a code I found on the arduino website so I think it's right).
Basically my issue is this: if I plug my nmea stream into the RX pin on the arduino (and ground) and then plug the GPS into power, I get data but my GPS lock indicator light does not come on. If I reverse the order and power up the GPS before plugging in the nmea stream, my GPS indicator light will come on, but will turn off about 30 seconds after plugging in the nmea stream (yet I receive data the entire time). Unplug the nmea stream, and the GPS light is immediately on again.
Have any of you ever worked with Sensor-1 GPS systems, or had a similar issue? I talked to their tech support, and while they were very nice and were obviously trying their best, the best they could tell me was "that's weird."
Here's my code:
int byteGPS=-1;
int rxPin = 0;
void setup() {
// put your setup code here, to run once:
pinMode(rxPin, INPUT);
Serial.begin(19200);
}
void loop() {
// put your main code here, to run repeatedly:
byteGPS=Serial.read();
if (byteGPS == -1) {
delay(100);
} else {
Serial.println(byteGPS);
delay(100);
}
}
Normally, you can't hook the GPS TX to the Arduino RX pin, because that one is used to communicate over USB to the computer. That's also how new programs get uploaded.
Could you hook the GPS to pins 8 & 9 (assuminag an UNO) and use AltSoftSerial for a second serial port? Then you can read the AltSoftSerial and write to Serial for a simple "echo test":
#include <AltSoftSerial.h>
AltSoftSerial gps_port; // always uses 8 & 9 on an UNO, different pins on other Arduinos
void setup()
{
Serial.begin( 9600 ); // or whatever the Serial Monitor Window is using
gps_port.begin( 9600 ); // or whatever the GPS is using...
}
void loop()
{
if (gps_port.available())
Serial.write( gps_port.read() );
}
This is the proper way to check for received data.
Thank you for the help.
I am using an arduino mega. Based on what google says, I should be using pins 46 and 48 for AltSoftSerial.
When verifying your code, I got the following error: "Error compiling for board Arduino/Genuino Mega or Mega 2560." Does the code have to be written differently for the mega?
I'm going to guess that you need to download and install AltSoftSerial.
You were correct. That was my issue, however since I am using the mega I just wired my GPS to one of my other hard serial ports which solved my above mentioned problem.
Now I have another issue. I am trying play around with and learn to use the TinyGPS++ library, but I am coming up with an issue I am sure is a simple coding error on my part.
Here is the code:
#include <TinyGPS++.h>
TinyGPSPlus gps;
void setup()
{
Serial.begin(19200);
Serial1.begin(19200);
}
void loop()
{
if (Serial1.available() > 0); //execute if receiving data
{
gps.encode(Serial1.read());
Serial.println("Satellites:");
Serial.println(gps.satellites.value()); //Print number of satellites
Serial.println(Serial1.available()); //Check if if statement is working properly
}//if
}//void loop
With nothing plugged into serial port 1, I am getting a constant string of:
"Satellites:
0
0"
Why is my if statement being executed? The second 0 confirms Serial1 is not getting data.
Because it takes many characters before the gps data fields are parsed.
There are many examples in my GPS library, NeoGPS, that show the correct loop structure. Most of the examples in TinyGPS++ are not structured correctly, and as you add things for your specific app, it quits working. NeoGPS is also much smaller and faster, and you can configure it to parse just the information you care about.
Here a NeoGPS example for your specific case. It uses the "fix-oriented" methods gps.available and gps.read. You just pass the GPS serial port to the gps.available method, and it checks for GPS characters and parses them. When an entire fix has been assembled from those characters (i.e., lat, lon, satellites, etc.), you can access it with gps.read:
#include "NMEAGPS.h"
NMEAGPS gps; // This object parses received characters
gps_fix fix; // This structure is filled out by gps.read()
void setup()
{
Serial.begin( 9600 );
Serial1.begin( 9600 );
}
void loop()
{
while (gps.available( Serial1 )) {
fix = gps.read();
Serial.println( F("Satellites:") );
if (fix.valid.satellites)
Serial.print( fix.satellites ); // may not have any yet
Serial.println();
}
}
You can see the loop structure is very simple. And this sketch only takes 3878 bytes of program space, and 388 bytes of RAM, and executes in about 800us. The TinyGPS++ sketch takes 5396 bytes of program space and 578 bytes of RAM, and executes in about 1500us.
Even if you don't use the library, be sure to read the Troubleshooting section. It has lots of good tips and things to avoid.
Thank you for showing me your library. It looks to be just what I need.
However, after downloading and following your installation instructions, I tried running your example code without success.The issue is that the while loop is not being entered (determined by printing test text inside and outside the loop).
I know Serial1 is receiving data from running other test codes. Could I have done something incorrectly in the installation process?
There must be some other problem, and it's probably why your original program just spit out zeroes. Did you read the Troubleshooting link I posted?
NeoGPS has a diagnostic program you can use: NMEAdiagnostic.ino. It will try all the baud rates on Serial1, the default port for a Mega build. You shouldn't have to modify anything.
As described in the Install Instructions, make an NMEAdiagnostic subdirectory and copy NMEAdiagnostic.ino into that subdirectory. Also copy in the 14 NeoGPS .H and .CPP files:
I ran NMEAdiagnostic.ino and got "No valid sentences, but characters are being received" for every baud rate. This leads me to believe that there is something wrong with the GPS I am using rather than my code. I contacted tech support at Sensor-1 in hopes of getting that resolved.
I was actually already suspicious that might be the case because running the following code didn't give me nmea sentences, but rather a series of seemingly random integers.
The NeoGPS diagnostic tried 4800 baud. If you copy the NMEAdiagnostic output from the Serial Monitor window into a code block here, we might see something. This is very important, because I suspect it may be using a binary protocol instead of the NMEA text protocol. We can probably tell which GPS device is being used internally, according to what binary protocol it's emitting.
NMEAdiagnostic.INO: started
Looking for GPS device on Serial1
____________________________
Checking 9600 baud...
No valid sentences, but characters are being received.
Check baud rate or device protocol configuration.
Received data:
1599887B428838AD9C18D418389D3D411C7B3BB81D3D42887B0C9C7BAFCE08AD ...{B.8.....8.=A.{;..=B.{..{....
18E9BDB94E294AED9C8818888808FBFBC088DCDE18DE7B8888E58CF9FBC0BC0C ....N)J...............{.........
BC3CB85088DEF9FBC088CC38ED0CBC0808DC98C4E9FBC60C1C38AD9C98887B6A .<.P.......8.............8....{j
15 .
____________________________
Checking 1200 baud...
No valid sentences, but characters are being received.
Check baud rate or device protocol configuration.
Received data:
68 h
____________________________
Checking 2400 baud...
No valid sentences, but characters are being received.
Check baud rate or device protocol configuration.
Received data:
69BFABBF2DDF2E395030538E53F8DD i...-..9P0S.S..
____________________________
Checking 4800 baud...
No valid sentences, but characters are being received.
Check baud rate or device protocol configuration.
Received data:
69DC7BDEFCEF8ED6DC77F6EFF60F i.{......w....
____________________________
Checking 14400 baud...
No valid sentences, but characters are being received.
Check baud rate or device protocol configuration.
Received data:
A9AAC88E37F48CCCEEED3E00 ....7.....>.
____________________________
Checking 19200 baud...
No valid sentences, but characters are being received.
Check baud rate or device protocol configuration.
Received data:
00FFF7D66FEF4BE7DE29636B6B67DE2D676BE7F6DEEBE7EFEBA3CE52E7FF08CE ....o.K..)ckkg.-gk.........R....
CECFE3EB67DE6B679AEFFFEFD66FEF4BE7EB6BAD6B675E2D676BE7F6DEDE35E3 ....g.kg.....o.K..k.kg^-gk....5.
EBA9E7CE35E74A2AE7FFEFFED6DE67E7EBE7EBBDDEA7EFCECE63E7E3EB636BFB ....5.J*......g..........c...ck.
FFEF68E7E7A9EBEBEF67EBEBEB6F67EBEFEBE7499DEB5AD6EF6BADE7FFEF6867 ..h......g...og....I..Z..k....hg
E7EBEBEED6EBDEE7EFEFCEEBADDEEBADDEB5EFEE676BEDE7FFEF6867E7EBEFEF ....................gk....hg....
E7E7A5EF6F67EBBDDE35EB67EFADDEE7E7676B68E7FFEF68E7E7EB9DCED663EF ....og...5.g.....gkh...h......c.
FFDFCF216BAD6B67DE2D676BE7F6D66FEF4BE79AED67 ...!k.kg.-gk...o.K...g
____________________________
Checking 28800 baud...
No valid sentences, but characters are being received.
Check baud rate or device protocol configuration.
Received data:
0095DE6DF2F5EF03EA29A5A7D5E61B33A42A23ED7EE36EBDA72EA66A2BA46AAB ...m.....).....3.*#.~.n....j+.j.
1BA7EA2BE335BDA303A669CDABA7E99ABD9D9E65C2EBB5E615E64BA7695BD1F5 ...+.5....i........e......K.i[..
E11BEB55AE575EA337ABDE16FAF5EF03EA29A5A7D5A063A963A53EAB6EBDA726 ...U.W^.7........)....c.c.>.n..&
A62A2BE423EB5AE6F5E7D5E923EB5EE9694DAB75A95B9A35DDA153BD959E56F2 .*+.#.Z.....#.^.iM.u.[.5..S...V.
ABE6DBBDA1F5A7F5A5D5A6D5A0D5A7F5A4F5A2358DE3D5E13BE34BEE5BEEAA43 ...................5....;.K.[..C
ADCBBA6E65979A6DADAB1AA61AA769ADE1F5E234B5A5F5A4F5A0F5EB5BED34BD ...ne..m......i....4........[.4.
A2F5A0D5A6B6A669BDA1B5A7D5A434B5E82A53BA6E65979A6DADAB69BDECD5ED .......i......4..*S.ne..m..i....
F5EFD5E569CDA61BA75BA533ABD5A0D5A1F5A469B5A1DDA6FDA6FDA71BA52BA0 ....i....[.3.......i..........+.
____________________________
Checking 31250 baud...
No valid sentences, but characters are being received.
Check baud rate or device protocol configuration.
Received data:
8C6A734A734A73537673536D3D692C3A73525A73F9562567DDB7E54F4E5BAF6D .jsJsJsSvsSm=i,:sRZs.V%g...ON[.m
AC9A6FD9356DEC7A73D27A73EC6A737A73B92A73CC4A73D29A6FD29A6DF83567 ..o.5m.zs.zs.jszs.*s.Js..o..m.5g
6C6A737A6FAC6A7552EB750D5F59CABB6D8C9A6FF92D6BAC6A73B9B673AC3A73 ljszo.juR.u._Y..m..o.-k.js..s.:s
739A6F539A6D6D256FEC2A73D34A73D26D254DEC4A732A6B8C6A75D2EB750D5F s.oS.mm%o.*s.Js.m%M.Js*k.ju..u._
596A8F4F526A71527A67F9CD733A675316356DD24A73CAAC7A6F524D9A699A5F Yj.ORjqRzg..s:gS.5m.Js..zoRM.i._
CCB769B675 ..i.u
____________________________
Checking 38400 baud...
No valid sentences, but characters are being received.
Check baud rate or device protocol configuration.
Received data:
56EBB7715F71717DA79B9F9D91958FA3979FA79D919D99A391999B8D8DA763A7 V..q_qq}......................c.
9F8F8F958DA3959B99979FA751A79DA79F8FA79DA39D99A78F9DA399A765A7A5 ............Q................e..
8FA399A765A7A7AB937DE5EBB7715F71597DA77DA799A79F93A79B8FA79F9BA7 ....e....}...q_qY}.}............
9D8DA79D91A7999FA79F99A79F95A7A7A7A7A79DA3918FA79DA39D99A79DA399 ................................
91AB9F73E5EBB7715F715953A799A79DA79D9BA79F9BA79793A79B9597A7999B ...s...q_qYS....................
A79F99A79F91A79F9799A79999A79F95A79F91A79D8D8DA79D93A79F93A7938F ................................
A7999997A79B8FAB917BE5EBB7715F715953A799A79BA79D9BA79D9BA79F9FA7 .........{...q_qYS..............
999B9BA7A79D99A79F9FA79B9D8DA7A79D91A79993A79F999BA79993A79D8DA7 ................................
____________________________
Checking 57600 baud...
No valid sentences, but characters are being received.
Check baud rate or device protocol configuration.
Received data:
9C8E1FEEE38C1EEF9CE2E3EC1CEF1EEF9C9CEC9C9CEC9CE21C1E6E9C9CEC9CE2 ..........................n.....
EC9C9CEC1F73721E6F9C8F1EEE9C8C1FEE9C70EC1CE39F1FEE9C9C9382FE136F .....sr.o.........p............o
9F6EF29212926C1F6E9CEC8F1E6F9C8E1F6E9C8E1EEF9C9CEC1CEFEF1FEEEC1E .n....l.n....o...n..............
E21EEE9C9CEC8EF2721EEEEC1F831F6E9C8C1EEF9C9C8E1F6E9C8C1E6F9C70EC ........r......n........n...o.p.
E31F1EEF9C9C9CEC8EF36E6E9C926E9F6EF39212926C1E6E9CEC1C1F6E9C8F1E ..........nn..n.n....l.n....n...
EF9CE3EC8EF21EEF9C70E3ECEC8E7E1E6FE21E1F6E9C9C9CEC1C921E6E9C9CEC .........p....~.o...n.......n...
9C70EC1E8F931F6E9CE2EC1CE21FEE9C9CEC9C70E2EC1CE36F6E9C9EE26E9F6E .p.....n...........p....on...n.n
F393F2F2F26E9C9C9C9C9082E2E2FF7F1FEEF2EF9C707013730F6EE28FE292E3 .....n...............pp.s.n.....
____________________________
Checking 115200 baud...
No valid sentences, but characters are being received.
Check baud rate or device protocol configuration.
Received data:
FCE0FCE0FCE0FCE0FCE0FC1CFCE0FCE0FCE01C1CFC1CFCE01CE0FCE0FCE0FCE0 ................................
1CE0FCE0FCE01CE0FCE0FCE0FC1C1CE0FCE01CE0FCE0FCE0FCE01C1CFCE0FCE0 ................................
1CE0FCE01CE01C001C00FCE01CE01CE0FCE0FCE0FCE0FCE0FCE0FC00FCE01CE0 ................................
1CE0FC1CFCE0FCE0FCE0FC1C1CE01C1C1CE0FCFCFCFC1C1C1C1C1CE01CFC1CFC ................................
E01CE0FCE0FCE0FCE01CE0FCE0FCE01CE0FCE0FCE0FCE0FCE0FCE01CE0FCE0FC ................................
E0FCE0FCE01CE01CE0FCE0FCE0FCE0FCE0FCE01CE01C00FCE0FCE01CE01CE0FC ................................
E01CE0FCE0FCE0FCE01CE0FCE0FCE01CE01C1CFCE01CE01C00FCE0FC1C1CE0FC ................................
E0FCE0FCE0FCE0FCE0FCE0FCE0FC1C1CE01C1C1CFCFCFCFC1C1C1C1C1CE01CFC ................................
All baud rates tried!
** NMEAdiagnostic completed **
Most of the Sensor-1 products appear to be geared for the agricultural equipment market, specifically speed sensors, and some output radar pulses (?). "Never buy a radar gun again!" Wut?
The data you captured could be RTCM, a closed standard for differential GPS devices. RTCM has a preamble character of 0x66, which occurs several times in the data at 19200. But I think the RTCM protocol is also 30-bit words, so I'm not sure that the preamble of 0x66 is always aligned on an byte boundary. Geez, what committee came up with this. :-/
Not only that, it may be correction information only: it may need to be injected to a GPS receiver, which will use the corrections to improve its solution (i.e., location or speed).
Anybody with RTCM/DGPS or ag experience care to comment?
I don't know of any libraries that parse and use RTCM data, although gpsd (a biiiig package) might have some capabilities.
matters:
You were correct. That was my issue, however since I am using the mega I just wired my GPS to one of my other hard serial ports which solved my above mentioned problem.
Now I have another issue. I am trying play around with and learn to use the TinyGPS++ library, but I am coming up with an issue I am sure is a simple coding error on my part.
Here is the code:
void loop()
{
if (Serial1.available() > 0); //execute if receiving data
{
gps.encode(Serial1.read());
Serial.println("Satellites:");
Serial.println(gps.satellites.value()); //Print number of satellites
Serial.println(Serial1.available()); //Check if if statement is working properly
}//if
}//void loop
With nothing plugged into serial port 1, I am getting a constant string of:
"Satellites:
0
0"
Why is my if statement being executed? The second 0 confirms Serial1 is not getting data.
Remove the semicolon at the end of "if (Serial1.available() > 0);" - with the semicolon there, that is one statement. You want it to do the bracketed following code if true.