Writing to NMEA


I have a gps device that outputs several other sensor readings (wind, heading, ect.). All of those strings are output in NMEA format strings. I am able to read these strings and also (with the TinyGPS library) I can parse them to pull what I need.

Now the problem,

I want to be able to send NMEA strings back at the device in order to tell it to output different NMEA string types.

For example, sending "$PAMTC,EN,HDG" should enable the "$HCHDG" string on the device. Or sending "#PAMTC,QV" should query the software version number.

My code to read from the device is:

void setup()
  // put your setup code here, to run once:

void loop()
  // put your main code here, to run repeatedly:
  char c;
  c = Serial1.read();

"Serial" is to print to the computer serial monitor. "Serial1" is to read from the device.

Any help would be appreciated.


Seems the obvious way to do it. If a linefeed is needed to terminate the command string then use Serial1.println() instead.

I have made a previous attempt with this in the set-up code but have had no luck enabling the strings. I dont know if there is a way to see if I am successfully communicating with the device. Additionally, do I need to stop the incoming flow with a break or is this done automatically?

You might need to calculate a checksum for the message.

Sending configuration messages to my GPS devices require checksums. There is an algorithm for this which dr google should be able to help you find.

The GPS I've been using accepts commands asynchronously with respect to its output. After receiving a command it responds as soon as possible with an acknowledgement string containing a parameter to indicate success or failure. The commands require a checksum as well as a CR and LF. But that's not your GPS. What is your GPS? Have you read the manual carefully?

As far as seeing if the commands were accepted, lacking any sort of acknowledgement responses the obvious thing would be to see if it starts doing what you tried to command it to do.

Are you sure you have the serial line that transmits to the GPS connected and programmed correctly?

The checksum scheme is standard in NMEA and all GPS devices that I have seen, use them. When the GPS device outputs it's data to you, it's up to you whether you want to bother verifying them, or not. When you are trying to send data TO the GPS device, they will usually require the correct checksum.

I get the sense that NMEA is a pretty loose standard and it is sometimes intermixed with proprietary sentences and commands. So who knows what his GPS does?

I found a document that could be the manual for his device. It accepts the command he’s asking about anyway. It says this:

All received sentences and commands can include or omit the NMEA checksum. If a checksum is included, the sentence will be checked against its checksum, and the sentence will be accepted only if there is a checksum match. If the NMEA checksum is excluded, it is required that the preceding asterisk (*) also be excluded. If no checksum is provided, the WeatherStation will accept the sentence without error checking. It is recommended that all sentences and commands provided to the WeatherStation include a checksum to help ensure integrity of the transmitted data.

I am using an Airmar 150wx. ftp://gyre.umeoce.maine.edu/pub/cinar/docs/airmar_wx200/300WXUserTechnicalManual_0183.pdf

There is nothing in the manual about the use of checksums to send data back.

Does anyone have sample code for this?

I do have a list of what strings I need to send the device.

nconway15: I am using an Airmar 150wx. ftp://gyre.umeoce.maine.edu/pub/cinar/docs/airmar_wx200/300WXUserTechnicalManual_0183.pdf

There is nothing in the manual about the use of checksums to send data back.

Sure there is. Section 1.2, page 45. It says they're optional but recommended.

Are you sure you read the manual? Looking at the page for the command you want to send to enable the HDG sentence output it appears you aren't using the correct syntax.

Coming up with NMEA checksums could be extremely painful if not for... http://nmeachecksum.eqth.net/

I don't know what part of page 66 you didn't read, probably, none of it.

Try this


which should turn the heading messages ON with a frequency of once per second.

You might also want to try this.

char s[]= { "$PAMTC,EN,HDG,1,10*HH\r\n" } ;

int cpos=1 ;
uint8_t cs=0 ;

while (true)
    cs = cs^s[cpos] ;
    cpos++ ;
    if ( s[cpos] == '*' )
         char css[3] ;
         sprintf( css,"%02X", cs);
         s[cpos+1] = css[0] ;
         s[cpos+2] = css[1] ;
         break ;
Serial1.print(s) ;

Would you recomend putting this all into void setup() to only run once? Or do you think it will require a constant looping of it?

Thanks, Nolan

Well you should only need to configure the device once. And if you plan to always run it this way, you can save the preferred setting in the gps device's own eprom.