UART - Communicate with PC over USB to Serial Module
Introduction of UART
UART uses two wire, one for transmitting and the other one for receiving, so the data transmission is bidirectional. The communication uses a predefined frequency (baud rate) to transmit data. In Arduino, UART is called “Serial”. There is only one hardware UART on Arduino Uno and it is primarily used to read the log and messages printed by Arduino (so it is also called “Log UART”). If we use the hardware UART for other purposes, the Log UART does not have resources to function. To provide more UART connections, it is possible to use a GPIO pin to simulate the behavior of UART with a software approach, this is called Software Serial. Ameba is equipped with several hardware UART ports, but it is also compatible with the Software Serial library.
Materials
AmebaD [AMB21 / AMB22 / AMB23 / BW16] x 1
USB to TTL Adapter x 1
Example
Install USB to TTL Adapter
Executing the Example
“File” -> “Examples” ->
“AmebaSoftwareSerial” -> “SoftwareSerial_Basic”
:Next, open a serial port terminal, such as Putty or Tera Term. (Putty is used in this example). Open the Putty window, choose “Serial” in connection type, and specify the port number of the USB to TTL adapter (e.g. COM8). In the 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 set baud rate 4800.
Next, select “Serial” on the left side. Set data bits to 8, stop bits to 1, parity to none, and flow control to none.
Then click Open and press the reset button on Ameba. You can see the “Hello, world?” message appears in Putty. If characters are typed into 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 will get something like this:
Code Reference
SoftwareSerial:begin(speed)
to set the baud rate for the
serial communication:write()
to send data, and use SoftwareSerial:available()
to get the
number of bytes available for reading from a software serial port: