开发者

Android USB host-to-serial connection?

开发者 https://www.devze.com 2023-03-26 03:09 出处:网络
Apparently with Android 2.3.4 and 3.1 one can now access USB accessories. I have a Ardupilot Mega (based on Arduino) board with a USB cable connected to my laptop, and I can connect to it using a sim

Apparently with Android 2.3.4 and 3.1 one can now access USB accessories.

I have a Ardupilot Mega (based on Arduino) board with a USB cable connected to my laptop, and I can connect to it using a simple serial communications program over COM7 and 115,200 baud. This allows me into the command-line interface, and I can issue commands and get logs.

开发者_开发问答

Is it possible to write an Android app that will communicate over USB to my Ardupilot Mega board?

I've seen many similar threads, but most of them were pre-USB host.


usb-serial-for-android is my open source library written for exactly this need. It supports FTDI and CDC-ACM usb serial devices using Android's USB host support; no root or ADK necessary. It can talk most Arduinos.

The project is still in its early days, but the basic support has worked well enough for several projects. There is also a discussion list where you can get help.


Unfortunately the library from mik3y's answer (see here: mik3y/usb-serial-for-android) seems to be long dead. It has many problems and waiting pull requests. Also the LGPL licence prevents anybody to fork it and maintain it.

But don't lose your hope, there's a working replacement and it's under the MIT licence. felHR85/UsbSerial.

EDIT: I found a maintained fork of mik3y's library. But the licence or readme is not updated, so I suppose the owner doesn't have a connection to mik3y and simply took it and improved it. I hope he won't get into any trouble because of the licence, because we need this library. See kai-morich/usb-serial-for-android

EDIT2: It seems that all of these libraries are maintained again, mik3y joined forces with kai-morich and they're working together now.

EDIT3: mik3y/usb-serial-for-android is under MIT license now. And still maintained in 2022.


Maybe. Check out the Android Open Accessories announcement on the Android Developers Blog. The Arduino Mega ADK is compatible. Not sure about the Ardupilot Mega.

From their page:

The Android 3.1 platform (also backported to Android 2.3.4) introduces Android Open Accessory support, which allows external USB hardware (an Android USB accessory) to interact with an Android-powered device in a special "accessory" mode. When an Android-powered powered device is in accessory mode, the connected accessory acts as the USB host (powers the bus and enumerates devices) and the Android-powered device acts as the USB device. Android USB accessories are specifically designed to attach to Android-powered devices and adhere to a simple protocol (Android accessory protocol) that allows them to detect Android-powered devices that support accessory mode. Accessories must also provide 500mA at 5V for charging power. Many previously released Android-powered devices are only capable of acting as a USB device and cannot initiate connections with external USB devices. Android Open Accessory support overcomes this limitation and allows you to build accessories that can interact with an assortment of Android-powered devices by allowing the accessory to initiate the connection.

Note: Accessory mode is ultimately dependent on the device's hardware and not all devices will support accessory mode. Devices that support accessory mode can be filtered using a "uses-feature" element in your corresponding application's Android manifest. For more information, see the USB Accessory Developer Guide.

The following list of distributers are currently producing Android Open Accessory compatible development boards:

The Arduino Store provides the Arduino Mega ADK (in EU nations or non-EU nations) that is based on the ATmega2560 and supports the ADK firmware. DIY Drones provides an Arduino-compatible board geared towards RC (radio controlled) and UAV (unmanned aerial vehicle) enthusiasts. Microchip provides a PIC based USB microcontroller board. Modern Device provides an Arduino-compatible board that supports the ADK firmware. RT Corp provides an Arduino-compatible board based on the Android ADK board design. Seeed Studio provides an Arduino-compatible board that supports the ADK firmware. SparkFun's IOIO board now has beta support for the ADK firmware.


You can check out the library described in Slick USB 2 Serial Library.

It enables common USB-to-serial adapters to work with Android devices that have USB host mode without needing to root.


http://slickdevlabs.com/

I am currently using the library in my own app, however I think you can get away with just the app that slick has on the market. There are two free apps and one is the "pro" version of one of the free ones; search slick usb in Google Play.

It does use HOST mode and you can change the baud rate to whatever you need.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号