UART - Communicate with the computer via UART

Introduction of UART

  • UART uses two wirelines, one for transmitting and the other one for receiving, so as to make the data transmission bidirectional. The commnication use a predefined frequency (baud rate) to transmit data.In Arduino, UART is called “Serial”. There is only one hardware UART on Arduino Uno, and is primarily used to read the log and messages printed by arduino (so it’s also called “Log UART”). If we use the hardware UART for other purposes, the Log UART does not have resources to do its job. To provide more UART connections, Arduino UNO uses Serial Pin to simulate the behavior of UART by a software approach, this is called Software Serial.However, Ameba is equipped with a number of hardware UART. But to be compatible with the Software Serial API of Arduino, Ameba follows the name “Software Serial”

Materials

  • Ameba x 1
  • USB to TTL Adapter x 1

Example

In this example, we use UART to connect USB to TTL Adapter to Ameba.
USB to TTL Adapter sends data to Ameba, the data would be returned by Ameba, and showed on the screen.
 
  • Install USB to TTL Adapter

USB to TTL Adapter converts USB to Serial interface. Normally, there are 4 pins on the adapter, that is 3V3 (or 5V), GND, TX and RX. Gernerally, installing the driver for the USB to TTL Adapter would be required before using it. If the adapter uses the chip of FTDI, Windows would search and install the driver automatically, otherwise, you may need to install corresponding driver yorself.
Afterwards, open the Device Manager. You can find corresponding Serial Port of the USB to TTL Adapter:

5-1
  • Executing the Example<

Open the “SoftwareSerialExample” example in “File” -> “Examples” -> “AmebaSoftwareSerial” -> “SoftwareSerialExample”:

5-2

Connect the wirelines as the diagram. The TX pin of USB to TTL Adapter is connected to D0 (which is its RX) of Ameba, and the RX pin of USB to TTL Adapter is connected to D1 (which is its TX) of Ameba.

5-3
 

RTL8710 Wiring Diagram:
5-2

Next, open the Serial Port Terminal, such as Putty, Tera Term. (We use Putty in this example.) Open the Putty window, choose “Serial” in Connection Type, and specify the port of USB to TTL Adapter in Serial line field (Ex. COM8).In Speed field, fill in the baud rate of this connection. (Note that both sides of the connection should use the same baud rate.) In this example we se baud rate 4800.
5-4
Next, click “Serial” on the left side. We set Data bits to 8, Stop bits to 1, Parity to None, and Flow control to None.
5-5
Then click Open, and press the reset button on Ameba. You can see the “Hello, world?” message appears in Putty. If insert characters in Putty, the input characters would be sent to Serial RX of Ameba by TX of USB to TTL Adapter, and returned by Serial TX of Ameba. Finally, RX of USB to TTL Adapter receives the returned characters and prints them in Putty. Therefore, if you insert “I am fine”, you would get something like this:
5-6

Code Reference

First, use SoftwareSerial: begin(speed) to set the baud rate for the serial communication:
https://www.arduino.cc/en/Reference/SoftwareSerialBegin
Use write() to send data, and use SoftwareSerial: available() to get the number of bytes available for reading from a software serial port:
https://www.arduino.cc/en/Reference/SoftwareSerialAvailable
If there are data available to read, use read() to read from serial port.
Please confirm that QQ communication software is installed