Shop OBEX P1 Docs P2 Docs Learn Events
Java USB serial access on Android — Parallax Forums

Java USB serial access on Android

pedwardpedward Posts: 1,642
edited 2013-05-06 10:25 in Propeller 1
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.

Comments

  • RS_JimRS_Jim Posts: 1,766
    edited 2013-02-04 05:40
    Would this work on an android phone as well?
    Jim
  • Heater.Heater. Posts: 21,230
    edited 2013-02-04 07:29
    Fantastic, just what I have been dreaming of since a year or two back when host support was impossible. Thanks.
    Looks like I need a new tab/phone:)
  • StefanL38StefanL38 Posts: 2,292
    edited 2013-02-04 08:53
    Hi pedward,

    cool ! You wrote
    eads data from the USB serial device!

    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
  • pedwardpedward Posts: 1,642
    edited 2013-02-04 10:09
    At present all this code does is enable serial communication with the Propeller. The ability to download code and program the Prop is something yet to be done.

    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.
  • edited 2013-02-04 16:14
    Hi all,

    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.
  • edited 2013-02-04 17:20
    Okay, I've managed to light up the P23 LED on the Quickstart board by sending "a" from the D2XXSample application. All I needed to do was to change the baudrate in the app.
  • teganburnsteganburns Posts: 134
    edited 2013-02-04 17:29
    This is going to be awesome! Got a new project tonight. :D
  • frank freedmanfrank freedman Posts: 1,983
    edited 2013-02-04 23:59
    If only bradc was still hacking on the bst tool. Just think prop programming on your tablet...... Almost pushes me toward the nexus 10......
  • Heater.Heater. Posts: 21,230
    edited 2013-02-05 00:33
    frank,

    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.
  • rosco_pcrosco_pc Posts: 464
    edited 2013-02-05 03:42
    Heater. wrote: »
    frank,
    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.

    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 :)
  • ZetsuZetsu Posts: 186
    edited 2013-02-07 08:45
    are not most andriod devices still using the 2.1 or 2.8 ( i cant recall exactly ) revision due to 95% of the devices supporting it.
    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..
  • TorTor Posts: 2,010
    edited 2013-02-07 10:27
    I have no numbers to back it up, but my definite impression is that most devices are or will soon be at 4.x - there seemed to be a large movement to 4.0 when it came out. It's true that everything stopped there for a while at 2.x, that's probably because 3.x was a tablet version of Android and everybody waited for 4.0 which was the unified phone/tablet version. And as I see lots of the Android applications updates are now about supporting Jelly Bean - the next 4.x version. My own Asus Transformer Prime has received regular updates from Asus (no choice - they're pushed) and I'm now at 4.1.1
    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
  • pedwardpedward Posts: 1,642
    edited 2013-02-07 11:29
    There are many 2.x devices out there, but those devices rarely support host mode, so they are precluded from direct communication with USB devices in host->client mode. Like was said in post #6, if the connector doesn't have the detents, and is rounded, it's a mini-A connector.

    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.
  • ZetsuZetsu Posts: 186
    edited 2013-02-07 11:44
    iirc there is an xml document that you can change the api level in... the problem really crops up ( atleast in my neck of the woods, omg i cant believe i just said that ) when I try to use a widget that isn't supported by the min api...


    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.. )
  • TorTor Posts: 2,010
    edited 2013-02-07 13:12
    Zetsu wrote: »


    I would take a guess that 95% of the population is using a 2.x device...
    Make that 45%. Found a statistics page, unfortunately I can't paste the link here because the hopeless forum software doesn't let me do that on Android. But it can be found on android.com, developer's section. It goes something like this:
    2.3.3-2.3.7: 45%
    2.2: 8%
    4.0x: 29%
    4.1x: 12%
    Everything else: Not much.

    -Tor
  • ZetsuZetsu Posts: 186
    edited 2013-02-07 13:25
    Right on thanks, about 6 months ago those numbers were fairly different IIRC.

    I did say it was a guess ;p
  • rickfluckrickfluck Posts: 5
    edited 2013-05-06 10:25
    Please be aware that just because an Android device sports Android 4.0 or above, it does not mean that it supports USB Host mode -the Nexus 4 is one prime example.

    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
Sign In or Register to comment.