> ## Documentation Index
> Fetch the complete documentation index at: https://docs.t3gemstone.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Serial Port

> Serial Port Usage

export const int_0 = "Interface"

export const device_0 = "Device"

export const file_0 = "Overlay File"

<Tip>
  By the end of this section, you will gain experience in the following topics:

  * Establishing a serial port connection between the developer's computer and the Gemstone board using a USB TTL cable.
  * Communicating between both computers via a terminal.
  * Preliminary preparation for the [t3gemstone/examples/serial](https://github.com/t3gemstone/examples/tree/main/serial) project.
</Tip>

A serial port is a communication channel that enables data transmission between devices such as computers and
microcontrollers. This communication typically occurs via the `UART (Universal Asynchronous Receiver-Transmitter)`
protocol and is ideal for low-speed data transmission. For example, serial ports are often preferred when
communicating with external modules like GPS or Radio Transmitters.

### Serial Port Interfaces

The serial port interfaces on the T3-GEM-O1 card are listed in the table below.

<Frame caption="Pins that can be used as serial ports">
  <img className="rounded-lg" src="https://mintcdn.com/t3gemstone-754bcb96/xXa-dgH9QsK0Txx6/images/o1-board/33-serials.png?fit=max&auto=format&n=xXa-dgH9QsK0Txx6&q=85&s=dfe2c62300278d4ca66a1e33c901f951" width="1221" height="750" data-path="images/o1-board/33-serials.png" />
</Frame>

<Frame caption="UART-MAIN0 TTL Port Connection">
  <img className="rounded-lg" src="https://mintcdn.com/t3gemstone-754bcb96/uJeZoP5Biqzgvh8k/images/o1-board/35-serial-port-ttl-2.png?fit=max&auto=format&n=uJeZoP5Biqzgvh8k&q=85&s=f4f99381c4c1f23d97f63f4bb8bb3c35" width="1053" height="639" data-path="images/o1-board/35-serial-port-ttl-2.png" />
</Frame>

| {int_0}        | {device_0} | GPIO (RX)     | GPIO (TX)     | {file_0}                             |
| -------------- | ---------- | ------------- | ------------- | ------------------------------------ |
| **UART-MAIN0** | `ttyS2`    | Serial Header | Serial Header |                                      |
| **UART-MAIN1** | `ttyS3`    | GPIO-15       | GPIO-14       |                                      |
| **UART-MAIN6** | `ttyS6`    | GPIO-4        | GPIO-17       | `k3-am67a-t3-gem-o1-uart-ttys6.dtbo` |
| **UART-WKUP0** | `ttyS0`    | GPIO-7        | GPIO-24       | `k3-am67a-t3-gem-o1-uart-ttys0.dtbo` |

<Note>
  * Access to the Linux terminal is obtained from the UART‑MAIN0 serial port.
  * When the `k3-am67a-t3-gem-o1-pwm-epwm0-gpio5-gpio14.dtso` overlay is enabled, the UART‑MAIN1 TX pin is disabled, while
    the RX pin continues to function normally.
  * Bluetooth becomes disabled when the UART‑MAIN6 serial port is activated.
</Note>

The names of the overlay files for the interfaces to be enabled must be added to the `overlays` variable
in the `/boot/uEnv.txt` file. Detailed information about overlays can be found in the
[Device Tree](./introduction/#2-device-tree) section.

### Serial Port Usage

<Steps>
  <Step title="SSH/VNC Connection">
    Connect to the development board using one of the methods: [SSH](../../../quickstart#2-3-network-connection-via-ssh) or
    [VNC](../../../quickstart#2-2-remote-desktop-connection-via-browser-with-vnc).
  </Step>

  <Step title="Shell">
    Create Bash Shell scripts.
  </Step>

  <Step title="TTL and Terminal">
    Connect the developer's computer and the Gemstone board using a TTL cable and perform data exchange via the Tabby.sh terminal.
  </Step>
</Steps>

#### 1. Creating a Shell Script

Create a script file for opening the serial port and sending data.

```bash theme={"system"}
touch serial-test.sh
```

#### 2. Using a Text Editor

Open the `serial-test.sh` file using the `nano` text editor from the terminal interface.

```bash theme={"system"}
nano serial-test.sh
```

After copying the following code, paste it into the `serial-test.sh` file.

```bash lines theme={"system"}
#!/bin/bash

SERIAL_PORT="/dev/ttyS3"
BAUD_RATE="115200"

stty -F /dev/ttyS3 115200 -crtscts

while true; do
    echo "Teknofest" > $SERIAL_PORT
    sleep 1
done
```

Press `CTRL+X`, then press `Y` to save and exit the nano editor.

#### 3. Running the Shell Script

Make the `serial-test.sh` file executable using the `chmod` command and start it.

<CodeGroup>
  ```bash Terminal lines theme={"system"}
  chmod +x serial-test.sh
  ./serial-test.sh
  ```

  ```bash Output lines theme={"system"}
  ```
</CodeGroup>

#### 4. Communication

<Frame>
  <video controls className="w-full aspect-video" src="https://mintcdn.com/t3gemstone-754bcb96/oFj6OOIrYSQVBj-3/videos/seri-test.mp4?fit=max&auto=format&n=oFj6OOIrYSQVBj-3&q=85&s=94cdd4d850ccb4e8fdfaa371f96370b7" data-path="videos/seri-test.mp4" />
</Frame>
