Serial Confusion

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Serial Confusion

Postby pictiPig » Mon Sep 08, 2008 5:31 am

Hi, I'm new to the Arduino and to Micro-controllers in general (although fairly experienced with code), so I'm at the bottom of my learning curve.

I'm trying to pass serial data from an Arduino to my PC, but the data is arriving scrambled in Docklight. I've obviously missed something important.

I'm connecting Pins 0/1 (Rx/Tx) and ground from the Arduino to the serial cable (pins 2,3 & 5), and using Serial.print. Baud rates are both 9600 (I've tested most other options too), 8,1,N on the receiver (again, I think I must have tried every combination!). I get the same results in Hyperterminal, Docklight or my own Serial monitor I wrote a while ago - I've tried several different Arduino Boards, all give the same results :

Sending integers 0 - 6 Serial.print(0);Serial.print(1)... receives : D6 B6 96 76 56 36 56 EB 00

Sending ASCII Serial.println("abcdefg") : 4F A7 BA AA 9A 8A 2A EB 00.


Results are identical over different boards/wires/bauds etc, so I think I can discount dodgy hardware.

If I send via the USB, everything works fine. What am I doing wrong?

Any help would be greatly appreciated!


Scott
User avatar
pictiPig
 
Posts: 8
Joined: Mon Jul 07, 2008 11:50 am
Location: Scotland

Postby mtbf0 » Mon Sep 08, 2008 6:31 am

do you have an rs-232 level converter between the arduino and your pc. if not, say a little prayer of thanks to the guys at atmel for sending you a chip that could survive the abuse you've given it. the signal levels coming out of your pc a likely to be way out of spec for your poor little mega168. and who knows what's going to happen when the pc's tx line goes negative. your arduino really doesn't want to see anyhing outside the range of 0-5 volts.

iff, that's ok, consider the following.

are you using a null modem cable? if not, do, or swap rx and tx at the arduino. if so, uh, don't know.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1642
Joined: Fri Nov 09, 2007 11:59 pm
Location: oakland ca

Postby pictiPig » Mon Sep 08, 2008 7:45 am

Thanks for the reply mtbf0, and a special thanks to the guys at atmel - since I've just plugged the wires directly into my pc... Can you suggest a good level converter?

I already tried swapping rx and tx to see if it was a null modem type problem, so I'm fairly sure it's not that.

Could it be that the signal is too high (voltage wise) for the mega168, causing it to misinterpret the values? They are consistent over different hardware setups - which is what I find most bizarre.

Anyway, I'll wait until I'm sending a proper voltage before I try anything else.

Thanks again.


Scott
User avatar
pictiPig
 
Posts: 8
Joined: Mon Jul 07, 2008 11:50 am
Location: Scotland

Postby mtbf0 » Mon Sep 08, 2008 8:03 am

you could be getting voltages like +/-15. a max232 or similar and a handful of small caps. i think there's something like a max233 that doesn't require the caps. costs a little more, though. if you're more clever than me you can build one up from discrete components.

there's a board called a p4 that you can get from modern devices or the maker shed.

similar things can be had from sprkfun or acroname.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1642
Joined: Fri Nov 09, 2007 11:59 pm
Location: oakland ca

Postby pictiPig » Mon Sep 08, 2008 8:52 am

Thanks again for the info, I just ordered one of these : http://www.nkcelectronics.com/rs232-to- ... 32356.html

Which looks like It'll do what I need. (I'm too scared to try and build one myself! - yet!!)

I'll abandon this project until I get my converter, then pop back on here to give you all closure :-)

Thanks again,


Scott
User avatar
pictiPig
 
Posts: 8
Joined: Mon Jul 07, 2008 11:50 am
Location: Scotland

Postby lou » Mon Sep 08, 2008 9:36 am

pictiPig wrote:Could it be that the signal is too high (voltage wise) for the mega168, causing it to misinterpret the values? They are consistent over different hardware setups - which is what I find most bizarre.


Misinterpret? No. However, the levels, besides having different voltages, are also inverted.
If you lucked out and didn't burn out your RxD pin (and, since you tried a null modem cable, your TxD pin, as well), the chip would still have been reading ones as zeroes and zeroes as ones, and that includes things like start/stop bits.

One of the things that RS-232 level shifter circuits do is to deal with that inversion.
lou
 
Posts: 91
Joined: Fri Jul 11, 2008 8:39 am

Postby pictiPig » Mon Sep 08, 2008 10:58 am

I actually thought of trying to invert the binary to see if I could make sense of the output. The hacker in me won't let a mystery like that alone. I did try different stop bit settings but I didn't manage to discover a way of converting what I got into what I should have got. A straight mapping would be cheating!

I have a few Arduino's here so I think I'll connect two together to see if I can pass data from one to the other. That should prove whether I have burned my pins out or not at least. I'm glad I decided to buy several boards now <grin>.

Well, lots learned today. Thanks again everyone!


Scott
User avatar
pictiPig
 
Posts: 8
Joined: Mon Jul 07, 2008 11:50 am
Location: Scotland

Postby adafruit » Mon Sep 08, 2008 4:26 pm

User avatar
adafruit
 
Posts: 10485
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Postby pictiPig » Mon Sep 08, 2008 5:38 pm

Thanks for the Tutorial link ladyada, just what I was needing.

I'm really enjoying learning all this circuit stuff. I've been interfacing with rs232 for decades but never given much of a thought to what was happening on the other end of my 9 pins. If my software pals could see me now!



Scott
User avatar
pictiPig
 
Posts: 8
Joined: Mon Jul 07, 2008 11:50 am
Location: Scotland


Return to Arduino

Who is online

Users browsing this forum: No registered users and 15 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [100]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[108]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[69]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]