I'm trying to read serial data from a GPS. That effort has devolved into just trying to do a serial echo test, and the serial echo tests have been unsuccessful.
I can see the serial data stream on my oscilloscope coming from the GPS, but the Arduino can't read the data. After changing GPS units and Arduino (Uno) units, I tried something much simpler: just a serial echo.
I've read many posts about problems with SoftwareSerial and with AltSoftwareSerial, but none of them have helped me solve my problem. Both the SoftwareSerial and the AltSoftwareSerial seem to produce garbage characters coming in to the Arduino. I've checked baud rates and delay times, and I still get garbage. I'll show you the actual readings appended to my code sample later in this plaintive cry for help.
The latest iteration is using the AltSoftwareSerial echo test code available online.
Arduino Uno, Pin 0 (hardware Rx) jumpered to Pin 9; Pin 1 (hardware Tx).
Here's the code, with the result appended in a Comment:
// NOTE: This AltSoftSerial REQUIRES that Pin 9 be the Tx Pin and Pin 8 be the Rx Pin
// Connect Arduino Uno Pin 0 (Rx) to Pin 9 (Tx), and connect Arduino Uno Pin 1 (Tx) to Pin 8 (Rx)
#include <AltSoftSerial.h>
AltSoftSerial altSerial;
void setup() {
Serial.begin(9600);
Serial.println("AltSoftSerial Test Begin");
altSerial.begin(9600);
delay(100);
altSerial.println("Hello World");
}
void loop() {
char c;
if (Serial.available()) {
c = Serial.read();
altSerial.print(c);
}
delay(200
); //This makes the looping go very slowly
if (altSerial.available()) {
c = altSerial.read();
Serial.print(c);
}
}
// RESULTS:
/*
AltSoftSerial Test Begin
±ÑM½™ÑM•É¥…±�Test Begin
±ÑM½™ÑM•É¥…±�Test Begin
±ÑM½™ÑM•É¥…±�Test Begin
±ÑM½™ÑM•É¥…±�Test Begin
±ÑM½™ÑM•É¥…±�Test Begin
±ÑM½™ÑM•É¥…±�Test Begin
±ÑM½™ÑM•É¥…±�Test Begin
So, looking online, I found a second echo program that I tried, and it gives an error because the data received doesn't match the data sent - again, I append the output from the Serial Monitor as a Comment section at the end:
//
// Transmit data with Serial1 and try to receive
// it with AltSoftSerial. You must connect a wire
// from Serial1 TX to AltSoftSerial RX.
#include <AltSoftSerial.h>
AltSoftSerial altser;
const int mybaud = 9600;
// Board Serial1 TX AltSoftSerial RX
// ----- ---------- ----------------
// Teensy 3.x 1 20
// Teensy 2.0 8 (D3) 10 (C7)
// Teensy++ 2.0 3 (D3) 4 (D4)
// Arduino Leonardo 1 13
// Arduino Mega 18 48
// Serial1 on AVR @ 16 MHz minimum baud is 245
// Serial1 on Teensy 3.2 @ 96 MHz minimum baud is 733
byte sentbyte;
unsigned long prevmillis;
byte testbyte=0xF0;
void setup() {
delay(200);
Serial.begin(9600);
while (!Serial) ; // wait for Arduino Serial Monitor
Serial.begin(mybaud); // connect a wire from TX1
altser.begin(mybaud); // to AltSoftSerial RX
Serial.println("AltSoftSerial Receive Test");
prevmillis = millis();
}
void loop() {
// transmit a test byte on Serial
if (millis() - prevmillis > 250) {
sentbyte = testbyte++;
Serial.write(sentbyte);
prevmillis = millis();
}
// attempt to receive it by AltSoftSerial
if (altser.available() > 0) {
byte b = altser.read();
Serial.println(b);
if (b != sentbyte) Serial.println("***** ERROR *****");
while(1) { } // This stops the program if the error occurs.
}
}
/* RESULTS:
I know I have some very fundamental problem, and I appreciate your patience and indulgence and any insights you can provide. I'm definitely preparing myself to feel stupid. Thanks!