4-4 Serial Communication Functions
Learning Objectives
This chapter will help you understand and use Serial Communication on the NVIDIA Jetson Pandora platform. We will use simple commands to teach you how to configure the Pandora's UART interface, understand basic serial communication parameters (such as baud rate, data bits, etc.), and learn how to send and receive text messages.
What is Serial Communication?
Serial communication is a method of transmitting data "one-to-one" between devices. Data is transmitted sequentially, bit by bit, like a queue. It is just like talking to a friend on a walkie-talkie: you say one sentence at a time and wait for the other person to reply.
Key Parameters of Serial Communication
Before configuring the serial port, you need to know a few important parameters:
- Baud Rate: The speed of data transmission, e.g., 115200 (transmits 115,200 bits per second).
- Data Bits: How many bits of data are sent at a time, usually 8 bits (cs8).
- Stop Bits: The "pause" after each data packet, usually 1 bit (cstopb).
- Parity: Checks if data is correct, usually disabled (parenb).
We can use the stty command to set these parameters.
Setting up Serial Communication on Pandora
Serial Ports: /dev/ttyTHS3, /dev/ttyTHS1
1. Configure Serial Parameters
We will use the ttyTHS3 serial port. You can use the following command to configure it:
Bash
sudo stty -F /dev/ttyTHS3 speed 115200 cs8 -parenb -cstopb
- sudo: Requires administrator privileges.
- /dev/ttyTHS3: Serial port name.
- speed 115200: Sets the transmission rate to 115200.
- cs8: Sets data bits to 8 bits.
- parenb: Disables parity check.
- cstopb: Sets stop bits to 1 bit.
2. Using Serial Communication
Sending Data
(1) Switch to administrator mode:Bash
sudo su
(2) Configure the serial port:Bash
stty -F /dev/ttyTHS3 speed 115200 cs8 -parenb -cstopb
(3) Send the text "Hello Pandora":Bash
echo "Hello Pandora" > /dev/ttyTHS3
Receiving Data
Use the following command to read data received by the serial port:
Bash
cat /dev/ttyTHS3
This will display text messages received from the serial port. Press Ctrl+C to stop receiving.
Note: To test serial communication, you need to connect the Pandora's serial port (via a UART-to-USB cable) to another device (like a computer) and use a serial tool (such as Minicom or PuTTY) to view the data.
Summary
- Serial Communication is a way for Pandora to "chat" with other devices, transmitting data bit by bit.
- You need to use stty to configure serial parameters (like 115200 baud rate, 8 data bits).