I use an Arduino Uno R2 with a Flytron GPS and a Sparkfun Nokia LCD with the TinyGPS library (version 12) and ColorLCDShield library.
The GPS is attached to pins 2 and 3 with SoftwareSerial. The LCD shield is attached as such: Vbat to 5v of the Arduino, 3.3V to the 3.3V pin on the Arduino, GND to gnd obviously. Then reset to pin 8, DIO to pin 11, SCK to pin 13 and CS to pin 9.
I also use an external 12V power supply because I noticed the GPS wouldn't get a fix when I just powered everything of a USB port.
The idea is to have GPS data show on the lcd, but for now I just output it to Serial.
I can get the GPS to work, or the LCD shield, but not both together.
This is the code, it's a combination of sample code found for both the gps and lcd shield:
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <ColorLCDShield.h>
TinyGPS gps;
LCDShield lcd;
#define RXPIN 2
#define TXPIN 3
SoftwareSerial nss(RXPIN, TXPIN);
long GPS_lat, GPS_lon = 0;
unsigned long GPS_speed, GPS_course, GPS_number_of_satellites = 0;
unsigned long GPS_chars;
unsigned short GPS_sentences, GPS_failed_checksum;
unsigned long previousTime, currentTime;
int GPS_year = 0 ;
byte GPS_month, GPS_day, GPS_hour, GPS_minute, GPS_second, GPS_hundredths = 0 ;
unsigned long GPS_fix_age = 0;
byte LCD_cont = 50; // Good center value for contrast
void setup()
{
previousTime = currentTime = 0;
nss.begin(9600);
Serial.begin(9600);
lcd.init(EPSON); // Initialize the LCD, try using PHILLIPS if it's not working
lcd.contrast(LCD_cont); // Initialize contrast
lcd.clear(WHITE); // Set background to white
lcd.setPixel(GREEN, 66, 66);
lcd.setCircle(66, 66, 30, GREEN);
lcd.setCircle(66, 66, 60, GREEN);
lcd.setCircle(66, 66, 1, GREEN);
lcd.setStr("test", 20, 20, WHITE, BLACK);
}
void loop()
{
currentTime = millis();
while (nss.available())
{
//Serial.println("ding dong");
int c = nss.read();
if (gps.encode(c))
{
Serial.println("GPS data ontvangen!");
// retrieves +/- lat/long in 100.000ths of a degree
gps.get_position(&GPS_lat, &GPS_lon, &GPS_fix_age);
gps.crack_datetime(&GPS_year, &GPS_month, &GPS_day, &GPS_hour, &GPS_minute, &GPS_second, &GPS_hundredths, &GPS_fix_age);
GPS_hour = GPS_hour+2;
if (GPS_hour >= 24) GPS_hour = GPS_hour -24;
// returns speed in 100ths of a knot
GPS_speed = gps.speed();
// course in 100ths of a degree
GPS_course = gps.course();
GPS_number_of_satellites = gps.satellites();
}
}
if (currentTime - previousTime >= 1000) {
if (GPS_number_of_satellites > 0) {
Serial.print (GPS_hour);
Serial.print (":");
Serial.print (GPS_minute);
Serial.print (":");
Serial.print (GPS_second);
Serial.print (" - ");
Serial.print ("Latitude: ");
Serial.print (GPS_lat);
Serial.print (" Longitude: ");
Serial.print (GPS_lon);
Serial.print (" Fix age: ");
Serial.print (GPS_fix_age);
Serial.print (" Satellieten: ");
Serial.println (GPS_number_of_satellites);
}
else {
Serial.println ("No GPS fix");
}
previousTime = currentTime;
}
}
Symptom: the LCD keeps flashing on and off, drawing only a small part of the circle.
So I started commenting parts. If I comment the lcd.SetStr:
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <ColorLCDShield.h>
TinyGPS gps;
LCDShield lcd;
#define RXPIN 2
#define TXPIN 3
SoftwareSerial nss(RXPIN, TXPIN);
long GPS_lat, GPS_lon = 0;
unsigned long GPS_speed, GPS_course, GPS_number_of_satellites = 0;
unsigned long GPS_chars;
unsigned short GPS_sentences, GPS_failed_checksum;
unsigned long previousTime, currentTime;
int GPS_year = 0 ;
byte GPS_month, GPS_day, GPS_hour, GPS_minute, GPS_second, GPS_hundredths = 0 ;
unsigned long GPS_fix_age = 0;
byte LCD_cont = 50; // Good center value for contrast
void setup()
{
previousTime = currentTime = 0;
nss.begin(9600);
Serial.begin(9600);
lcd.init(EPSON); // Initialize the LCD, try using PHILLIPS if it's not working
lcd.contrast(LCD_cont); // Initialize contrast
lcd.clear(WHITE); // Set background to white
lcd.setPixel(GREEN, 66, 66);
lcd.setCircle(66, 66, 30, GREEN);
lcd.setCircle(66, 66, 60, GREEN);
lcd.setCircle(66, 66, 1, GREEN);
// lcd.setStr("test", 20, 20, WHITE, BLACK); <<<<-------------------------------------------------
}
void loop()
{
currentTime = millis();
while (nss.available())
{
//Serial.println("ding dong");
int c = nss.read();
if (gps.encode(c))
{
Serial.println("GPS data ontvangen!");
// retrieves +/- lat/long in 100.000ths of a degree
gps.get_position(&GPS_lat, &GPS_lon, &GPS_fix_age);
gps.crack_datetime(&GPS_year, &GPS_month, &GPS_day, &GPS_hour, &GPS_minute, &GPS_second, &GPS_hundredths, &GPS_fix_age);
GPS_hour = GPS_hour+2;
if (GPS_hour >= 24) GPS_hour = GPS_hour -24;
// returns speed in 100ths of a knot
GPS_speed = gps.speed();
// course in 100ths of a degree
GPS_course = gps.course();
GPS_number_of_satellites = gps.satellites();
}
}
if (currentTime - previousTime >= 1000) {
if (GPS_number_of_satellites > 0) {
Serial.print (GPS_hour);
Serial.print (":");
Serial.print (GPS_minute);
Serial.print (":");
Serial.print (GPS_second);
Serial.print (" - ");
Serial.print ("Latitude: ");
Serial.print (GPS_lat);
Serial.print (" Longitude: ");
Serial.print (GPS_lon);
Serial.print (" Fix age: ");
Serial.print (GPS_fix_age);
Serial.print (" Satellieten: ");
Serial.println (GPS_number_of_satellites);
}
else {
Serial.println ("No GPS fix");
}
previousTime = currentTime;
}
}
Symptom: Everything works, with GPS info over Serial, but there's obviously no text on the lcd.
With only the gps code commented:
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <ColorLCDShield.h>
TinyGPS gps;
LCDShield lcd;
#define RXPIN 2
#define TXPIN 3
SoftwareSerial nss(RXPIN, TXPIN);
long GPS_lat, GPS_lon = 0;
unsigned long GPS_speed, GPS_course, GPS_number_of_satellites = 0;
unsigned long GPS_chars;
unsigned short GPS_sentences, GPS_failed_checksum;
unsigned long previousTime, currentTime;
int GPS_year = 0 ;
byte GPS_month, GPS_day, GPS_hour, GPS_minute, GPS_second, GPS_hundredths = 0 ;
unsigned long GPS_fix_age = 0;
byte LCD_cont = 50; // Good center value for contrast
void setup()
{
previousTime = currentTime = 0;
nss.begin(9600);
Serial.begin(9600);
lcd.init(EPSON); // Initialize the LCD, try using PHILLIPS if it's not working
lcd.contrast(LCD_cont); // Initialize contrast
lcd.clear(WHITE); // Set background to white
lcd.setPixel(GREEN, 66, 66);
lcd.setCircle(66, 66, 30, GREEN);
lcd.setCircle(66, 66, 60, GREEN);
lcd.setCircle(66, 66, 1, GREEN);
lcd.setStr("test", 20, 20, WHITE, BLACK);
}
void loop()
{
currentTime = millis();
// while (nss.available())
// {
// //Serial.println("ding dong");
// int c = nss.read();
// if (gps.encode(c))
// {
// Serial.println("GPS data ontvangen!");
// // retrieves +/- lat/long in 100.000ths of a degree
// gps.get_position(&GPS_lat, &GPS_lon, &GPS_fix_age);
//
// gps.crack_datetime(&GPS_year, &GPS_month, &GPS_day, &GPS_hour, &GPS_minute, &GPS_second, &GPS_hundredths, &GPS_fix_age);
// GPS_hour = GPS_hour+2;
// if (GPS_hour >= 24) GPS_hour = GPS_hour -24;
// // returns speed in 100ths of a knot
// GPS_speed = gps.speed();
//
// // course in 100ths of a degree
// GPS_course = gps.course();
//
// GPS_number_of_satellites = gps.satellites();
//
// }
// }
if (currentTime - previousTime >= 1000) {
if (GPS_number_of_satellites > 0) {
Serial.print (GPS_hour);
Serial.print (":");
Serial.print (GPS_minute);
Serial.print (":");
Serial.print (GPS_second);
Serial.print (" - ");
Serial.print ("Latitude: ");
Serial.print (GPS_lat);
Serial.print (" Longitude: ");
Serial.print (GPS_lon);
Serial.print (" Fix age: ");
Serial.print (GPS_fix_age);
Serial.print (" Satellieten: ");
Serial.println (GPS_number_of_satellites);
}
else {
Serial.println ("No GPS fix");
}
previousTime = currentTime;
}
}
Symptom: The screen just hangs, blue color, no serial info is sent (Tx on the Arduino doesn't blink)
It seems that the lcd.SetStr and setChar functions are the key, as everything starts working as soon as I comment the lcd.setStr line.
If I change lcd.setStr("test", 20, 20, WHITE, BLACK); to lcd.setChar('t', 20, 20, WHITE, BLACK); the circles draw partially, the 't' appears on the screen, but Serial is outputting crap.
gps_locator.ino (2.41 KB)