Hi,
I'm completely new to arduino, so I need some help with the serial ports.
I want to read data from gps with my arduino due.
So I need to communicate via serial ports with my computer and the gps-modul.
I found lots of code solving the Problem with the library: SoftwareSerial
But as I have read, there is no need (and also not working for the arduino due, i tried) for this library, because the due has 4 serial ports, which I can use.
Now my question: I managed to send and recieve data from my computer. But i can't recieve the Data from the gps-modul. How do I get the serial Input from the other ports?
This is my poor version =(
int rx1pin = 19; // gps-rx
int incomingByte = 0; // for incoming serial data
void setup() {
Serial.begin(9600); //serial PC
Serial1.begin(4800); //serial gps
pinMode(PPSPin, INPUT); // Initialize LED pin
Serial.println("Hello world!"); // prints hello with ending line break
}
void loop() {
// send data only when you receive data:
if (Serial1.available() > 0) {
// read the incoming byte:
incomingByte = Serial1.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
}
Well your suggestion works better than mine, but I have still problems with my Code.
First of all: When I compare your code with mine, you replaced in the if-statement Serial1.available() by Serial.available() and it worked.
So why doesn't Serial1.available() work, because I want the Signal from the gps?
Now the serial monitor just prints output, when I give him input from pc. But then he prints endless data
My second problem is, that I get output now, but the serial monitor prints nonsens.
By searching the web I found, that the Baud-rate (9600) has to match my code
Serial.begin(9600); //serial PC
Serial1.begin(9600); //serial gps
Serial Monitor is printing ?????????? endless.
I also updated my code a little.
Do I have to write this line for a rx port? pinMode(rx1pin, INPUT);
int rx1pin = 19; // gps-rx
int incomingByte = 0; // for incoming serial data
char gpsoutput;
const int sentenceSize = 80;
char sentence[sentenceSize];
void setup() {
Serial.begin(9600); //serial PC
Serial1.begin(9600); //serial gps
pinMode(rx1pin, INPUT);
// Serial.println("Hello world!"); // prints hello with ending line break
}
void loop() {
static int i = 0;
// send data only when you receive data:
if (Serial.available()>0)
{
gpsoutput=Serial1.read();
if (gpsoutput != '\n' && i < sentenceSize)
{
sentence[i] = gpsoutput;
i++;
}
else
{
sentence[i] = '\0';
i = 0;
}
Serial.write(sentence);
}
}
Endless garbage on the serial ports normally means you have the wrong baud rate (could be a problem with number of stop bits). Check you have the right settings for the GPS and the serial monitor.