Setting Up USB-to-Serial Communication on LicheePi 4A

This guide covers estbalishing serial communication between a LicheePi 4A board and a host PC using a USB-to-TTL adapter. The board runs Debian 20231023 with the LicheePi 4A 8+8G configuration.

Prerequisites

The onboard UART1 operates at 1.8V logic levels. Since most USB-to-Serial adapters use 3.3V or 5V signalnig, a voltage level converter is required for direct GPIO access. This guide uses a USB-to-Serial module connected to the board's USB-C debug port as an alternative approach.

Installing the Serial Communication Library

Install the pyserial package for Python-based serial communication:

pip3 install pyserial

Verify the installation:

pip3 list | grep pyserial

Expected output:

pyserial 3.5

Identifying the USB Serial Port

Connect the USB-to-Serial module and enumerate available serial devices:

ls -la /dev/serial/by-id/

The USB Serial device typically appears as:

/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0

Using the device ID path provides a stable identifier that persists across reboots and USB port changes.

Serial Communication Implementation

The following Python script demonstrates bidirectional serial communication with a dedicated receive thread:

# -*- coding: utf-8 -*-
import serial
import time
import threading

# Serial configuration
PORT = "/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0"
BAUD = 115200
TIMEOUT = 0.5

# Initialize serial connection
conn = serial.Serial(PORT, BAUD, timeout=TIMEOUT)

def read_incoming():
    """Continuously monitor and display incoming serial data."""
    while True:
        if conn.in_waiting > 0:
            payload = conn.read(conn.in_waiting).decode("utf-8")
            print(payload, end='')

# Launch background reader
receiver_thread = threading.Thread(target=read_incoming, daemon=True)
receiver_thread.start()

# Main loop: transmit periodic messages
try:
    while True:
        message = "serial_test\n"
        conn.write(message.encode('utf-8'))
        time.sleep(1)
except KeyboardInterrupt:
    conn.close()
    print("\nConnection closed.")

Communication Parameters

Parameter Value Description
Baud Rate 115200 Standard baud rate for embedded devices
Data Bits 8 Default configuration
Stop Bits 1 Default configuraton
Parity None No error checking
Timeout 500ms Receive timeout

Testing Procedure

  1. Connect the USB-to-Serial module to the host PC
  2. Identify the assigned serial port on the host
  3. Configure terminal software (minicom, screen, or puTTY) with matching baud rate
  4. Execute the Python script on LicheePi 4A
  5. Verify transmitted messages appear in the terminal emulator
  6. Confirm received data displays in the script's console output

Troubleshooting

No data received: Verify the baud rate matches on both ends and confirm physical connections.

Permission denied: Add the user to the dialout group:

sudo usermod -a -G dialout $USER

Garbled output: Ensure both devices use identical baud rates and data format settings.

Tags: licheepi-4a serial-communication usb-serial pyserial debian

Posted on Sun, 17 May 2026 07:27:40 +0000 by shibbi3