2012 1 arduino_rs232
Upcoming SlideShare
Loading in...5
×
 

2012 1 arduino_rs232

on

  • 352 views

Presentation for Desert Code Camp 2012.1

Presentation for Desert Code Camp 2012.1

Statistics

Views

Total Views
352
Views on SlideShare
352
Embed Views
0

Actions

Likes
0
Downloads
8
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

2012 1 arduino_rs232 2012 1 arduino_rs232 Presentation Transcript

  • Implementing RS-232 Serial PortsOn An ArduinoDESERT CODE CAMP 2012.1 Presented by Don Doerres Embedded Pro Guy don@azlaborlaw.com
  • 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
  • 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
  • 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
  • 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‘
  • 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
  • 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
  • ANOTHER VIEW OF THE SAME THING Here we show both the bit stream and the Arduino voltage levels
  • 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
  • ANOTHER VIEW OF THE SAME THING This time RS232 A ‗1‘ is -12V A ‗0‘ is +12V
  • SO HOW DO WE GET FROM LOW LEVEL TORS232? We need a hardware level translator This one is a Sparkfun PRT-00449
  • HOW TO HOOK TO ARDUINO Note the signal arrows between the adapter and the Arduino
  • TEST CODE INCLUDES AND DEFINES#include <SoftwareSerial.h>#define INSOFT1 7#define OUTSOFT1 8int incomingByte = 0;SoftwareSerial SWSerial(INSOFT1, OUTSOFT1);
  • TEST CODE SETUPvoid setup(){Serial.begin(9600);SWSerial.begin(9600);}
  • 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); }}
  • SCREEN CAPTURES
  • SCREEN CAPTURES
  • MORE STUFF… Q: How do I hook up right? A: Use an RS232 Analyzer and adapters
  • HOOK TO THE MAIN COMPUTER The TD light should light Note TD and DTR, may light for a more advanced connection
  • 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
  • HOOK TOGETHER The ideal outcome – all the lights!
  • FIXING IT Sometimes you need a NULL adapter on one side
  • 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
  • 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)
  • 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
  • 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