Java USB serial access on Android
pedward
Posts: 1,642
Hi everyone. I got an Android tablet recently and was playing with the USB On-The-Go functionality. When I plug a propeller board into the USB port, the kernel registers the device, but no Unix driver claims it.
I started researching and found that Android has USB host driver capabilities built-in to the API from version 11 (3.1) onward.
I went to the Google project http://code.google.com/p/usb-serial-for-android/ and cloned the Git repo to my computer.
Being a novice at Android development, it took a few minutes to interpret the errors I was getting during build. Ultimately the only thing I had to do was create a 'res' directory in the library project, and I added the SDK files (right click on project, 'Android->Add SDK support').
I built the library first, then the example program and uploaded them to my tablet. Now when I plug a Propeller (with FTDI chip) into the USB port, the example application launches and reads data from the USB serial device!
This is super cool because it opens up some opportunities to make the Propeller a popular hacker/maker accessory to Android tablets and phones based on Android 4.0 or above!
I attached the apk from the example program, if anyone wants to try it.
I started researching and found that Android has USB host driver capabilities built-in to the API from version 11 (3.1) onward.
I went to the Google project http://code.google.com/p/usb-serial-for-android/ and cloned the Git repo to my computer.
Being a novice at Android development, it took a few minutes to interpret the errors I was getting during build. Ultimately the only thing I had to do was create a 'res' directory in the library project, and I added the SDK files (right click on project, 'Android->Add SDK support').
I built the library first, then the example program and uploaded them to my tablet. Now when I plug a Propeller (with FTDI chip) into the USB port, the example application launches and reads data from the USB serial device!
This is super cool because it opens up some opportunities to make the Propeller a popular hacker/maker accessory to Android tablets and phones based on Android 4.0 or above!
I attached the apk from the example program, if anyone wants to try it.
Comments
Jim
Looks like I need a new tab/phone:)
cool ! You wrote
So this means the tablet was able to receive sending data from the prop with the prop using FullDuplexSerial or similar?
Did you already test if code can be downloaded to RAM or EEPROM?
Is the sourcecode of the propellent.dll or the propeller-tool available so that someone can port it to android?
best regards
Stefan
Host most is present in Android 3.1 up. Android 3.x was a closed source release that only appeared on tablets. ICS/4.0 was the first open source release that included this and was present on phones and tablets. I have an ICS phone, but I haven't confirmed if this works (the display is broken). I have confirmed this working on an ICS tablet (Motorola Xyboard 8.2).
Devices like the IOIO are USB hosts themselves, so they work with a larger variety of phones, but they aren't powered by Propellers.
Today I managed to get a response from FT232R from Quickstart on my Android 2.3.4 phone. (Sony Xperia Mini Pro sk17i)
Yes, Android 2.3.4 does not officially support USB Host mode, so this weekend I read a bunch of stuff about all this and crossed my fingers and rooted my phone.
I downloaded FTDI's D2XX drivers for Android (Beta) and their example app, D2XXSample.
Had to change a path to the .so (the driver) in a source file and recompile the example. ran it and it works.
I had to make my own OTG cable. Went to an electronics store and bought the cheapest micro A and mini A USB cables, cut them open, soldered the wires together, soldered the sense and the ground pins on the micro A side to make it micro B (pins 4 and 5).
I managed to compile FTDI's example application in eclipse on my PC and download it to my phone via WiFi, while Quickstart was connected to the phone via USB. Haven't tried debugging yet, though.
If anyone wants to walk through all this, I'll be glad to try and explain what I did to get it running.
What I'd like to see now is a way to download propeller applications from my PC via WiFi via my phone to the Quickstart board.
Is the download protocol open and if so, where can I find it?
Note: If you're unsure if your phone has USB Host hardware capability, check if it's micro USB socket is rectangular, rather than trapezoidal.
We may not have BradC and the wonderful BST to hack on but now we have fully open source equivalents.
I'm sure with the Andriod NDK one could get the open source spin compiler and loader compiled and running on your phone/tab. Perhaps even Simple IDE as now there is support for Qt on Android.
Or as you can now get Debian on Android just compile all those tools on your device and away you go.
About half a year ago I got the open source spin compiler working under android (http://forums.parallax.com/showthread.php/140189-Android-Spin-Tool?p=1103003&viewfull=1#post1103003). At the time I had no USB drivers for my tablet, so could not connect to the propeller. Time to try again with peward's discovery
I design android apps sometimes for the company I work for ( mainly just calculator type applications for machinists down on the shop floor )
When I used the Higher level API's no ones phone would run them, and I had to recreate my apps in the 2.1 or 2.8 whatever it is, api so others could use them...
Just saying..
However, there are at least some 'old' models of, in particular, phones that aren't getting upgrades from the vendors, including some Sony Xperia ones. That's presumably to 'force' users to buy new devices.
For tablets (which are maybe more useful for possible Propeller work) I believe the situation is much better, after all they should all be at 3.x as a minimum.
-Tor
There are other devices, like the IOIO, which are intended for communication with client only phones.
I've only started playing with Android programming, but you can specify a min and target API level, I'm assuming that if you attempt to use an API that isn't present in the min API level, it will throw an error during compilation.
I would take a guess that 95% of the population is using a 2.x device... Even the galaxy 3s were 2.x devices....
I say that because i assume most of the population buys ipads over androids ( not the tech people, just avg users etc.. etc.. )
2.3.3-2.3.7: 45%
2.2: 8%
4.0x: 29%
4.1x: 12%
Everything else: Not much.
-Tor
I did say it was a guess ;p
We have developed an Android data acquisition module that is propeller based that can be read and write data via USB, Bluetooth, or WiFi using an Android phone or tablet.
More information about our module is here: http://www.controlcapture.com/androiddaqmod