Upcoming SlideShare
×

# 2012 1 arduino_rs232

422 views
354 views

Published on

Presentation for Desert Code Camp 2012.1

Published in: Technology
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
422
On SlideShare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
11
0
Likes
0
Embeds 0
No embeds

No notes for slide

### 2012 1 arduino_rs232

1. 1. Implementing RS-232 Serial PortsOn An ArduinoDESERT CODE CAMP 2012.1 Presented by Don Doerres Embedded Pro Guy don@azlaborlaw.com
2. 2. TODAY’S TAKEAWAYS The Arduino has a ―Low Level‖ serial connection; many electronic devices have higher voltage serial connections called RS- 232 This class will explain  The basics of the serial connection  What the low and high level signals look like  How to convert between the types of signals  Some generalized RS-232 interfacing suggestions
3. 3. LET’S PICK A CHARACTER FOR AN EXAMPLE Let‘s use capital ‗C‘ for Code Camp Look this up on an ANSI Chart Dec: 67, Hex:43, Binary, 8 bits: 01000011
4. 4. THE BASIC SERIAL PROTOCOL 1 The bits of the characters come one at a time, through a single wire. The wire ―idles‖ at a ‗1‘ level to show that it is alive The bits come out low order bit first We will program for bytes of 8 bits each
5. 5. THE BASIC SERIAL PROTOCOL 2 We know the wire is alive because it idles at ‗1‘, the higher voltage level We know in advance how fast bits will be coming out of the wire; this is called the ―baud rate‖ So, our Arduino is sampling the incoming wire for a transition from ‗1‘ to a ‗0‘
6. 6. THE BASIC SERIAL PROTOCOL 3 So now we have one start bit This will be followed by 8 bits of the byte And, to keep this straight, we will have 1 extra bit of 1 at the end of the string of bits to guarantee that a ‗1‘ to ‗0‘ transition can take place to indicate the start of a next byte
7. 7. PUTTING IT ALL TOGETHER 1 Start Bit, 8 data bits, 1 Stop bit The bits of the byte come out low order bit first in time So we will have this string of 10 bits, with gray showing the state of the wire before and after the byte: …1 1 1 1 0 1 1 0 0 0 0 1 0 1 1 1 1 1… Time
8. 8. ANOTHER VIEW OF THE SAME THING Here we show both the bit stream and the Arduino voltage levels
9. 9. NOW RS232 On the Arduino, the serial line swings between 0 and 5 volts (some are 0 to 3.3V) RS-232 is an older protocol A ‗1‘ is -12V  A ‗0‘ is +12V Don‘t even think about connecting the Arduino directly to this…please
10. 10. ANOTHER VIEW OF THE SAME THING This time RS232 A ‗1‘ is -12V A ‗0‘ is +12V
11. 11. SO HOW DO WE GET FROM LOW LEVEL TORS232? We need a hardware level translator This one is a Sparkfun PRT-00449
12. 12. HOW TO HOOK TO ARDUINO Note the signal arrows between the adapter and the Arduino
13. 13. TEST CODE INCLUDES AND DEFINES#include <SoftwareSerial.h>#define INSOFT1 7#define OUTSOFT1 8int incomingByte = 0;SoftwareSerial SWSerial(INSOFT1, OUTSOFT1);
14. 14. TEST CODE SETUPvoid setup(){Serial.begin(9600);SWSerial.begin(9600);}
15. 15. TEST CODE LOOPvoid loop(){while (Serial.available() > 0) { incomingByte = Serial.read(); SWSerial.print((char)incomingByte); }while (SWSerial.available() > 0) { incomingByte = SWSerial.read(); Serial.print((char)incomingByte); }}
16. 16. SCREEN CAPTURES
17. 17. SCREEN CAPTURES
18. 18. MORE STUFF… Q: How do I hook up right? A: Use an RS232 Analyzer and adapters
19. 19. HOOK TO THE MAIN COMPUTER The TD light should light Note TD and DTR, may light for a more advanced connection
20. 20. HOOK TO THE TARGET The RD light should light Sometimes Target powered from the host, and there will be no lights—or the target is off! Note possible:  CD  CTS  DSR
21. 21. HOOK TOGETHER The ideal outcome – all the lights!
22. 22. FIXING IT Sometimes you need a NULL adapter on one side
23. 23. IF YOU DO THIS A BIT… Invest in some adapters These are a long term investment I bought the first of mine 30 years ago…they wear well
24. 24. SOURCE FOR RS232 GEAR These companies offer different adapters over time  Radio Shack (www.radioshack.com)  Frys Electronics (www.frys.com) This company is more expensive, but has a huge variety in stock at all times  Black Box (www.blackbox.com)
25. 25. RS232 TO LOW LEVEL ADAPTER Sparkfun has two different ones  PRT-00133 (\$6.95) is a through hole kit  PRT-00449 (\$13.95) is surface mount and is pre- built www.sparkfun.com
26. 26. QUESTIONS? Find more slides from Don at www.slideshare.net/dondoerres The Arduino code shown came be downloaded from https://github.com/dondoerres/drdCodeCamp2012. 1