Hi, I have a terribly aggravating problem. When I use this code...
void setup() {
Serial.begin(115200);
Serial.println("System Started.");
}
void loop() {
while (Serial.available() > 0) {
char a = Serial.read();
Serial.print(a);
}
}
while having my Arduino plugged into the PC and open the serial monitor it works fine. It prints back everything that I sent over the serial connection. If I power it externally 5 volts and connect with a USB to serial converter to the hardware serial (pins 0, 1) it does not talk back. It prints the "System Started." but the Serial.available() never goes true if I transmit to it. I have tried it on Mega 2560, Uno, and some China clone Mega board. I have used a USB to serial converter, tried using a UNO board with processor removed as a serial converter, so that part works fine. I have used Arduino IDE on Windows 10 and on Raspian same results.
Thanks in advance.
void setup() {
Serial.begin(115200);
Serial.println("System Started.");
}
void loop() {
if (Serial.available() > 0) {
char a = Serial.read();
Serial.print(a);
}
}
I would toggle a LED when you receive data so you can see if you actually receive something. Something in the line of (base on IEEE488's code):
const byte ledPin = LED_BUILTIN;
byte ledState = HIGH;
void setup()
{
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, ledState);
Serial.println("System Started.");
}
void loop()
{
if (Serial.available() > 0)
{
ledState = !ledState;
digitalWrite(ledPin, ledState);
// optional delay for testing
delay(1000);
char a = Serial.read();
Serial.print(a);
}
}
Thanks for the replies.
But has none of you experienced that problem? There is no more explaining needed because my first post said it all.
I would toggle a LED when you receive data so you can see if you actually receive something.
Yes, I have done that and it never turned on.
I will take another shot at it later this week. See what results I get this time.
edgar_wideman:
But has none of you experienced that problem?
Probably not. Are you trying to talk to Arduino with the serial monitor connected to hardware serial pins 0,1?