Hi guys,
Need your help on this problem. I have an Arduino Mega 2560 with the following code below:
byte incomingByte;
void setup() {
Serial1.begin(9600);
}
void loop() {
while (!Serial1.available());
incomingByte = Serial1.read();
Serial1.write(incomingByte);
}
I open 'Serial Monitor' and type some string to the textbox. The problem is I get a random characters in return. I have a UART-USB Converter from FTDI (USB-RS232-WE-1800-BT_5.0) which is connected directly to Serial1 pins (18 and 19) of Arduino. I've tested the same code on Serial0 (replacing 'Serial1' to 'Serial' of course) without any problems. Do you guys have any idea what's causing this problem? Appreciate your help, thanks.
Hi, did you connected the pins the right way?
GND with GND;
TX of USB2SERIAL with RX of the MEGA;
RX of USB2SERIAL with TX of the MEGA;
In any case 2 observations:
- This forum is dedicated to the Arduino 101 board so this is not the right place to post this;
- I suggest you to replace the code in the loop with:
void loop() {
if(Serial1.available()){
incomingByte = Serial1.read();
Serial1.write(incomingByte);
}
}
Unless there is something connected to the pin you are measuring or you specify differently the pin will "float" and give spurious values.
Its easy to show if you have IDE 1.6.12 by using the AnalogSerial example and then opening serial plotter in the IDE. next try it with something attached to the pin and it will output a set data stream that would would expect.
a_guadalupi give you a superb answer.
And I dont think I was an AVR / Mega / UNO/ Mini etc. specific section in "products"