using Serialx (Serial1, Serial2, Serial3) connected to PC produces Garbage

I am attempting to communicate with my PC using one of the Serialx (Serial1, Serial2, Serial3) ports with very little success. The output on the PC is garbage.

I have tested both Serial1 and Serial3 with the same problems. I have atmega2560 and using a “USB to serial” cable converter. Following is my sketch:

void setup() {
Serial1.begin(9600);
}
void loop(){
// repeat writing “abc” 3 times
for(int i=0;i<3;i++) {
Serial1.write(61);
Serial1.write(62);
Serial1.write(63);
}

delay(200);
}

the output displayed in hex:

61 B0 60 61 B0 60 61 B0 60

Notice the only letter that is correct is the first one, the letter little ‘a’.
I have also tried Serial1.print() which produces the same results.
I have tried various Windows Device Manager and Putty port configuration settings. Different settings create different results, all incorrect. The test above is using 9600/8/N/1 and Flow Control: NONE

I am creating the hex view by cut/paste from the Putty terminal/window into a binary editor (MS Visual Studio).

Questions:

  1. Has anyone successfully communicated with the PC using the Serialx ports?
  2. What should the Windows Device Manager and Putty port settings be?
  3. Can you control/set the prort settings in the Arduino sketch, and if so, how?

thanks, JL

How are you doing the serial level conversion and inversion before connecting to the USB device?

AWOL: don't understand what you mean by "...doing the serial level conversion and inversion before connecting to the USB device?..."

thanks for your quick response.

the output displayed in hex:

Which version of the IDE are you using V1.0?

61 (decimal) is not the lower case letter 'a'. It is the equals sign '='. 62 is > and 63 is ? If you want lower case a, b and c you need to use 0x61, 0x62 and 0x63.

Pete

I am using Arduino 1.0 IDE.

You are correct about the character values. I have tried the (decimal) values 97, 98 and 99 as well as 0x61, 0x62 and 0x63 which produce the following hex values on the PC:

4F A7 4E.....repeated forever

As you pointed out, when sending the (decimal) values 61, 62 and 62, I should have received =>? which are the hex values: 0x3D, 0x3E and 0x3F, but as you can see, I did not get these values.

You cannot simply connect TTL level serial lines to an RS232 serial converter and expect sensible results. a) The signals are inverted b) the signals are level-shifted.

You need something like a MAX232 to do the conversion for you.

thank you AWOL. if I am understanding you correctly, I will need the following:

  1. from the atmega2560 board, I would connect the TX/TX/GND ports to a TTL converter (like the MAX232)
  2. the MAX232 would be connected to my USB-to-RS232 cable converter
  3. the USB-to-RS232 cable converter would plug into my PC in a USB port.

or, are there devices that convert the TTL signals to USB directly?

On the parallax site they have a schematic of a simple RX/TX adapter to go to /from TTL to RS232 I built one for programming my basic stamp.

What is the spec on your "USB to serial" cable converter? It's likely that the cable already has the electronics for the level conversion built into it.

jlb1: or, are there devices that convert the TTL signals to USB directly?

Arduino clones that don't include a USB port are usually programmed via the SPI, aren't they? There is a common interface you can get that connects to the SPI and provides a USB interface. Perhaps you could use one of these instead of going via RS232?