Arduino SW UART example

The Arduino Uno R3 only has 1 HW UART that is connected to the on board USB – UART chip.  I need a second one to interface with my recently purchased ESP8266 ($4 Wifi module).

  • Challenge 1: Voltage Difference
    • ESP8266 is 3.3V only IO
    • Arduino Uno R3 is 5V IO
  • Solution: Use simple R divider
    • This only is good for slow speed signals.  I plan on using only 9600 baud so this should work for now.
    • To keep is simple, I am using just 2x 10K ohm R’s on the Arduino SW UART TX pin.  The Arduino RX pin shouldn’t need anything.  Hoping that 3.3V coming from the ESP8266 is high enough for the switching level of the Arduino.
    • Here is the simple diagram of my plan…
    • FinalConnectionDiagram

Instead of jumping straight in, I am going to use an FTDI TTL-232R-3V3 cable to test the Arduino SW UART concept.  This is easier to debug since I can use TeraTerm on the PC to connect to the FTDI cable and send / receive any characters at any time to test the connects and the Arduino SW sketch.

  1. Here is the connection diagram I used…
    1.  SWUART_TestingWithFTDICable
    2. FTDI cable diagram
    3. PinoutDiagram
  2. Simple Arduino sketch for testing
    1. Concept is to pass all data from the FTDI cable connected to Arduino pins6,7 (which are NOT HW UARTs) to the Arduino HW UART.
    2. Here is my simple sketch
      1. /*
        Software serial testReceives from the hardware serial, sends to software serial.
        Receives from software serial, sends to hardware serial.*/
        #include <SoftwareSerial.h>

        SoftwareSerial mySerial(7, 6); // RX, TX

        void setup()
        {
        // Open serial communications and wait for port to open:
        Serial.begin(9600);
        mySerial.begin(9600);

        mySerial.println(“Hello, world?”);
        }

        void loop() // run over and over
        {
        if (mySerial.available())
        Serial.write(mySerial.read());
        if (Serial.available())
        mySerial.write(Serial.read());
        }

      2. It is based off of http://arduino.cc/en/Reference/softwareSerial
    3. Screen Capture of TeraTerm and Arduino
      1. TerminalScreenCapture

YAHOOO!!!!!  It worked.  Now to connect it up to the ESP8266 and see if it work.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s