Simple serial parsing

Hi everyone, I’m new to this Arduino platform, and excited to try things out, but having some trouble with what should be simple serial communications. I’ve pulled out some code from a larger project to try and understand a bug and replicate it. Eventually, I will be sending data from various structures on the Arduino to a Python parser, but I can’t seem to even transmit single correct bytes…

Arduino Code::

void setup() {
  Serial3.begin(57600);
}

void loop() {
  for (byte i = 0; i < 10; ++i){
    Serial3.write(i);
  }
  
  delay(5000); 
}

Python Code::

from serial import Serial

COM = Serial(port = "COM6", baudrate = 57600)
bytesAvail = 0;
serial_data = ''

while (1):	
	bytesAvail = COM.inWaiting()
	if (bytesAvail):
		serial_data = COM.read(bytesAvail)		
		out_str = ''
		for ch in serial_data:
			out_str += "%02X " % ord(ch)
		print out_str

Now I should be getting parsed numbers from 0 - 9, something like 01 02 03 … etc
But I’m actually getting this stream: FD FB F9 F7 F5 F3 F1 EF ED 00

Do I need to configure the serial port differently, or is it possible I have a hardware issue?

I’m getting the data back in Python by connecting pins 2,3, and 7 on a db9 connector to serial3tx, rx, and gnd and to a simple usb-serial dongle (that’s COM6).

Any thoughts would be much appreciated.

Serial3.write(i);

"write" send the binary value, not the ASCii. Try "print"

I want to send binary data.

OK This:

But I'm actually getting this stream: FD FB F9 F7 F5 F3 F1 EF ED 00

looks suspiciously like an inversion.

I'm getting the data back in Python by connecting pins 2,3, and 7 on a db9 connector

and what is driving the appropriate levels?

I'm using a Belkin USB-Serial converter, but I assumed that the levels were being driven by the board.. I scoped the transmit pin and it looks fine.

but I assumed that the levels were being driven by the board

Hmm.

I scoped the transmit pin and it looks fine.

I think you need to define "fine"

Groove:

but I assumed that the levels were being driven by the board

Hmm.

I scoped the transmit pin and it looks fine.

I think you need to define "fine"

The edges are clean, rise time looks fine, dead on at 5volts.. I don't know, looks like a clean rs232 signal to me.

If I just do Serial.write(99), and connect the output to a putty terminal, I get "N" which is not right.. so I am leaning towards it being a hardware issue.

I don't know, looks like a clean rs232 signal to me.

Have you ever actually looked at an RS232 signal?

yes

cj_moore:

Groove:

but I assumed that the levels were being driven by the board

Hmm.

I scoped the transmit pin and it looks fine.

I think you need to define "fine"

The edges are clean, rise time looks fine, dead on at 5volts.. I don't know, looks like a clean rs232 signal to me.

If I just do Serial.write(99), and connect the output to a putty terminal, I get "N" which is not right.. so I am leaning towards it being a hardware issue.

http://www.sparkfun.com/tutorials/215

It most certainly is a hardware issue. Arduino cannot drive Rs-232 by itself. Why are you doing it that way anyway? Why not use arduino's built in usb-serial?

cj_moore: yes

Then you know that RS-232 uses bipolar voltage signal lines, a space is a positive voltage (3-15vdc) and a mark is a negative voltage (-3 to -15vdc)? As an Arduino uses single polarity TTL voltage levels (0 or +5v) you have a serious mismatch wiring directly to arduino pins. Negative voltages can be death to input pins on the Arduino and positive voltages above +5vdc are also death, but it sounds like your USB/RS-232 conveter limits it's positive voltage to +5vdc. You also have a logic inversion between what polarity a one bit is in rs-232 Vs TTL.

So you need to use a USB to TTL serial converter, which by the way you already have built into your Arduino board. Have you not seen the serial monitor feature inside the Arduino IDE, it allows serial communications between your arduino and the PC's comm port assigned to the arduino board? It's the same path as the Arduino IDE uses to upload sketches to your board.

So any PC application software that can talk to a comm port can be made to communicate with your Arduino, you don't need a separate comm port or USB serial converter.

Lefty