Hello,
I have a Sparkfun GPS shield that works fine for me when I use the Serial Monitor for output. By default, the Sparkfun GPS shield connects to pins 2 and 3 on the Arduino board.
When I try to get the output on a serial LCD (a Sparkfun serial LCD), I get no output... I am using pin 7 to connect Arduino to the Serial LCD. In the code below, if I comment out the lines that involve the LCD, the GPS works fine - it prints out the latitude and longitude to the Serial output. But I cannot use the GPS with the LCD! I just see the message "Wait for lock..." from the setup() function and then nothing happens...
I have also tried using the other setting on the Sparkfun board - changing the DLINE setting to UART (so that the GPS uses pins 0 and 1), but then I do not even get the message from the setup() function...
Any help much appreciated!
Ravi
----------------------------------------------------------------------------------------------
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#define RXPIN 2
#define TXPIN 3
#define TERMBAUD 115200
#define GPSBAUD 4800
TinyGPS gps;
SoftwareSerial uart_gps(RXPIN, TXPIN);
SoftwareSerial LCD(4,7); // RX, TX
void getgps(TinyGPS &gps);
void setup() {
Serial.begin(TERMBAUD);
uart_gps.begin(GPSBAUD);
LCD.begin(9600);
clearScreen();
LCD.print("Wait for lock...");
Serial.println("");
Serial.println("GPS Shield QuickStart Example Sketch v12");
Serial.println(" ...waiting for lock... ");
Serial.println("");
}
void loop() {
while(uart_gps.available()) {
int c = uart_gps.read();
if(gps.encode(c)) {
getgps(gps);
}
}
}
void getgps(TinyGPS &gps) {
float latitude, longitude;
gps.f_get_position(&latitude, &longitude);
clearScreen();
LCD.write(0xFE); // command flag
LCD.write(128); // write to line 1
LCD.print("Lat = ");
LCD.print(latitude, DEC);
LCD.write(0xFE); // command flag
LCD.write(192); // write to line 2
LCD.print("Long = ");
LCD.print(longitude, DEC);
Serial.print("Lat/Long: ");
Serial.print(latitude,5);
Serial.print(", ");
Serial.println(longitude,5);
}
void clearScreen() {
LCD.write(0xFE);
LCD.write(0x01);
}