Notes About Working with Various Arduino & Netduino Microcontroller Boards

Wednesday, September 11, 2013

Sending NMEA Commands from an Arduino Due Sketch to a Copernicus II (Trimble) GPS Module

Sparkfun's Copernicus II DIP Module Breakout is a GPS option that works quite handily with the Arduino Due.  The Trimble Studio utility is a free GUI tool for configuring the chip, but it is also quite possible to send NMEA commands to the module via a TTL serial connection from an Arduino sketch.  This brief example, shows how to send NMEA commands from an Arduino Due to the Copernicus II to change the chip's serial port settings and change the default NMEA output.

Connections


Copernicus II Arduino Due
VCC           3.3V
GND           GND
TX-B          RX1 (D19)
RX-B          TX1 (D18)

Code


The following Arduino setup block switches the default speed for the module's serial port B to 19200 baud. It then configures the module to output the NMEA GLL sentence every second.  

void setup() {
  Serial.begin(115200); // For output to serial console
  Serial1.begin(4800);  // Comm for GPS
  // Change port to 19200 baud
  Serial1.write("$PTNLSPT,019200,8,N,1,4,4*1C\r\n");
  delay(1000);  // Delay to let change take effect
  Serial1.end();
  Serial1.begin(19200); // Reconnect at new speed
  // Output GLL sentence only 
  Serial1.write("$PTNLSNM,0002,01*55\r\n");
}

The initial default speed for the Copernicus II's TX-B/RS-B is 4800 baud.

The PT serial port configuration command ($PTNLSPT) is covered on pp. 242-243 of the Copernicus manual. This is a proprietary command that will not work with other GPS modules.

When sending NMEA commands, be sure to pay close attention to the format of the command.  The manual indicates how many characters or digits are expected for each command parameter.  The documentation shows that the baud rate has to be given in 6 digits, so zeros need to be added to the left side of the baud rate to pad it to 6 digits if the speed is less that 115200. Improperly formatted commands don't work, and there are no error messages returned to help you find the problem.

After the asterisk (*) that marks the end of the command parameters comes the 2-digit checksum.  Commands sent to the module will fail silently if the checksum is not correct.  This Web page provides a very convenient tool for calculating the correct NMEA checksum. Don't include the $ and the * when you input the command text for the checksum calculation.  Remember to update the checksum any time you change the command text in any way.

Each NMEA command ends with a carriage return character (\r) followed by a newline character (\n).

The NM automatic message command ($PTNLSNM) is covered on p. 241 of the manual.  The first parameter is the sum of the codes for the desired output sentences (listed in the manual).  Again, left-pad with zeros so the parameter has the required width.  This is another proprietary command that probably won't work with other GPS modules.

If you run into problems, you can always use Trimble Studio on a Windows PC and an FTDI connector to configure the module. While the module does not provide any useful error messages if an NMEA command doesn't work, I have not found the incorrect or malformed commands cause any permanent problems.

This quick example covers only a couple of the GPS module settings that you can change.  See Appendix C, "NMEA 0183," of the Copernicus II Manual for full documentation.

No comments:

Post a Comment