https://github.com/xanthium-enterprises/linux-serialport-programming-using-c-termios-api
Learn to program the serial port of a Linux Computer like Ubuntu,Fedora,Arch using C language and termios API for communicating with a single board computer like Arduino (ATmega328P) or Raspberry Pi Pico.
https://github.com/xanthium-enterprises/linux-serialport-programming-using-c-termios-api
arduino-linux-serialport arduino-serial atmega328p c-language c-programming c-programming-language linux linux-serialport msp430g2553 raspberry-pi raspberry-pi-pico serial-communication serial-port-communication serialport termios termios-structure tty ttys0 ttyusb
Last synced: 5 months ago
JSON representation
Learn to program the serial port of a Linux Computer like Ubuntu,Fedora,Arch using C language and termios API for communicating with a single board computer like Arduino (ATmega328P) or Raspberry Pi Pico.
- Host: GitHub
- URL: https://github.com/xanthium-enterprises/linux-serialport-programming-using-c-termios-api
- Owner: xanthium-enterprises
- License: mit
- Created: 2025-06-15T12:26:55.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-06-17T13:14:19.000Z (8 months ago)
- Last Synced: 2025-07-27T06:09:10.807Z (6 months ago)
- Topics: arduino-linux-serialport, arduino-serial, atmega328p, c-language, c-programming, c-programming-language, linux, linux-serialport, msp430g2553, raspberry-pi, raspberry-pi-pico, serial-communication, serial-port-communication, serialport, termios, termios-structure, tty, ttys0, ttyusb
- Language: C
- Homepage: https://www.xanthium.in/native-serial-port-communication-arduino-micro-linux-unix-bsd-system-c-lang-terminos-api
- Size: 906 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Linux Serial Port Programming Tutorial using C Language and termios API
- In this repo ,You will find code for programming the serial port of your Linux distribution(Ubuntu,Fedora,Arch,Linux Mint) using C language.
- We will also Learn to perform Bi-Directional Serial Communication between a Linux PC and an Arduino UNO
- Here we will be using the native API's provided by the Linux System like the
- **termios** structure.
- **read()** system call
- **write()** system call
- to configure the serial port of our linux system.
- Code is written in **Pure C** language and compiled using **GCC**.

## Online Tutorial
A detailed writeup of the Linux serial Port Programming tutorial can be found using the below link
- [Linux Serial Port Programming tutorial for the Absolute Beginner](https://www.xanthium.in/native-serial-port-communication-arduino-micro-linux-unix-bsd-system-c-lang-terminos-api)
-


## Hardware Connections

The above image shows how to connect the Arduino board with the Linux PC for Serial Communication.

The above image shows how to interface bare microcontrollers like 8051,ATmega328P,MSP430 with linux serial port using a [USB to Serial Converter](https://www.xanthium.in/USB-to-Serial-RS232-RS485-Converter).
## Compiling the Code.
The Code can be compiled using GCC on any modern Linux Systems.
`gcc serial_port_code.c -o serial_port_code`
Code tested on
- `OS :Fedora Linux 42 (Workstation Edition) x86_64`
- `Kernel :Linux 6.14.9-300.fc42.x86_64`
- `Compiler :gcc (GCC) 15.1.1 20250521 (Red Hat 15.1.1-2)`
- `OS : Ubuntu 24.04.2 LTS x86_64`
- `Kernel : 6.11.0-26-generic`
- `Compiler :gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0`
## Screen shots
