{"id":13604615,"url":"https://github.com/mik3y/usb-serial-for-android","last_synced_at":"2025-05-13T15:13:22.701Z","repository":{"id":9255360,"uuid":"11079679","full_name":"mik3y/usb-serial-for-android","owner":"mik3y","description":"Android USB host serial driver library for CDC, FTDI, Arduino and other devices.","archived":false,"fork":false,"pushed_at":"2025-04-18T06:42:25.000Z","size":945,"stargazers_count":5176,"open_issues_count":35,"forks_count":1625,"subscribers_count":236,"default_branch":"master","last_synced_at":"2025-05-12T14:47:23.520Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mik3y.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.txt","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2013-06-30T23:17:45.000Z","updated_at":"2025-05-12T09:16:39.000Z","dependencies_parsed_at":"2023-01-14T11:53:38.637Z","dependency_job_id":"c1186dd5-9592-4543-9522-9c8f0375ce75","html_url":"https://github.com/mik3y/usb-serial-for-android","commit_stats":null,"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mik3y%2Fusb-serial-for-android","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mik3y%2Fusb-serial-for-android/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mik3y%2Fusb-serial-for-android/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mik3y%2Fusb-serial-for-android/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mik3y","download_url":"https://codeload.github.com/mik3y/usb-serial-for-android/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253969267,"owners_count":21992265,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T19:00:49.305Z","updated_at":"2025-05-13T15:13:17.689Z","avatar_url":"https://github.com/mik3y.png","language":"Java","funding_links":[],"categories":["Java","Libraries","Libs","Android","Other"],"sub_categories":["\u003cA NAME=\"Embedded\"\u003e\u003c/A\u003eEmbedded","Android libraries"],"readme":"[![Actions Status](https://github.com/mik3y/usb-serial-for-android/workflows/build/badge.svg)](https://github.com/mik3y/usb-serial-for-android/actions)\r\n[![Jitpack](https://jitpack.io/v/mik3y/usb-serial-for-android.svg)](https://jitpack.io/#mik3y/usb-serial-for-android)\r\n[![Codacy](https://app.codacy.com/project/badge/Grade/ef799bba8a7343818af0a90eba3ecb46)](https://app.codacy.com/gh/kai-morich/usb-serial-for-android-mik3y/dashboard?utm_source=gh\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_grade)\r\n[![codecov](https://codecov.io/gh/mik3y/usb-serial-for-android/branch/master/graph/badge.svg)](https://codecov.io/gh/mik3y/usb-serial-for-android)\r\n\r\n# usb-serial-for-android\r\n\r\nThis is a driver library for communication with Arduinos and other USB serial hardware on\r\nAndroid, using the\r\n[Android USB Host Mode (OTG)](http://developer.android.com/guide/topics/connectivity/usb/host.html)\r\navailable since Android 3.1 and working reliably since Android 4.2.\r\n\r\nNo root access, ADK, or special kernel drivers are required; all drivers are implemented in\r\nJava.  You get a raw serial port with `read()`, `write()`, and [other functions](https://github.com/mik3y/usb-serial-for-android/wiki/FAQ#Feature_Matrix) for use with your own protocols.\r\n\r\n## Quick Start\r\n\r\n**1.** Add library to your project:\r\n\r\nAdd jitpack.io repository to your root build.gradle:\r\n```gradle\r\nallprojects {\r\n    repositories {\r\n        ...\r\n        maven { url 'https://jitpack.io' }\r\n    }\r\n}\r\n```\r\n\r\nStarting with gradle 6.8 you can alternatively add jitpack.io repository to your settings.gradle:\r\n```gradle\r\ndependencyResolutionManagement {\r\n    repositories {\r\n        ...\r\n        maven { url 'https://jitpack.io' }\r\n    }\r\n}\r\n```\r\n\r\nIf using gradle kotlin  use line\r\n```gradle.kts\r\n        maven(url = \"https://jitpack.io\")\r\n```\r\n\r\nAdd library to dependencies\r\n```gradle\r\ndependencies {\r\n    implementation 'com.github.mik3y:usb-serial-for-android:3.9.0'\r\n}\r\n```\r\n\r\n**2.** If the app should be notified when a device is attached, add \r\n[device_filter.xml](https://github.com/mik3y/usb-serial-for-android/blob/master/usbSerialExamples/src/main/res/xml/device_filter.xml) \r\nto your project's `res/xml/` directory and configure in your `AndroidManifest.xml`.\r\n\r\n```xml\r\n\u003cactivity\r\n    android:name=\"...\"\r\n    ...\u003e\r\n    \u003cintent-filter\u003e\r\n        \u003caction android:name=\"android.hardware.usb.action.USB_DEVICE_ATTACHED\" /\u003e\r\n    \u003c/intent-filter\u003e\r\n    \u003cmeta-data\r\n        android:name=\"android.hardware.usb.action.USB_DEVICE_ATTACHED\"\r\n        android:resource=\"@xml/device_filter\" /\u003e\r\n\u003c/activity\u003e\r\n```\r\n\r\n**3.** Use it! Example code snippet:\r\n\r\nopen device:\r\n```java\r\n    // Find all available drivers from attached devices.\r\n    UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);\r\n    List\u003cUsbSerialDriver\u003e availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager);\r\n    if (availableDrivers.isEmpty()) {\r\n        return;\r\n    }\r\n\r\n    // Open a connection to the first available driver.\r\n    UsbSerialDriver driver = availableDrivers.get(0);\r\n    UsbDeviceConnection connection = manager.openDevice(driver.getDevice());\r\n    if (connection == null) {\r\n        // add UsbManager.requestPermission(driver.getDevice(), ..) handling here\r\n        return;\r\n    }\r\n\r\n    UsbSerialPort port = driver.getPorts().get(0); // Most devices have just one port (port 0)\r\n    port.open(connection);\r\n    port.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE);\r\n```\r\nthen use direct read/write\r\n```java\r\n    port.write(request, WRITE_WAIT_MILLIS);\r\n    len = port.read(response, READ_WAIT_MILLIS);\r\n```\r\nor direct write + event driven read:\r\n```java\r\n    usbIoManager = new SerialInputOutputManager(usbSerialPort, this);\r\n    usbIoManager.start();\r\n    ...\r\n    port.write(\"hello\".getBytes(), WRITE_WAIT_MILLIS);\r\n    \r\n@Override\r\npublic void onNewData(byte[] data) {\r\n    runOnUiThread(() -\u003e { textView.append(new String(data)); });\r\n}\r\n```\r\nand finally:\r\n```java\r\n    port.close();\r\n```\r\n\r\nFor a simple example, see\r\n[UsbSerialExamples](https://github.com/mik3y/usb-serial-for-android/blob/master/usbSerialExamples)\r\nfolder in this project.\r\n\r\nSee separate github project [SimpleUsbTerminal](https://github.com/kai-morich/SimpleUsbTerminal) \r\nfor a more complete example with:\r\n* Background service to stay connected while the app is not visible or rotating\r\n* Flow control \r\n\r\n## Probing for Unrecognized Devices\r\n\r\nSometimes you may need to do a little extra work to support devices which\r\nusb-serial-for-android doesn't (yet) know about -- but which you know to be\r\ncompatible with one of the built-in drivers.  This may be the case for a brand\r\nnew device or for one using a custom VID/PID pair.\r\n\r\nUsbSerialProber is a class to help you find and instantiate compatible\r\nUsbSerialDrivers from the tree of connected UsbDevices.  Normally, you will use\r\nthe default prober returned by ``UsbSerialProber.getDefaultProber()``, which\r\nuses USB interface types and the built-in list of well-known VIDs and PIDs that\r\nare supported by our drivers.\r\n\r\nTo use your own set of rules, create and use a custom prober:\r\n\r\n```java\r\n// Probe for our custom FTDI device, which use VID 0x1234 and PID 0x0001 and 0x0002.\r\nProbeTable customTable = new ProbeTable();\r\ncustomTable.addProduct(0x1234, 0x0001, FtdiSerialDriver.class);\r\ncustomTable.addProduct(0x1234, 0x0002, FtdiSerialDriver.class);\r\n\r\nUsbSerialProber prober = new UsbSerialProber(customTable);\r\nList\u003cUsbSerialDriver\u003e drivers = prober.findAllDrivers(usbManager);\r\n// ...\r\n```\r\n*Note*: as of v3.5.0 this library detects CDC/ACM devices by USB interface types instead of fixed VID+PID,\r\nso custom probers are typically not required any more for CDC/ACM devices.\r\n\r\nOf course, nothing requires you to use UsbSerialProber at all: you can\r\ninstantiate driver classes directly if you know what you're doing; just supply\r\na compatible UsbDevice.\r\n\r\n## Compatible Devices\r\n\r\nThis library supports USB to serial converter chips with specific drivers\r\n* FTDI FT232R, FT232H, FT2232H, FT4232H, FT230X, FT231X, FT234XD\r\n* Prolific PL2303\r\n* Silabs CP2102, CP210*\r\n* Qinheng CH340, CH341A\r\n\r\nsome other device specific drivers\r\n* GsmModem devices, e.g. for Unisoc based Fibocom GSM modems\r\n* Chrome OS CCD (Closed Case Debugging)\r\n\r\nand devices implementing the generic CDC/ACM protocol like\r\n* Qinheng CH9102\r\n* Microchip MCP2221\r\n* Arduino using ATmega32U4\r\n* Digispark using V-USB software USB\r\n* ...\r\n\r\n## Help \u0026 Discussion\r\n\r\nFor common problems, see the [FAQ](https://github.com/mik3y/usb-serial-for-android/wiki/FAQ) wiki page.\r\n\r\nAre you using the library? Add your project to \r\n[ProjectsUsingUsbSerialForAndroid](https://github.com/mik3y/usb-serial-for-android/wiki/Projects-Using-usb-serial-for-android).\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmik3y%2Fusb-serial-for-android","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmik3y%2Fusb-serial-for-android","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmik3y%2Fusb-serial-for-android/lists"}