#include <SoftwareSerial.h>
SoftwareSerial ser(3,8);
void setup() {
Serial.begin(9600);
ser.begin(9600);
}
void loop() {
static int i = 0;
while (ser.available()) {
char ch = ser.read();
Serial.print(ch);
ser.print(ch);
}
}
If I comment out the "ser.print(ch);" line, all works as I would expect, and the incoming serial data from my sensor is printed correctly to the Serial Monitor.
If I uncomment that line, the data that's written to the Serial Monitor becomes gibberish.
I can't think of any other changes. It replicates each time I do it:
Comment out the line --> good data
Uncomment the line --> bad data
I'm new to Arduino, so maybe I'm missing something basic, but that seems like a highly odd side effect. Why would that line alter what happens above it?
As I recall, doing writes (prints) with software serial turns interrupts off. With interrupts off, incoming data might be missed. Why are you sending data back to the sensor?