I am working on a program using a Arduino Mega 2560 clone (from SainSmart, boards are identical to R3), the SparkFun CAN-Bus shield, and the USGlobalSat EM-406A GPS unit. The library being used is the TinyGPS series of libraries from Mikal Hart. I am trying to get engine information, do some calculations with it, pair it with latitude and longitude, and write the data to an SD card.
A few days ago, I was not having any issues getting information from my GPS (though I couldn’t do it AND get information from the engine… that’s different, though) and I haven’t done much with my project since. Now, I’m trying to get it to do both the engine data and the GPS data. Problem is, there’s an error.
The EM-406A is apparently getting a lock on the GPS satellites, because the LED is blinking, as it does when the device is being tracked. However, when I try and upload the sketch to the Arduino Mega, I get the result pictured in the screenie below. The EM-406A is connected through a CAN-Bus shield (also from SparkFun) and uses SoftwareSerial on pins 3 & 4. I have also tried pins 4 and 5. I have tried this with two different CAN-Bus shields and two different EM-406As. The only thing that’s remained constant is the Arduino Mega. The original hardware combination worked fine just a week or so ago, but, I noticed that pin 6 on the EM-406A connector (the one nearest the outside edge of the shield) was bent and was thus not properly connected. I’m not sure when this damage occured. This pin is one of two ground pins on the connector. The Mega continued to work, but since I haven’t had the GPS logging part of the program working yet, it’s unknown if this caused damage. Furthermore, the second shield/GPS combo did not have this damage.
Speaking of the Mega, it may be worth noting that the pins are jumpered due to incompatibilities between the Uno (which the shield was designed for) and the Mega. The jumpers are as follows:
13->52
12->50
11->51
10->53
I have tried uploading several of Hart’s sample sketches to the Mega in order to see if changing parameters on the program (the pins through which software serial is connected) works. It doesn’t help at all. If the problem was caused by something in my sketch, it would not have been duplicated in Hart’s sketches. The sketch I’m working with is below.
Here’s the kicker: this is my final project for my senior year in college and two other people are relying on me to get this to work. The presentation for this project is May 5th, two weeks from now. This is a critical component in my project. What do I need to do to figure out what I’m doing wrong and fix it?
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
/*
This sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
It requires the use of SoftwareSerial, and assumes that you have a
4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 4800;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
void setup()
{
Serial.begin(115200);
ss.begin(GPSBaud);
Serial.println(F("DeviceExample.ino"));
Serial.println(F("A simple demonstration of TinyGPS++ with an attached GPS module"));
Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
Serial.println(F("by Mikal Hart"));
Serial.println();
}
void loop()
{
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0)
if (gps.encode(ss.read()))
displayInfo();
if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
while(true);
}
}
void displayInfo()
{
Serial.print(F("Location: "));
if (gps.location.isValid())
{
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print(gps.location.lng(), 6);
}
else
{
Serial.print(F("INVALID"));
}
Serial.print(F(" Date/Time: "));
if (gps.date.isValid())
{
Serial.print(gps.date.month());
Serial.print(F("/"));
Serial.print(gps.date.day());
Serial.print(F("/"));
Serial.print(gps.date.year());
}
else
{
Serial.print(F("INVALID"));
}
Serial.print(F(" "));
if (gps.time.isValid())
{
if (gps.time.hour() < 10) Serial.print(F("0"));
Serial.print(gps.time.hour());
Serial.print(F(":"));
if (gps.time.minute() < 10) Serial.print(F("0"));
Serial.print(gps.time.minute());
Serial.print(F(":"));
if (gps.time.second() < 10) Serial.print(F("0"));
Serial.print(gps.time.second());
Serial.print(F("."));
if (gps.time.centisecond() < 10) Serial.print(F("0"));
Serial.print(gps.time.centisecond());
}
else
{
Serial.print(F("INVALID"));
}
Serial.println();
}