Gameboy-like keys and D-Pad for Android - android

I wanted to make an RPG for Android 2.3 Mobile Phone and thought that the good old Gameboy had the perfect format for such games. So I want to build a "Case" with a D-Pad and a few keys and connect them with the Android Device over USB. I don't want Bluetooth, because it needs to much energy. I thought about giving the Case its own Battery Cell and maybe loading the Android Device with it. So my Question is:
How can I access the Keys of this Case from the Android Device?

You might consider the Android Open Accessory Development Kit.
Even if you don't want to buy the ADK, the above link has information that will be useful to you in developing an interface to your accessory. In particular, the section on implementing the accessory protocol and the following section on how the ADK implements the protocol should prove informative. In addition, you'll probably want to look at the USB Accessory link which contains a section concerning communication with an accessory.

You can use USB on devices that have a host USB port unfortunately, not many devices have this. Your other options are bluetooth or wifi both can be accomplished in a multitude of ways. If you Google Arduino + Android I believe you will find examples of people connecting hardware to Android devices via Arduino. This is not the only way to do it, just an example of one way you could do it.
Android USB documentation
http://developer.android.com/guide/topics/usb/index.html
EDIT
You, could I suppose, use Arduino as the USB host also and use accessory mode on the Android end. In any case this none of these options are incredibly straightforward and you will need to do a lot of research to accomplish what you are envisioning.

Related

USB Power Delivery Power Role Swap in Android

