# Sending Serial Data Over FTDI causes loop

I'm trying to send and receive serial data from an atmega328 (using the arduino library) over an FTDI (FT232R) chip. I can send data to my pc and view it in a serial monitor. I can send data from my pc and flash an LED. But, if I try to send data from my pc and return a "received data x..." over serial it creates a loop of echos.

The following code is from the arduino site

String inputString = "";         // a string to hold incoming data
boolean stringComplete = false;

void serialEvent() {
while (Serial.available()) {
// get the new byte:
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}

void loop() {
// print the string when a newline arrives:
if (stringComplete) {
Serial.println(inputString);
// clear the string:
inputString = "";
stringComplete = false;
}
}


When I send "hello" I get back:

he

l

o

he

ll

o

he

ll

o

he

ll

o

he

ll

o

he

ll

o

he

l

o

...

And it goes on forever.

In case it's a hardware issue, here is my schematic.

What is causing the loop-back and how can I go about fixing it?

• Try checking power pins - if no VCC, or if the PC ground is not board ground, the whole thing floats and PC Rx will float up and down with Tx, causing your symptom. – John Birckhead Jun 19 '17 at 22:19
• Hmm.. Interesting. Gnd is connected. And I'm not using vcc from usb, but powering it from an ac/dc adapter. But looking at the ftdi datasheet, maybe I needed to connect vbus to the reset pin with a couple resistors? ftdichip.com/Support/Documents/DataSheets/ICs/DS_FT232R.pdf (Section 6.2) – bwoogie Jun 20 '17 at 0:04
• If you have a scope, get on the TXD pin with respect to your PC ground and make sure it is quiet when the PC is sending. If using a laptop, it may or may not be floating with respect to earth with the charger plugged in, and is certainly floating if not plugged in, so you will have to pick up ground from the laptop itself. – John Birckhead Jun 20 '17 at 3:35
• Are those the exact results? Sometimes, an 'L' is missing? The broken "hello" prints endlessly after your first transmit? Have you tried replacing the String with a C string? – SoreDakeNoKoto Jun 20 '17 at 19:28
• Yes, those are the exact results, except there are a few new lines separating the "hellos". I haven't tried a C string.. – bwoogie Jun 20 '17 at 23:34