Hi. I am trying to design a project which interfaces an arduino to a GPS, and sends this data to an LCD. Both the GPS module and the LCD have Serial ports, so I just need to connect each to a serial port on the arduino. To do this, I understand I have to use the SoftwareSerial() function to create serial ports for both the LCD and the GPS. I can get my arduino to interface with each of these devices one at a time. But when I try to get them both talking to the arduino at the same time, my the data coming in from the GPS is all jumbled.
To be clear, my the GPS is only SENDING (TX) data to the arduino, and the LCD is only RECEIVING (RX) data from the arduino, so the arduino isn't receiving data from 2 ports ( I understand that is a limitation of SoftwareSerial)
My sketch looks like this:
#include <SoftwareSerial.h>
#define txPin 4
SoftwareSerial GPS(2, 3);
SoftwareSerial LCD(0, txPin);
// different commands to set the update rate from once a second (1 Hz) to 10 times a second (10Hz)
#define PMTK_SET_NMEA_UPDATE_1HZ "$PMTK220,1000*1F"
#define PMTK_SET_NMEA_UPDATE_5HZ "$PMTK220,200*2C"
#define PMTK_SET_NMEA_UPDATE_10HZ "$PMTK220,100*2F"
// turn on only the second sentence (GPRMC)
#define PMTK_SET_NMEA_OUTPUT_RMCONLY "$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"
// turn on ALL THE DATA
#define PMTK_SET_NMEA_OUTPUT_ALLDATA "$PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
void setup()
{
Serial.begin(57600);
Serial.println("Adafruit MTK3329 NMEA test!");
LCD.begin(9600);
// 9600 NMEA is the default baud rate
GPS.begin(9600);
// uncomment this line to turn on only the "minimum recommended" data for high update rates!
GPS.println(PMTK_SET_NMEA_OUTPUT_RMCONLY);
// 1 Hz update rate
GPS.println(PMTK_SET_NMEA_UPDATE_1HZ);
}
void loop() // run over and over again
{
LCD.print("hi");
if (GPS.available()) {
Serial.print((char)GPS.read());
}
}
GPS is the serial for the GPS
LCD is the serial for the LCD
In this program, for now I just want the GPS serial to display on the Serial Monitor for my PC while the LCD constantly prints "hi"
Again, if I delete the LCD.print() in the loop, the GPS works perfectly fine
When the LCD.print() is in the loop, the Serial monitor is all jumbled.
Thanks