Adding prints appears to change reads

I have the following sketch:

#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:

  1. Comment out the line --> good data
  2. 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?

Thanks!

What sensor? How is all this wired up?

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?

Or more specifically, What does the sensor do when you return it's output data as input data? confirm it?

Bob

OK, so that makes sense.

It's actually 2 sensors, one is a GPS (input) and one is a Bluetooth (output).

When I tried using 2 different SoftwareSerial objects, nothing worked at all.

I think I have an idea for how to get it to work.

Thanks for the answers/thoughts! I think they're really going to help!

I think I have an idea for how to get it to work.

Unless it involves different hardware, with multiple hardware serial ports, it won't work.