SlideShare a Scribd company logo
1 of 26
Implementing RS-232 Serial Ports
On An Arduino

DESERT 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 TO
RS232?
 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 8

int incomingByte = 0;
SoftwareSerial SWSerial(INSOFT1, OUTSOFT1);
TEST CODE SETUP
void setup()
{
Serial.begin(9600);
SWSerial.begin(9600);
}
TEST CODE LOOP
void 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

More Related Content

What's hot (17)

Kramer VS-611
Kramer VS-611Kramer VS-611
Kramer VS-611
 
Kramer VS-1001-XLM
Kramer VS-1001-XLMKramer VS-1001-XLM
Kramer VS-1001-XLM
 
Kramer 401Dxl
Kramer 401DxlKramer 401Dxl
Kramer 401Dxl
 
Kramer VS-601-XLM
Kramer VS-601-XLMKramer VS-601-XLM
Kramer VS-601-XLM
 
Kramer VS-1201XL
Kramer VS-1201XLKramer VS-1201XL
Kramer VS-1201XL
 
Not gate
Not gateNot gate
Not gate
 
Building light automation (1)
Building light automation (1)Building light automation (1)
Building light automation (1)
 
Kramer VM-9T
Kramer VM-9TKramer VM-9T
Kramer VM-9T
 
Kramer VS-1011
Kramer VS-1011Kramer VS-1011
Kramer VS-1011
 
transistor transistor logic
transistor transistor logictransistor transistor logic
transistor transistor logic
 
jiby
jibyjiby
jiby
 
Vs 81 h-dxl
Vs 81 h-dxlVs 81 h-dxl
Vs 81 h-dxl
 
Kramer VS-81-HDXL
Kramer VS-81-HDXLKramer VS-81-HDXL
Kramer VS-81-HDXL
 
SFP(FT-901B-S-LC20)_DataSheet_ver_1.1
SFP(FT-901B-S-LC20)_DataSheet_ver_1.1SFP(FT-901B-S-LC20)_DataSheet_ver_1.1
SFP(FT-901B-S-LC20)_DataSheet_ver_1.1
 
Franklin oscillator
Franklin oscillatorFranklin oscillator
Franklin oscillator
 
Hw4
Hw4Hw4
Hw4
 
Kramer VM-312
Kramer VM-312Kramer VM-312
Kramer VM-312
 

Similar to 2012 1 arduino_rs232

Arduino Workshop (3).pptx
Arduino Workshop (3).pptxArduino Workshop (3).pptx
Arduino Workshop (3).pptx
HebaEng
 
Arduino spooky projects_class3
Arduino spooky projects_class3Arduino spooky projects_class3
Arduino spooky projects_class3
Anil Yadav
 

Similar to 2012 1 arduino_rs232 (20)

I2c interfacing raspberry pi to arduino
I2c interfacing raspberry pi to arduinoI2c interfacing raspberry pi to arduino
I2c interfacing raspberry pi to arduino
 
Embedded system course projects - Arduino Course
Embedded system course projects - Arduino CourseEmbedded system course projects - Arduino Course
Embedded system course projects - Arduino Course
 
Arduino Workshop (3).pptx
Arduino Workshop (3).pptxArduino Workshop (3).pptx
Arduino Workshop (3).pptx
 
Physical prototyping lab3-serious_serial
Physical prototyping lab3-serious_serialPhysical prototyping lab3-serious_serial
Physical prototyping lab3-serious_serial
 
publish manual
publish manualpublish manual
publish manual
 
Arduino Workshop
Arduino WorkshopArduino Workshop
Arduino Workshop
 
Logic Gates & Family.pdf
Logic Gates & Family.pdfLogic Gates & Family.pdf
Logic Gates & Family.pdf
 
Intro_to_Arduino_-_v30.pptx
Intro_to_Arduino_-_v30.pptxIntro_to_Arduino_-_v30.pptx
Intro_to_Arduino_-_v30.pptx
 
Arduino windows remote control
Arduino windows remote controlArduino windows remote control
Arduino windows remote control
 
Fun with arduino
Fun with arduinoFun with arduino
Fun with arduino
 
Arduino spooky projects_class3
Arduino spooky projects_class3Arduino spooky projects_class3
Arduino spooky projects_class3
 
ARDUINO (1).pdf
ARDUINO (1).pdfARDUINO (1).pdf
ARDUINO (1).pdf
 
Smart Blind stick by using arduino uno and sensor
 Smart Blind stick  by using arduino  uno  and sensor Smart Blind stick  by using arduino  uno  and sensor
Smart Blind stick by using arduino uno and sensor
 
Measurements upload
Measurements uploadMeasurements upload
Measurements upload
 
Arduino Slides With Neopixels
Arduino Slides With NeopixelsArduino Slides With Neopixels
Arduino Slides With Neopixels
 
Introduction to Arduino 16822775 (2).ppt
Introduction to Arduino 16822775 (2).pptIntroduction to Arduino 16822775 (2).ppt
Introduction to Arduino 16822775 (2).ppt
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digital
 
Arduino projects &amp; tutorials
Arduino projects &amp; tutorialsArduino projects &amp; tutorials
Arduino projects &amp; tutorials
 
Micro c lab8(serial communication)
Micro c lab8(serial communication)Micro c lab8(serial communication)
Micro c lab8(serial communication)
 
Arduino Meetup with Sonar and 433Mhz Radios
Arduino Meetup with Sonar and 433Mhz RadiosArduino Meetup with Sonar and 433Mhz Radios
Arduino Meetup with Sonar and 433Mhz Radios
 

More from Don Doerres (10)

2018 03 28_near_scifi
2018 03 28_near_scifi2018 03 28_near_scifi
2018 03 28_near_scifi
 
2018LifeOnOtherWorldsl
2018LifeOnOtherWorldsl2018LifeOnOtherWorldsl
2018LifeOnOtherWorldsl
 
2018 tamid sshw
2018 tamid sshw2018 tamid sshw
2018 tamid sshw
 
2018_03_15_life_on_otherworlds
2018_03_15_life_on_otherworlds2018_03_15_life_on_otherworlds
2018_03_15_life_on_otherworlds
 
2017 aacr youth day
2017 aacr youth day2017 aacr youth day
2017 aacr youth day
 
Presentation desert codecamp_2017_1_sonichandkerchief
Presentation desert codecamp_2017_1_sonichandkerchiefPresentation desert codecamp_2017_1_sonichandkerchief
Presentation desert codecamp_2017_1_sonichandkerchief
 
2013 1 arduino_datalogger
2013 1 arduino_datalogger2013 1 arduino_datalogger
2013 1 arduino_datalogger
 
Rasberry pi class
Rasberry pi classRasberry pi class
Rasberry pi class
 
Raspberry pi lnl
Raspberry pi lnlRaspberry pi lnl
Raspberry pi lnl
 
Single Boards Overview
Single Boards OverviewSingle Boards Overview
Single Boards Overview
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 

2012 1 arduino_rs232

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