TLDR
When I connect two USB-C Android phones together in the USB Preferences I can hot swap the power roles via the "Charge connected device" option.
How can I duplicate this functionality outside of two Android phones connecting together (i.e. when I connect my own custom 3rd party hardware)? I understand I will have to implement or make use of some USB stack hardware/firmware on the 3rd party hardware side, but I'm not sure exactly what standards are necessary. For example Digi-key produced a nice article describing the various USB specifications. So for Android Power Swapping comparability, do I need USB PD 3.0, or would USB Type-C 1.2 work, or USB BC 1.2, etc.?
Also I would like a link to some official confirmation that Android Open Accessory is NOT the current way to handle powering an Android phone from an external device despite what is suggested by the official dev docs. Instead it appears that USB-PD, or some other USB type C standard with Android remaining the DATA Host, while the external device being the POWER SOURCE is the current standard way of doing this. I haven't found anything about this in the Android dev docs so far and it seems very strange to me that something they haven't updated since 2012 is still in the official docs as the ONLY way of doing things.
It appears this USB Power Swapping functionality is not listed in the Android dev docs that I could find, but you can find the source code responsible for the hot swapping of power roles here
Detailed Background
I have a project where I need to power an Android phone via an external battery powered MCU. According to the android dev docs on usb connectivity, I'm supposed to have my MCU act as a host and implement the Android Open Accessory Protocol (AOA).
Looking for how to do so turned out to be a fairly deep rabbit hole, but in short I found manufacturers like FTDI that make dedicated ICs for handling AOA protocol, but their examples haven't been updated since 2012 and the AOA is hardcoded so any future changes to the protocol would require making new hardware.
I also have worked on the IOIO Board repo a bit (from the Android side), but looking into the firmware used on the PIC24F it looks like the original developer created a custom USB-Host stack that implemented the AOA and makes several comments in the repo wiki about how this is VERY hard.
Finally, I found repo that implements AOA on a MAX3421E. It appears this may have stemmed off or related to other projects in 2011/2012 surrounding the AOA like the Arduino ADK which is now obsolete.
It summary it appears anything surrounding the AOA or "ADK" is completely user or 3rd-party driven and nothing officially supported by Android/Google. For example, in the docs there is a link to viewing the "source code" for the ADK, but this link redirects you back to the same documentation (not the source code). I actually found the mentioned source code from a copy of it on an Instructables page by a 12 year kid with a link to the official repo. You're free to have a look at this code, but it is OLD and does not work with the current Android build system and you'd find the USB_Host_Shield_2.0 project to be much more well organized and easy to understand, which is based on the hardware from what I understand.
With how little support Android appears to be providing for this, it looks like it was all but abandoned since 2012 a year after it was introduced in 2011. Thus, I was looking for a more future-proof solution to power the Android device from an external controller. From what I can tell the modern way to approach this is to use a USB-PD controller to allow power roles to be independently selected from the data roles. For example, if I connect to Android phones with a USB-C cable, it appears the orientation of the plug/cable determines the Host/Accessory role with the default Power Source being the accessory. (i.e. from the screenshot before, this is the Host since "USB Controller By" set to "This device" and the Power Source is the opposite phone since "Charge connected device" is disabled here (and enabled on the other device).
I'll go ahead an post a potential answer, though I'm hoping for some official answer to override my assumptions and guesses.
From what I can see in the source code handling this functionality, there are three power roles of {POWER_ROLE_NONE, POWER_ROLE_SINK, POWER_ROLE_SOURCE}.
Following these imports, I can see here that there is a clear separation between power roles and data roles.
If I plug in the phone to a USB port not supporting USB-PD, this "Charge connected device" option disappears. It also does not appear when connecting the phone to a USB-PD charger. So I'm assuming the connected device has to show that is a Dual Role UFP | DFP in order for this option to appear.
If anyone can add any official documentation on this, and what USB standard (3.0, 3.1, 3.2, 4.0, etc.) is necessary and how this relates to which Android versions are supported for this functionality, etc., this would override this answer.

controlling Embedded system from MOBILE. ANDROID or iOS? suggestions and explanations please

As a part of feasibly study. I need to choose between Android or iOS for integrating it with an embedded system.
Basically, that embedded system will have an AVR or a PIC Microcontroller. I want to establish a communication between a mobile and that particular system.
Need some wireless technology for communication (bluetooth,wifi,internet etc..)
Micro Controllers have communication ports like UART, USART etc..
It really depends on the kind of communication you need.
I particular, if you have a normal WIFI connection and your controller can work with receiving & sending your data via wifi, you may go iOS or Android.
If however you need some kind of free format serial communication, you need to go Android, serial cable via USB.
recarding other factors, I guess it really is just a personal taste issue.
Could you give more info on how & what needs to be communicated and what kind of communication device you have between your phone and the device itself.
Not sure if this is similar to what you have in minde, but you might look at this: http://www.arduino.cc/ being probably the best known example in this context.
Using some serial to bluetooth module would be the most easier to implement.
I would go with Android unless your target audience are photographers. Seriously. Also, with iOS you need to be careful. For instance you want to use BlueTooth, but not all iOS devices will connect to, say, the Bluetooth protocol for a keyboard. (Ah! You didn't know there were more then one Bluetooth protocol did you?) And I don't think any iOS device will let you connect using the Bluetooth serial port protocol.
With Android you can jump in and start flying immediately by using the (or a copy of) the PIC 24F based IOIO board. And if you are an Android / Eclipse developer (I think) you can down load and use the IOIO JAVA / Android libraries. I have been told this makes programming the IOIO board just about as easy as programming an Arduino. Especially if you are well versed in JAVA, Android and the Eclipse editor. Add to this the IOIO board can be a host to the Android (i.e. connected by wired USB) or host to some Bluetooth modules (i.e. connect to the Andoid's bluetooth radio).
If you don't want to go it along you can buy the Microchip Android Development Kit (ADK) board which is also a PIC 24F based "USB wired" using AOA protocol to connect to an Android. I say "not going it alone" as I would expect you can then get limited support from Microchip w.r.t. their hardware (the ADK board), software (Android) and firmware (PIC ADk board). This solution, however, does not have built in Bluetooth support. I am guessing you can add it, it's just not part of the ADK software/firmware that Microchip put together.

Communicate with external MIDI device from Android device

What classes are available for Android platform to communicate (in/out) with external MIDI device? I have HTC Desire smartphone, it has USB port, I'd assume it is possible to connect it to a MIDI synthesizer, using standard USB cable + [Type A -> Mini A] converter. I'd like to write a MIDI sequencer app that would be able to record MIDI stream from the synthesizer and then play it back later.
Short answer: None. Slightly longer answer: On the HTC Desire there is no built-in support for USB host mode (which you need, since the usb-midi adapter would be the USB client).
(Android 3.1 does have some support for USB Host mode, but that's not available for the HTC Desire)
If you're not afraid of a soldering iron, you could go the midi-over-bluetooth route: http://nettoyeur.noisepages.com/2011/01/midi-over-bluetooth-part-iii-new-hardware/
Much has changed on this front. The following library allows for MIDI i/o with a USB OTG adapter on API 12+:
https://github.com/kshoji/USB-MIDI-Driver
It's far from perfect, and in my testing, pretty crashy, but it should at least be a good starting point for someone looking for the relevant classes.
As #edovino said, you need USB host mode, and then drivers.
If you don't mind rooting around your phone, and the hardware supports it, you do have some options. Check out this link: http://sven.killig.de/android/N1/2.2/usb_host/
This guy was able to get audio, video, keyboard, and some other stuff working. He includes audio/MIDI drivers.
Yes, as pointed above, it is not feasible using the phone because it does not provide USB-host capability. I have been working religiously over the past few months to make an XY-controller for my synthesizer so that I can transmit controller values to use for performances. I reckon, that is what you want to do with additional functionality.
Bluetooth is definitely an option and if you look up for libpd, Peter Brinkmann himself has addressed this issue and acknowledged that Bluetooth dongles for MIDI are not far away.
WiFi is also something one may be willing to look at. Using rtpMIDI, we can create sessions on the PC side of things and use just about any WiFI enabled MIDI device to transmit/receive data. IF you are looking to control software synthesizers using a phone, this seems ideal. TouchDAW and TouchOSC, applications on android, make use of this feature.
With the USB-Android driver, the only problem I see is no support for isochronous transfers using USB host. So, we cannot guarantee latency deterministic. But, considering no other bus accessories attached, the performance seems pretty decent in my tests.

How to communicate with a USB device from Android tablet?

From a year ago, Is there a way to communicate with USB devices on Android? this didn't look like a common requirement, but tablets have evolved, and hopefully, the OS has, as well.
I need to operate a simple USB relay card from my Curtis LT8025 tablet, currently running 2.1 patched.
I'm also a newcomer to both Android and java, so relatively clueless!
No need for bi-directional communication, just a simple serial command out to the device.
Any suggestions?
Thanks!
Dave
Sadly, there is currently no standard API to achieve wired communication with Android devices. I was facing a similar issue a while back (see Android: Communicating with a USB device which acts as host ).
I was able to successfully implement the solution provided by CommonsWare. Leave a comment if you need more help regarding this and I can provide details.
Edit (more details) -
Basically, I narrowed down to two possible solutions for this problem:
Modify the Android source itself to include custom drivers for whatever purpose you need and install this in your tablet. Since its mostly based on Linux, if you develop the drivers for Linux, the same can be used in Android with a little modification. This solution is simpler to develop, but not practical commercially if you are not providing the tablet/phone yourself.
Make your USB device act as an host and implement the ADB driver/command-set in your device. When connected, you can issue "adb forward" to forward tcp ports so you can interact with your Android apps and have two way communication between the device and the app.
I used the second method and it works flawlessly. But its only practical if you are making USB host devices. for USB slaves, first method is the only way I recon.
If you are using a serial device and have the ability to talk to it over native serial, you might want to consider IOIO (see http://ytai-mer.blogspot.com/2011/04/meet-ioio-io-for-android.html for more details).
I'm building an Android custom system. I did connect several devices on the USB. I looked to connect a device on the OTG port, the one that usually gets out of a tablet on which you use ADB. I gave up. This is a nightmare. I don't think you can use ADB on the OTG USB that is currently a device and expect to be able to use another device like a USB to serial converter. That means that you loose the whole ADB toolchain for debugging when you want to use the port as a host. On top of that, the USB OTG drivers you have for your tablet was probably not very well tested in host mode since it's not really used that way. So lots of headakes.
The simple way that I found was to use the second USB port on the CPU. This one is a plain HOST port (unfortunately limited to 12 Mbit/s). Unfortunately, I don't know if there are any tablet out there with 2 USB port available from outside (One OTG and one host).
If you get a set-up with two USB port (one HOST) then it's possible to compile as a module (drivername.ko), a usb to serial converter. There are several chipset supported in the kernel source tree and I already used a few of them and it works.
hope this bit of info is helpful.

Android USB I/O

OK, so i have seen all the stuff about how acting as a USB host is impossible on vanilla android, but is there anything in the Android API that would allow an app to override the default USB behavior in order to manually control the USB i/o responses, in order to support some other protocol? I have not seen anything that would facilitate this, but is it possible without hacking the kernel?
This seems like the sort of thing which should be relatively easy, but i haven't found anything. Forgive me if i've been googling incorrectly.
I believe that the stock kernel does not include the correct drivers for this. You need to be able to root your device and you need one of the devices capable of acting as a USB host.
See this page, http://sven.killig.de/android/N1/2.2/usb_host/
The linked page had source for the kernel and drivers you'll need ... GOOD LUCK, you'll need it
Last year I worked on an application that had a PC component and a smartphone component, and the two were communicating over a USB connection (using ADB port forwarding and regular sockets). So, if you want to do something like that, I'll show you how I did it, maybe it's helpful.
USB On-The-Go (USB OTG or just OTG) is a specification first used in
late 2001 that allows USB devices, such as tablets or smartphones, to
act as a host
#Wikipedia, If anybody is still looking for it
In order to manage usb traffic your device needs to become a host according to USB specification.

Categories

Resources