9

How do I write an Arduino sketch and an Android application to talk to each other over a standard USB cable?

6

Android devices usually don't have a USB host: they expect to be connected to some smarter device like your computer. Same goes with Arduino. For this reason Arduino made the Mega ADK (that means Accessory Development Kit).

Mega ADK and Due act as USB hosts and can be connected directly to your Android phone. If you already have a board, another option is to get a USB host shield to add USB host capababilities.

Your sketch will tell the phone what kind of accessory application it is and your phone will download the appropriate application from the store.

There is a book about connecting Arduino to Android.

  • There are converters from mini USB to USB-A host. – apnorton Feb 16 '14 at 21:55
  • @anorton Yes: those are OTG cables... see my post. – Anonymous Penguin Feb 18 '14 at 23:47
  • The premise of this answer was outdated years before it was posted - most contemporary android devices were intended to have USB host support, though there are cases where some quirk of the design leaves it broken. – Chris Stratton Oct 1 '14 at 17:38
3

You never mentioned your tablet model... or Arduino model

There are some tablets designed to work with USB flash drives and printers. This is called OTG (on the go.

You need:

  • A tablet supporting OTG
  • An OTG adapter that fits into your tablets USB slot and is compatible
  • The Arduino Uno Communicator App
  • Arduino Uno (or clone) [Note: It says that it works with Atmega16U2 or Atmega8U2 programmed as a USB-to-serial converter so I would assume that that would cover a few boards more than the Uno.)

Another alternitive is to look into Bluetooth (Note: I just picked a random link but there are hundreds of similar BT adapters)

  • Note that standard Android USB host mode does not support flash drives with any operating system functionality (though a few vendor builds do) - rather, it exposes a fairly raw USB host API to application code. – Chris Stratton Oct 1 '14 at 17:39
2

The USB protocol requires one end to be a "host" and the other end to be a "peripheral", and it doesn't work if the devices at both ends of the cable are "peripherals". Alas, most Arduinos and many early Android devices are "peripherals", so connecting such devices with a standard USB cable doesn't work.

Some modern Android devices support "OTG", so in theory one could make the Android end of the cable the "host". Has anyone gotten this to work?

Another approach is to somehow make the Arduino end of the cable the "host", and the Android end of the cable the "peripheral". That's the approach taken by

  • Microbridge (a) (b)
  • The IOIO board (a) (b)
  • The Android Accessory Development Kit (ADK) (a) (b) (c)

(The Amarino (a) and Cellbots (a) (b) take yet another completely different approach).

1

Processing is a great place to get started with device to device communication.

The interface and language are very similar to Arduino and there are many examples to get you started.

http://playground.arduino.cc/Interfacing/Processing

  • 2
    Does that run on Android? – Anonymous Penguin Feb 17 '14 at 14:01
  • @AnnonomusPerson Yes, processing for android – Faux_Clef Feb 18 '14 at 23:09
  • @Faux_Clef Hmm didn't know that. I still don't know if it's the best for Android, that link that you posted didn't seem like it was very stable... I know that processing has USB support but I don't know if you can do that on Android... – Anonymous Penguin Feb 18 '14 at 23:46
-1

You can connect Android and Arduino with usb and use the easy tool App inventor 2 for android

Did you try this new application : https://play.google.com/store/apps/details?id=bp.usbbridge.appinvDemo and full version : https://play.google.com/store/apps/details?id=bp.usbbridge.appinv

Find Videos about Explications : USB OTG Bridge Serial UART for APP Inventor 2 and ARDUBLOCK on youtube

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.