robotrory / py-android-accessory

Android Accessory in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

py-android-accessory

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.

Installation and setup

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.

Quick start

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.

PyAccessory app screenshot

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.

PyAccessory client screenshot

Contributions

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.

License

Copyright 2016 Arn-O under the MIT license.

About

Android Accessory in Python

License:MIT License


Languages

Language:Java 50.8%Language:Python 49.2%