2

I am intending to show the initial, searching for signal..., screen until the location is updated and then show the location on the lcd. However, even after the led on the gps indicates a satellite fix, the screen never leaves the searching for signal screen. Any help would be greatly appreciated-- very new to microcontroller programming. Sorry for the poorly formatted code block as well, I am in a rush. Thanks in advance.

#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
#include <TinyGPS++.h>
#define RXPin 2
#define TXPin 3
#define GPSBaud 4800
SoftwareSerial ss(RXPin, TXPin);
TinyGPSPlus gps;
LiquidCrystal lcd(12, 11, 10, 7, 6, 5, 4); 
double latt;
double lon;
int screen;
void setup(void);
void loop(void);
void readGPS(void);
void update(void);
void render(void);
void setup() {
 //variable initialization
 latt = 0.0;
 lon = 0.0;
 screen = 0;
 //lcd initial setup
 pinMode(9, OUTPUT);
 analogWrite(9, 100);
 pinMode(13, OUTPUT);
 digitalWrite(13, HIGH);
 //display intial screen
 lcd.begin(16,2);
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("Searching for");
 lcd.setCursor(6,2);
 lcd.print("Signal ...");
 ss.begin(GPSBaud); 
}
void loop() {
 readGPS();
 update();
}
/** Receives data from the gps if available */
void readGPS() {
 while (ss.available() > 0) {
 gps.encode(ss.read());
 }
}
/** Processes the data read by readGPS() */
void update() {
 if (gps.location.isUpdated()) {
 latt = gps.location.lat();
 lon = gps.location.lng();
 render(); 
 }
}
/** Displays the current screen on the lcd */
void render() {
 if (screen == 0) {
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("Lat:");
 lcd.print(latt);
 lcd.print(" Lng:");
 lcd.print(lon);
 lcd.setCursor(0,1);
 lcd.print("Sats:");
 lcd.print(gps.satellites.value());
 }
}
jfpoilpret
9,1627 gold badges38 silver badges54 bronze badges
asked Oct 30, 2014 at 21:27
2
  • Does this also happen when the Arduino is NOT connected to the computer? I've had problems with LCD displays when I leave the Arduino connected. I have to disconnect from the PC and then the display comes to life. Commented Nov 3, 2014 at 14:53
  • Have you tried this outside? A GPS can get a partial lock (I frequently get time/date signals without location signals) which would cause the lock light to turn on, but you wouldn't be receiving latitude and longitude yet. If you can I would output the GPS string to Serial as well and keep an eye on it to see if you are getting lat/long data or if that part is missing. Commented Feb 2, 2015 at 17:52

1 Answer 1

1

Adafruit GPS breakout has their own library setup.
Below is the code I use for my telemetry. Notice I'm using HardwareSerial though.
You can just change that into SoftwareSerial.

#include <SoftwareSerial.h>
#include <Adafruit_GPS.h>
#define GPSECHO false // Disables GPS breakout debug
boolean usingInterrupt = false;
HardwareSerial gpsSerial = Serial1;
Adafruit_GPS GPS(&Serial1);
SoftwareSerial XBee(2, 3); // For wireless
unsigned int REFRESH = 20;
double lat_deg, lon_deg, lat_min, lon_min;
char lat, lon;
void setup()
{
 Serial.begin(115200);
 GPS.begin(115200);
 GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
 GPS.sendCommand(PMTK_SET_NMEA_UPDATE_5HZ); // Either 1HZ or 5HZ
 GPS.sendCommand(PMTK_API_SET_FIX_CTL_5HZ);
 GPS.sendCommand(PGCMD_ANTENNA);
 useInterrupt(true);
}
SIGNAL(TIMER0_COMPA_vect)
{
 char c = GPS.read();
#ifdef UDR0
 if (GPSECHO)
 if (c) UDR0 = c;
#endif
}
void useInterrupt(boolean v)
{
 if(v)
 {
 OCR0A = 0xAF;
 TIMSK0 |= _BV(OCIE0A);
 usingInterrupt = true;
 }
 else
 {
 TIMSK0 &= ~_BV(OCIE0A);
 usingInterrupt = false;
 }
}
void loop()
{
 if(GPS.newNMEAreceived())
 {
 if(!GPS.parse(GPS.lastNMEA()))
 {
 writeData(1, true);
 Serial.print(GPS.hour, DEC); Serial.print(F(","));
 Serial.print(GPS.minute, DEC); Serial.print(F(","));
 Serial.print(GPS.seconds, DEC); Serial.print(F(","));
 Serial.print((int)GPS.fix); Serial.print(F(","));
 Serial.print((int)GPS.fixquality); Serial.print(F(","));
 Serial.print(F("-999")); Serial.print(F(","));
 Serial.print(F("-999")); Serial.print(F(","));
 Serial.print(F("-999")); Serial.print(F(","));
 Serial.print(F("-999")); Serial.print(F(","));
 Serial.print(F("-999")); Serial.print(F(","));
 Serial.print(F("-999"));
 }
 else if(GPS.fix)
 {
 writeData(1, true);
 parseGPS(GPS.latitude, GPS.longitude);
 Serial.print(GPS.hour, DEC); Serial.print(F(","));
 Serial.print(GPS.minute, DEC); Serial.print(F(","));
 Serial.print(GPS.seconds, DEC); Serial.print(F(","));
 Serial.print((int)GPS.fix); Serial.print(F(","));
 Serial.print((int)GPS.fixquality); Serial.print(F(","));
 Serial.print(lat_dd, 8); Serial.print(F(","));
 Serial.print(lon_dd, 8); Serial.print(F(","));
 Serial.print(GPS.speed); Serial.print(F(","));
 Serial.print(GPS.angle); Serial.print(F(","));
 Serial.print(GPS.altitude); Serial.print(F(","));
 Serial.print(GPS.satellites);
 }
 }
 delay(REFRESH);
}
void parseGPS(float _latitude, float _longitude)
{
 lat_deg = (int) (_latitude / 100);
 lon_deg = (int) (_longitude / 100);
 lat_min = _latitude - (lat_deg * 100);
 lon_min = _longitude - (lon_deg * 100);
 lat_dd = (double) lat_deg + ((double) lat_min / 60);
 lon_dd = (double) lon_deg + ((double) lon_min / 60);
 lat = GPS.lat; lon = GPS.lon;
 if (lat == 'S') lat_dd = -lat_dd;
 if (lon == 'W') lon_dd = -lon_dd;
}
void writeData(float data, boolean next)
{
 Serial.print(data);
 if (next) Serial.print(F(","));
}
answered Jan 3, 2015 at 8:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.