Go to file
Felix Hädicke 730ed711e1 UsbSerialPort: add purgeHwBuffers method.
Consolidates following changes from Felix (newest first):
  1123807 Rename flushHwBuffers to purgeHwBuffers
  3eb145d Use UsbSerialPort instead of UsbSerialDriver in SerialInputOutputManager
  f91a974 Return true in flushHwBuffers default implementation if there is nothing to flush
  69c0b59 Implement flushHwBuffers for Cp2102 driver
  4a41bd9 Rename UsbSerialPort.flush function to flushHwBuffers
  c908da4 Refactoring: Make ProlificSerialDriver a subclass of CdcAcmSerialDriver
  39cb480 Refactoring: New UsbSerialPort interface
  d542f64 Refactoring: Do not require permission to USB device when probing
  9a13571 Support flushing non-written / non-read data
2013-10-28 17:05:22 -07:00
UsbSerialExamples Device support: PL2303. 2013-10-28 16:41:57 -07:00
UsbSerialLibrary UsbSerialPort: add purgeHwBuffers method. 2013-10-28 17:05:22 -07:00
arduino Add example arduino program. 2012-08-30 17:08:44 -07:00
.gitignore Add gitignore. 2012-10-10 21:45:48 -07:00
CHANGELOG.txt Add Leaflabs Maple to CDC probe table. 2013-04-07 22:53:21 -07:00
LICENSE.txt
README.md Update README.md 2013-09-13 09:34:09 -07:00

README.md

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 API available on Android 3.1+.

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 basic functions for use with your own protocols.

Quick Start

1. Download usb-serial-for-android-v010.jar

2. Copy the jar to your Android project's libs/ directory. (See Android's FAQ for help).

3. Copy device_filter.xml to your project's res/xml/ directory.

4. Configure your AndroidManifest.xml to notify your app when a device is attached (see Android USB Host documentation for help).

<activity
    android:name="..."
    ...>
  <intent-filter>
    <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
  </intent-filter>
  <meta-data
      android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" 
      android:resource="@xml/device_filter" />
</activity>

5. Use it! Example code snippet:

// Get UsbManager from Android.
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);

// Find the first available driver.
UsbSerialDriver driver = UsbSerialProber.acquire(manager);

if (driver != null) {
  driver.open();
  try {
    driver.setBaudRate(115200);
    
    byte buffer[] = new byte[16];
    int numBytesRead = driver.read(buffer, 1000);
    Log.d(TAG, "Read " + numBytesRead + " bytes.");
  } catch (IOException e) {
    // Deal with error.
  } finally {
    driver.close();
  } 
}

For a more complete example, see the UsbSerialExamples project in git, which is a simple application for reading and showing serial data.

A simple Arduino application is also available which can be used for testing.

Compatible Devices

  • Serial chips: FT232R, CDC/ACM (eg Arduino Uno) and possibly others. See CompatibleSerialDevices
  • Android phones and tablets: Nexus 7, Motorola Xoom, and many others. See CompatibleAndroidDevices.

usb-serial-for-android is written and maintained by mike wakerly.

This library is licensed under LGPL Version 2.1. Please see LICENSE.txt for the complete license.

Copyright 2011-2012, Google Inc. All Rights Reserved.

Portions of this library are based on libftdi (http://www.intra2net.com/en/developer/libftdi). Please see FtdiSerialDriver.java for more information.

Help & Discussion

Please join our Google Group, usb-serial-for-android.

Are you using this library? Let us know and we'll add your project to ProjectsUsingUsbSerialForAndroid.