Hello,
A couple of days ago, I had posted a question at this forum asking how to use a serial LCD with GPS. I have just done this and the code is below...
The problem is that when you use SoftwareSerial, you can create multiple (soft) serial ports (like one for the serial lcd and one for the GPS), but only one of them can be active at any given time. There are methods to choose a particular port and read from it, but I found that a simpler solution is to connect the GPS module to the built in hardware serial port on the Uno (digital pins 0 and 1).
I am using the Sparkfun GPS shield (https://www.sparkfun.com/products/10709) and the Sparkfun Serial LCD (https://www.sparkfun.com/products/9395) with an Arduino Uno.
The Sparkfun GPS shield has a switch labelled UART - DLINE. To upload any code to the Arduino this switch must be in the DLINE position. If you create a SoftwareSerial port to read GPS data, this switch remains in the DLINE position. If you want to use the built in hardware serial port on pins 0/1, change this to the UART position (after uploading the code).Then the Serial object will read from and write to this hardware post. No connections need to be made for this. The Serial LCD is connected to a SoftwareSerial port. Here is the code - I put an LED on pin 13 to tell me if I could connect to a satellite...
// LED on pin 13, GPS connected to Hardware Serial pins 0/1
// so must be compiled with switch in DLINE position and run with switch in UART position
//
#include "TinyGPS.h"
#include <SoftwareSerial.h>
TinyGPS gps; // create a TinyGPS object
#define pin13 13
SoftwareSerial myLCD(4,7); // RX, TX
void setup() {
Serial.begin(4800); // GPS device operates at 4800 baud
pinMode(pin13, OUTPUT);
digitalWrite(pin13, LOW); // turn off LED to start
myLCD.begin(9600);
delay(800);
clearScreen();
myLCD.print("Wait...");
}
void loop() {
while (Serial.available()) {
int c = Serial.read();
if (gps.encode(c)) {
float lat, lon;
gps.f_get_position(&lat, &lon);
if (lat>18 && lat<19) // that's where I live...
digitalWrite(pin13, HIGH);
else
digitalWrite(pin13, LOW);
clearScreen();
myLCD.write(0xFE); // command flag
myLCD.write(128); // write to line 1
//delay(10);
//myLCD.print("La = ");
myLCD.print(lat, DEC);
myLCD.write(0xFE); // command flag
myLCD.write(192); // write to line 2
//delay(10);
//myLCD.print("Lo = ");
myLCD.print(lon, DEC);
}
}
}
void clearScreen() {
myLCD.write(0xFE);
myLCD.write(0x01);
}
/////////////////////////////////////////////////////////
I only had one problem - When I try to print the line "La = ", I get garbage on the serial lcd (instead of the string "La = ") though the rest of the output is fine. Don't know why that happens???
Ravi