mik3y /usb-serial-for-android

Android USB host serial driver library for CDC, FTDI, Arduino and other devices.

★ 5,723⑂ 1,694👁 238⑃ 86● 562▤ 36
JavaMITCreated 2013-06-30
Download: v3.12.0v3.12.0 ↓3.12.02026-11-10
+0
Daily
5,723
stars
1,694
forks
238
watchers
86
prs
562
issues
36
releases

README

usb-serial-for-android

This is a driver library for communication with Arduinos and other USB serial hardware on
Android, using the
Android USB Host Mode (OTG)
available since Android 3.1 and working reliably since Android 4.2.

No root access, ADK, or special kernel drivers are required; all drivers are implemented in
Java.  You get a raw serial port with read(), write(), and other functions for use with your own protocols.

 Quick Start

1. Add library to your project:

Add jitpack.io repository to your root build.gradle:
gradle
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}


Starting with gradle 6.8 you can alternatively add jitpack.io repository to your settings.gradle:
gradle
dependencyResolutionManagement {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}


If using gradle kotlin  use line
gradle.kts
        maven(url = "https://jitpack.io")


Add library to dependencies
gradle
dependencies {
    implementation 'com.github.mik3y:usb-serial-for-android:3.12.0'
}


2. If the app should be notified when a device is attached, add 
device_filter.xml 
to your project's res/xml/ directory and configure in your AndroidManifest.xml.

xml

    
        
    
    



3. Use it! Example code snippet:

open device:
java
    // Find all available drivers from attached devices.
    UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
    List availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager);
    if (availableDrivers.isEmpty()) {
        return;
    }

    // Open a connection to the first available driver.
    UsbSerialDriver driver = availableDrivers.get(0);
    UsbDeviceConnection connection = manager.openDevice(driver.getDevice());
    if (connection == null) {
        // add UsbManager.requestPermission(driver.getDevice(), ..) handling here
        return;
    }

    UsbSerialPort port = driver.getPorts().get(0); // Most devices have just one port (port 0)
    port.open(connection);
    port.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE);

then use direct read/write
java
    port.write(request, WRITE_WAIT_MILLIS);
    len = port.read(response, READ_WAIT_MILLIS);

or direct write + event driven read:
java
    usbIoManager = new SerialInputOutputManager(usbSerialPort, this);
    usbIoManager.start();
    ...
    port.write("hello".getBytes(), WRITE_WAIT_MILLIS);
    
@Override
public void onNewData(byte[] data) {
    runOnUiThread(() - { textView.append(new String(data)); });
}

and finally:
java
    port.close();


For a simple example, see
UsbSerialExamples
folder in this project.

See separate github project SimpleUsbTerminal 
for a more complete example with:
 Background service to stay connected while the app is not visible or rotating
 Flow control 

 Probing for Unrecognized

Top issues

Latest release

v3.12.0 3.12.0 2026-11-10
features:
- support CH34x RTS/CTS flow control 
  _note: looks like the chip handles CTS, but not RTS_

fixes:
- CH34x baud rate 307200 with lower deviation

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON