Android Accessory in Python
Proof of conception of data exchange between an Android device and a computer through USB, based on the Android Open Accessory protocol and Python. This can be used to use the sensors of the smart device from a standard computer application, in the context of a robotics project for example.
To install the Android application, have a look at the latest release and download the APK from your smartphone.
For the client, clone this repository to your local environment. The main dependencies is PyUSB
, which is a project now hosted on GitHub. I am used to install it with sudo pip install pyusb
on a Linux box. Some reports that it is more involved to install it on other OS.
Superuser privileges are required to start the client, since the USB node is assigned to the root user. This will be improved in a next version.
From the repository root folder, start the client with the command:
$ sudo python client/pyaccessory.py
Looking for an Android device
The client is now started and it is waiting for your Android device. Plug with a USB cable.
A pop-up should be displayed the first time, and the application will be automatically launched. You are ready to communicate from the application to the Python client, and the other way around.
Imagine a sensor and an actuator. The sensor value is managed by the client. The value of the senor is read by the application but it is never modified by the application directly. From the application, you can control a virtual actuator that will send a command to change the value of the sensor.
There is sometime a random deviation, and the value of the sensor is modified without command (as a proof that the application reads the sensor value). The client displays the value of the sensor, and the commands received from the application.
Contributions are welcome. The code is totally unstable, so there are many ways to improve it. Several flaws have been identified, have a look at the issues.
To get an hand-on the code and the Android Open Accessory protocol, you can refer to my blog post. A list of useful links is provided at the end.
Copyright 2016 Arn-O under the MIT license.