SlideShare une entreprise Scribd logo
1  sur  26
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances (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
 

Similaire à 2012 1 arduino_rs232

I2c interfacing raspberry pi to arduino
I2c interfacing raspberry pi to arduinoI2c interfacing raspberry pi to arduino
I2c interfacing raspberry pi to arduinoMike Ochtman
 
Embedded system course projects - Arduino Course
Embedded system course projects - Arduino CourseEmbedded system course projects - Arduino Course
Embedded system course projects - Arduino CourseElaf A.Saeed
 
Arduino Workshop (3).pptx
Arduino Workshop (3).pptxArduino Workshop (3).pptx
Arduino Workshop (3).pptxHebaEng
 
Physical prototyping lab3-serious_serial
Physical prototyping lab3-serious_serialPhysical prototyping lab3-serious_serial
Physical prototyping lab3-serious_serialTony Olsson.
 
Arduino Workshop
Arduino WorkshopArduino Workshop
Arduino Workshopatuline
 
Arduino windows remote control
Arduino windows remote controlArduino windows remote control
Arduino windows remote controlVilayatAli5
 
Arduino spooky projects_class3
Arduino spooky projects_class3Arduino spooky projects_class3
Arduino spooky projects_class3Anil Yadav
 
Arduino Slides With Neopixels
Arduino Slides With NeopixelsArduino Slides With Neopixels
Arduino Slides With Neopixelssdcharle
 
Introduction to Arduino 16822775 (2).ppt
Introduction to Arduino 16822775 (2).pptIntroduction to Arduino 16822775 (2).ppt
Introduction to Arduino 16822775 (2).pptansariparveen06
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalTony Olsson.
 
Arduino projects &amp; tutorials
Arduino projects &amp; tutorialsArduino projects &amp; tutorials
Arduino projects &amp; tutorialsAnshu Pandey
 
Micro c lab8(serial communication)
Micro c lab8(serial communication)Micro c lab8(serial communication)
Micro c lab8(serial communication)Mashood
 
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 Radiosroadster43
 

Similaire à 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
 

Plus de Don Doerres

2018 03 28_near_scifi
2018 03 28_near_scifi2018 03 28_near_scifi
2018 03 28_near_scifiDon Doerres
 
2018LifeOnOtherWorldsl
2018LifeOnOtherWorldsl2018LifeOnOtherWorldsl
2018LifeOnOtherWorldslDon Doerres
 
2018_03_15_life_on_otherworlds
2018_03_15_life_on_otherworlds2018_03_15_life_on_otherworlds
2018_03_15_life_on_otherworldsDon Doerres
 
2017 aacr youth day
2017 aacr youth day2017 aacr youth day
2017 aacr youth dayDon Doerres
 
Presentation desert codecamp_2017_1_sonichandkerchief
Presentation desert codecamp_2017_1_sonichandkerchiefPresentation desert codecamp_2017_1_sonichandkerchief
Presentation desert codecamp_2017_1_sonichandkerchiefDon Doerres
 
2013 1 arduino_datalogger
2013 1 arduino_datalogger2013 1 arduino_datalogger
2013 1 arduino_dataloggerDon Doerres
 
Rasberry pi class
Rasberry pi classRasberry pi class
Rasberry pi classDon Doerres
 
Raspberry pi lnl
Raspberry pi lnlRaspberry pi lnl
Raspberry pi lnlDon Doerres
 
Single Boards Overview
Single Boards OverviewSingle Boards Overview
Single Boards OverviewDon Doerres
 

Plus de 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
 

Dernier

Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXTarek Kalaji
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?IES VE
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URLRuncy Oommen
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxGDSC PJATK
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfJamie (Taka) Wang
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Brian Pichman
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxUdaiappa Ramachandran
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding TeamAdam Moalla
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...DianaGray10
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarPrecisely
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 

Dernier (20)

Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBX
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URL
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptx
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptx
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity Webinar
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 

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