User Tools

Site Tools


oak:tutorials:serial_through_arduino

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
oak:tutorials:serial_through_arduino [2017/01/09 00:58]
Rover#18 [Example Voltage Divider Resistor Combinations]
oak:tutorials:serial_through_arduino [2018/01/06 20:57]
pfeerick ammended warning about 5v tolerance due to corrections to datasheet
Line 1: Line 1:
 ======Oak: serial communication through an Arduino====== ======Oak: serial communication through an Arduino======
  
-The Oak uses a 3.3V serial interface on pins 3 (RX) and 4 (TX). This interface is useful for communicating wth serial-enabled peripheral devices, transmitting debug messages, receiving messages, and flashing firmware. ​ This last use case is an essential component of the [[A serial interface|Oak factory restore procedure]].  ​+The Oak uses a 3.3V serial interface on pins 3 (RX) and 4 (TX). This interface is useful for communicating wth serial-enabled peripheral devices, transmitting debug messages ​and program data, receiving messages, and flashing firmware. ​ This last use case is an essential component of the [[A serial interface|Oak factory restore procedure]].  ​
  
-One can communicate directly with the Oak through a 3.3V USB/UART adapter (ex: [[http://​www.amazon.com/​Module-Serial-Converter-Adapter-CH340G/​dp/​B00W74BTK2|1]],​ [[https://​www.sparkfun.com/​products/​13263|2]]),​ or through a 5V UART with special considerations for level conversion and/or current limiting.  ​+One can communicate directly with the Oak through a 3.3V USB/UART adapter (ex: [[http://​www.amazon.com/​Module-Serial-Converter-Adapter-CH340G/​dp/​B00W74BTK2|1]],​ [[https://​www.sparkfun.com/​products/​13263|2]]) ​if available, or through a 5V UART with special considerations for level conversion and/or current limiting.  ​
  
 This article describes an alternative method which uses an Arduino as a USB serial converter. ​ This method is particularly convenient for those of us who don't have a 3.3V USB UART on-hand but do happen to have a spare Arduino. This article describes an alternative method which uses an Arduino as a USB serial converter. ​ This method is particularly convenient for those of us who don't have a 3.3V USB UART on-hand but do happen to have a spare Arduino.
  
-{{ :​oak:​tutorials:​img_20160316_185542.jpg?​400 |}}+{{ :​oak:​tutorials:​img_20160316_185542.jpg?​500 |}}
  
 ===== Components used ===== ===== Components used =====
  
 ^ Part       ^ Quantity ​         ^ ^ Part       ^ Quantity ​         ^
-| Oak with soldered headers |1| +| Oak with soldered headers |   
-| Arduino| 1| +| Arduino| ​  
-| Breadboard| 1| +| Breadboard| ​  
-| Jumper wires| ​5-6+| Jumper wires| ​ 7-10  ​
-| 1 kOhm resistor* | 1| +| 1 kOhm resistor* |   
-| 2 kOhm resistor* | 1|+| 2 kOhm resistor* |   |
  
 ** * Note:** The resistor values above are not critical. \\  ** * Note:** The resistor values above are not critical. \\ 
Line 29: Line 29:
 \\  \\ 
 ---- ----
-===== A Word about (CounterintuitiveArduino UART Connections =====+===== A Word about Counterintuitive Arduino UART Connections =====
  
 Normally, we connect one device'​s Tx pin to another'​s Rx pin, and vice versa. ​ For example, if we were to connect the Oak to a computer, either through a native serial interface or through a USB-TTL dongle, the signal paths would be as follows: Normally, we connect one device'​s Tx pin to another'​s Rx pin, and vice versa. ​ For example, if we were to connect the Oak to a computer, either through a native serial interface or through a USB-TTL dongle, the signal paths would be as follows:
Line 43: Line 43:
 -------- ​        ​----------------- ​          --- -------- ​        ​----------------- ​          ---
 USB Tx -------->​ USB Rx -> UART Tx  -------->​ Rx USB Tx -------->​ USB Rx -> UART Tx  -------->​ Rx
-USB Rx <​-------- USB Tx -UART Rx  <​-------- Tx+USB Rx <​-------- USB Tx <- UART Rx  <​-------- Tx
 </​code>​ </​code>​
  
 However, the Arduino pin labeling does not follow this convention.  ​ However, the Arduino pin labeling does not follow this convention.  ​
  
-We will be operating our Arduino in pass-through mode.  We force this mode by shorting the reset pin to ground, which essentially turns off the ATmega main processor and allows direct access to the usb-serial interface via the Arduino'​s "​Tx"​ and "​Rx"​ pins.  A word of caution: in the mode in which we will operate our Arduino, the pins labeled "​Tx"​ and "​Rx"​ act opposite of their labels The "​Rx"​ pin transmits and the "​Tx"​ pin recieves.+We will be operating our Arduino in pass-through mode.  We force this mode by shorting the reset pin to ground, which essentially turns off the ATmega main processor and allows direct access to the usb-serial interface via the Arduino'​s "​Tx"​ and "​Rx"​ pins.  A word of caution: in the mode in which we will operate our Arduino, the pins labeled "​Tx"​ and "​Rx"​ act opposite of their labels the "​Rx"​ pin transmits and the "​Tx"​ pin recieves.
  
-Although counterintuitive,​ these appartenly ​backward labels are not an error. ​ The reason for this convention has to do with the Arduino ​architectore.  The Arduino features an internal usb-serial interface which dual purposes as a TTL UART when a user sketch is running, and acts as a pass-through when tri-stated, which is how we intend ​to use it.  The Arduino pin labeled "​Rx" ​carries the signal received from the computer ​(to be transmitted to our Oak), while the pin labeled "​Tx" ​carries ​signal to be transmitted to the computer ​(received from the Oak).  Wierd, right?+Although counterintuitive,​ these seemingly ​backward labels are not an error. ​ The reason for this convention has to do with the Arduino ​architecture.  The Arduino features an internal usb-serial interface which dual purposes as a TTL UART when a user sketch is running, and acts as a pass-through when tri-stated, which is how we plan to use it.  The Arduino pin labeled "​Rx" ​mirrors ​signal received ​//from the computer// over USB, while the pin labeled "​Tx" ​mirrors ​signal to be transmitted ​//to the computer// over USB.  Wierd, right?
  
 <​code>​ <​code>​
 Computer ​        ​Arduino ​                      Oak Computer ​        ​Arduino ​                      Oak
 -------- ​        ​-------------------- ​          --- -------- ​        ​-------------------- ​          ---
-USB Tx -------->​ USB Rx -> UART "​Rx"​* -------->​ Rx +USB Tx -------->​ USB Rx -> PIN0 "​Rx"​* -------->​ Rx 
-USB Rx <​-------- USB Tx -> UART "​Tx"​* <​-------- Tx+USB Rx <​-------- USB Tx <PIN1 "​Tx"​* <​-------- Tx
  
-     ​*NOTE: ​When the Arduino ​is used as a pass-through UART, as we intend to do,  +     ​*NOTE: ​The Arduino ​"​Rx"​ pin mirrors signal received over USB,  
-     ​the UART pin functions reverse. ​ The Arduino pin labeled ​"​Tx" ​received and  +      ​while ​the "​Tx" ​pin stages signal ​to be transmitted over USB. 
-     must connect ​to Oak Tx.  ​Similarly, ​the Arduino ​pin labeled ​"​Rx" ​transmits  +       
-     and must connect to Oak Rx.+    **NOTE 2: this is NOT a wiring diagram.  ​Connecting the Oak Rx  
 +      pin directly to the Arduino "​Rx" ​pin is not advised.
 </​code>​ </​code>​
 \\  \\ 
Line 73: Line 74:
   - Using a voltage divider resistor network to cut Oak Rx input voltage to 3.3V   - Using a voltage divider resistor network to cut Oak Rx input voltage to 3.3V
   - Using a current limiter resistor   - Using a current limiter resistor
-  - Direct connection (not recommended)+  - Direct connection ([[https://​digistump.com/​wiki/​oak/​tutorials/​serial_through_arduino#​warning_regarding_direct_connection_to_5v_uart|not recommended]])
  
 ==== Warning regarding direct connection to 5V UART ==== ==== Warning regarding direct connection to 5V UART ====
-Several users ([[http://​digistump.com/​board/​index.php/​topic,​2036.msg9266.html#​msg9266|1]],​ [[https://​github.com/​digistump/​OakCore/​issues/​56#​issuecomment-197618541|2]]) have reported success wiring an Oak's Tx/Rx pins directly to an Arduino'​s 5V UART.  The [[https://​www.adafruit.com/​images/​product-files/​2471/​0A-ESP8266__Datasheet__EN_v4.3.pdf|ESP8266 data sheet]] describes ​overvoltage ​protection on all GPIO pins, which suggests ​the Oak should be able to safely read 5V TTL signal ​into the Rx pin.  However, it is not well known whether operating in this way degrades the life of the ESP8266. ​ Inserting a 1K resistor between the Arduino'​s 5V transmit pin and the Oak's Rx pin will help to limit current into the Oak, although the signal level received by the ESP8266 will still be 5V and the same caution regarding the longevity of your Oak still applies. ​ If you choose to connect your Oak to a 5V serial signal, either directly from an external 5V UART or through a current limiting resistor, do so at your own risk.+ 
 +{{ :​oak:​tutorials:​esp8266_5v_tolerant_io.png?​150|}}I'​ll leave the below for posterity, but the answer is pretty simple... the ESP8266 (and hence the Digistump Oak, as the ESP8266 is the microcontroller the Oak is based on) has 5v tolerant I/O pins. You should **NOT** put 5v on the VCC connector, as that WILL kill the Oak, but due to confusion resulting from mistranslation of the original Chinese datasheet which has been cleared up in later releases, and also by the CEO of Espressif (shown on the right), the I/O pins of the ESP8266 have snapback diodes that protect the chip from over-voltage up to 5.8v, and also from reverse voltages.  
 + 
 +Several users ([[http://​digistump.com/​board/​index.php/​topic,​2036.msg9266.html#​msg9266|1]],​ [[https://​github.com/​digistump/​OakCore/​issues/​56#​issuecomment-197618541|2]]) have reported success wiring an Oak's Tx/Rx pins directly to an Arduino'​s 5V UART.  The   ​[[https://​www.adafruit.com/​images/​product-files/​2471/​0A-ESP8266__Datasheet__EN_v4.3.pdf|ESP8266 data sheet]] describes ​over-voltage ​protection on all GPIO pins (pg 17+)suggesting ​the Oak should be able to safely read 5V TTL signal ​directly.  However, it is not well known whether operating in this way degrades the life of the ESP8266. ​ Inserting a resistor ​(300+ Ohm, typ. 1K) between the Arduino'​s 5V transmit pin and the Oak's Rx pin will help to limit current into the Oak, although the signal level received by the ESP8266 will still be 5V at the Oak Rx pin, and the same caution regarding the longevity of your Oak still applies. ​ If you choose to connect your Oak to a 5V serial signal, either directly from an external 5V UART or through a current limiting resistor, do so at your own risk.
  
 ==== Recommended solutions ==== ==== Recommended solutions ====
-The recommended solution is to **bring the external UART's 5V Tx line down to 3.3V for the Oak**, using either a [[https://​www.sparkfun.com/​products/​12009|logic level converter]] if available, or a voltage divider circuit. ​ This recommendation applies whether the external UART is an Arduino or any other 5V UART. +The recommended solution is to **bring the external UART's 5V Tx line down to 3.3V for the Oak**, using either a [[https://​www.sparkfun.com/​products/​12009|logic level converter]] if available, or a voltage divider circuit. ​ This recommendation applies whether the external UART is an Arduino or any other 5V UART.  The rest of this tutorial focuses on the voltage divider option since it uses common components which many Oak users have on-hand
-==== Recommendation ​1:  Using a bi-directional logic level converter ====+==== Option ​1:  Using a bi-directional logic level converter ​(if available) ​====
   * Also see: [[https://​learn.sparkfun.com/​tutorials/​bi-directional-logic-level-converter-hookup-guide|Sparkfun BDLC hookup guide]]   * Also see: [[https://​learn.sparkfun.com/​tutorials/​bi-directional-logic-level-converter-hookup-guide|Sparkfun BDLC hookup guide]]
 <​code>​ <​code>​
Line 88: Line 92:
   Arduino Gnd ----------- Gnd Level Converter Gnd ---------- Oak Gnd   Arduino Gnd ----------- Gnd Level Converter Gnd ---------- Oak Gnd
   ​   ​
-     ​*NOTE: ​When the Arduino is used as a pass-through UART, as we intend to do,  +     ​*NOTE:​ The Arduino "Rx" ​pin mirrors signal ​received ​over USB,  
-     the UART pin functions reverse.  ​The Arduino ​pin labeled ​"Tx" received ​and  +      ​while ​the "Tx" ​pin stages signal ​to be transmitted over USB.
-     must connect to Oak Tx.  Similarly, ​the Arduino pin labeled ​"Rx" ​transmits  +
-     and must connect ​to Oak Rx.+
 </​code>​ </​code>​
  
-==== Recommendation ​2:  Voltage-divided input line ====+==== Option ​2:  Voltage-divided input line ====
   * See [[http://​digistump.com/​wiki/​oak/​tutorials/​serial_through_arduino#​voltage_divider_resistor_selection|Voltage Divider Resistor Selection]] for guidance regarding selection of resistors R1 and R2   * See [[http://​digistump.com/​wiki/​oak/​tutorials/​serial_through_arduino#​voltage_divider_resistor_selection|Voltage Divider Resistor Selection]] for guidance regarding selection of resistors R1 and R2
 <​code>​ <​code>​
Line 103: Line 105:
                        |                        |
     Arduino Gnd -------+---- Oak Gnd     Arduino Gnd -------+---- Oak Gnd
-  ​ + 
-     ​*NOTE: ​When the Arduino is used as a pass-through UART, as we intend to do,  +     ​*NOTE:​ The Arduino "Rx" ​pin mirrors signal ​received ​over USB,  
-     the UART pin functions reverse.  ​The Arduino ​pin labeled ​"Tx" received ​and  +      ​while ​the "Tx" ​pin stages signal ​to be transmitted over USB.
-     must connect to Oak Tx.  Similarly, ​the Arduino pin labeled ​"Rx" ​transmits  +
-     and must connect ​to Oak Rx.+
 </​code>​ </​code>​
 ==== Your mileage may vary:  Current-limited 5V to Oak ==== ==== Your mileage may vary:  Current-limited 5V to Oak ====
   * Limits current into Oak Rx pin, should be safer than direct connection.   * Limits current into Oak Rx pin, should be safer than direct connection.
-  * Leaves input signal at 5V.  ​Potential impact ​to ESP8266 life is not well documented.+  * Leaves input signal at 5V.  ​Impact ​to ESP8266 life is not well documented.
 <​code>​ <​code>​
   Arduino "​Tx"​* ---------- Oak Tx   Arduino "​Tx"​* ---------- Oak Tx
Line 117: Line 117:
   Arduino Gnd   ​---------- Oak Gnd   Arduino Gnd   ​---------- Oak Gnd
   ​   ​
-     ​*NOTE: ​When the Arduino is used as a pass-through UART, as we intend to do,  +     ​*NOTE:​ The Arduino "Rx" ​pin mirrors signal ​received ​over USB,  
-     the UART pin functions reverse.  ​The Arduino ​pin labeled ​"Tx" received ​and  +      ​while ​the "Tx" ​pin stages signal ​to be transmitted over USB.
-     must connect to Oak Tx.  Similarly, ​the Arduino pin labeled ​"Rx" ​transmits  +
-     and must connect ​to Oak Rx.+
 </​code>​ </​code>​
 ==== Not recommended: ​ Direct connection ==== ==== Not recommended: ​ Direct connection ====
   * Reported to work by multiple users.   * Reported to work by multiple users.
-  * Leaves input signal at 5V. Potential impact ​to ESP8266 life is not well documented.+  * Leaves input signal at 5V.  ​Impact ​to ESP8266 life is not well documented.
 <​code>​ <​code>​
   Arduino "​Tx"​* ---------- Oak Tx   Arduino "​Tx"​* ---------- Oak Tx
-  Arduino "Tx"* ---------- Oak Rx      <-- 5V input - do so at your own risk+  Arduino "Rx"* ---------- Oak Rx      <-- 5V input - do so at your own risk
   Arduino Gnd   ​---------- Oak Gnd   Arduino Gnd   ​---------- Oak Gnd
   ​   ​
-     ​*NOTE: ​When the Arduino is used as a pass-through UART, as we intend to do,  +     ​*NOTE:​ The Arduino "Rx" ​pin mirrors signal ​received ​over USB,  
-     the UART pin functions reverse.  ​The Arduino ​pin labeled ​"Tx" received ​and  +      ​while ​the "Tx" ​pin stages signal ​to be transmitted over USB.
-     must connect to Oak Tx.  Similarly, ​the Arduino pin labeled ​"Rx" ​transmits  +
-     and must connect ​to Oak Rx.+
 </​code>​ </​code>​
  
Line 144: Line 140:
 ===== Voltage Divider Resistor Selection ===== ===== Voltage Divider Resistor Selection =====
  
-Since each maker'​s resistor collection is different, this article describes design considerations which allow flexibility in resistor selection, rather than specifying one set of resistance values.+Since each maker'​s resistor collection is different, this article describes design considerations which allow flexibility in resistor selection, rather than specifying one set of resistance values.  Read on for a brief explanation for selecting resistors, or skip to  [[https://​digistump.com/​wiki/​oak/​tutorials/​serial_through_arduino#​example_voltage_divider_resistor_combinations|example resistor combinations]].
  
 The resistors are needed to create a "​voltage divider."​ There are many explanations and tutorials around this topic, which you are encouraged to take a look at, such as the one found on [[https://​learn.sparkfun.com/​tutorials/​voltage-dividers/​all?​print=1|SparkFun]]. The short summary for the purposes of this tutorial is that the input voltage can be dropped to a desired output like so: The resistors are needed to create a "​voltage divider."​ There are many explanations and tutorials around this topic, which you are encouraged to take a look at, such as the one found on [[https://​learn.sparkfun.com/​tutorials/​voltage-dividers/​all?​print=1|SparkFun]]. The short summary for the purposes of this tutorial is that the input voltage can be dropped to a desired output like so:
Line 196: Line 192:
 This tutorial focuses on the voltage division method for connecting the Oak to an Arduino UART.  To build this circuit, you'll need to select two resistors per the guidance provided [[http://​digistump.com/​wiki/​oak/​tutorials/​serial_through_arduino#​voltage_divider_resistor_selection|above]].  ​ This tutorial focuses on the voltage division method for connecting the Oak to an Arduino UART.  To build this circuit, you'll need to select two resistors per the guidance provided [[http://​digistump.com/​wiki/​oak/​tutorials/​serial_through_arduino#​voltage_divider_resistor_selection|above]].  ​
  
-| FIXMERedraw the Fritzing diagram. ​ The Arduino "​Rx"​ pin should connect to the TOP of the voltage divider. ​ The Oak Rx pin should connect to the voltage divider junction. ​ The Arduino Tx pin should connect directly to the Oak Tx pin.  Add jumper between Arduino Reset and ground. |+{{:oak:​tutorials:​oaktoarduinoserialwithvoltagedivider_fritzingdiagram_jwhendy.png?​direct&​400 ​|}}
 \\  \\ 
 ==== Procedure for Connecting Oak to Arduino with Voltage Divider ==== ==== Procedure for Connecting Oak to Arduino with Voltage Divider ====
oak/tutorials/serial_through_arduino.txt · Last modified: 2018/01/06 20:57 by pfeerick