explaingit

mik3y/usb-serial-for-android

5,586JavaAudience · developerComplexity · 3/5Setup · moderate

TLDR

Android Java library for communicating with hardware devices like Arduinos and USB serial adapters connected via USB, without needing root access or custom kernels on the device.

Mindmap

mindmap
  root((usb-serial-for-android))
    What it does
      Android USB serial
      Hardware communication
    Supported chips
      FTDI converters
      CP210x Silicon Labs
      CH340 Qinheng
      CDC and ACM devices
    Usage modes
      Direct read and write
      Event-driven callbacks
    Setup
      No root required
      Custom probe table
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Connect an Arduino or microcontroller to an Android device via USB and send and receive data from your app

USE CASE 2

Build an Android app that communicates with FTDI, CP210x, or CH340 USB-to-serial converter chips

USE CASE 3

Receive data from a USB serial device using event-driven mode that calls your code when new data arrives

USE CASE 4

Add support for an unlisted USB device by configuring a custom probe table with the device vendor and product IDs

Tech stack

JavaAndroid

Getting it running

Difficulty · moderate Time to first run · 1h+

Requires a physical Android device with USB host mode support and a compatible USB serial adapter or Arduino for testing, standard Android development environment needed.

In plain English

usb-serial-for-android is a Java library that lets Android apps talk to physical hardware devices connected via USB. The kind of hardware it targets includes Arduinos, microcontrollers, and USB-to-serial adapter chips commonly used in electronics projects. When you plug such a device into an Android phone or tablet using an OTG cable, this library lets your app send and receive data over the connection. Android has built-in support for USB host mode, meaning it can act as the controller rather than just a peripheral. This library builds on that feature by providing drivers for the specific chips that most USB serial adapters use. Supported chips include FTDI converters, Prolific PL2303, Silicon Labs CP210x, and Qinheng CH340 series, among others. Arduino boards and other devices that follow a general USB communication standard called CDC/ACM also work. No device rooting or custom kernel changes are needed, and everything runs in standard Java. Using the library involves three steps: adding it to your Android project's build file, optionally setting up an intent filter so your app launches automatically when a matching device is plugged in, and then writing code to open the port, set speed and parity parameters, and read or write bytes. The library supports both a simple direct read/write approach and an event-driven mode where a background manager calls your code whenever new data arrives. If a device is not in the built-in list of recognized hardware, you can configure a custom probe table with the device's specific USB vendor and product identifiers to point it at the right driver. The project also links to a more complete example app called SimpleUsbTerminal that demonstrates background connection management and hardware flow control.

Copy-paste prompts

Prompt 1
I want to connect an Arduino to my Android phone via USB OTG and send commands from my app. Show me how to set up usb-serial-for-android.
Prompt 2
How do I configure my Android app to launch automatically when a CP210x USB device is plugged in using usb-serial-for-android?
Prompt 3
Help me implement event-driven serial data reading in Android so my app gets a callback whenever the USB device sends new bytes.
Prompt 4
My USB device is not in the built-in driver list. How do I create a custom probe table with my device vendor and product ID?
Prompt 5
Walk me through reading and writing bytes to an FTDI USB serial adapter from an Android app at a specific baud rate.
Open on GitHub → Explain another repo

← mik3y on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.