FLORA communicating via USB with Android

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jcolnago
 
Posts: 5
Joined: Fri Jan 24, 2014 3:11 pm

FLORA communicating via USB with Android

Post by jcolnago »

Hi,
I wanted to use my Android phone to connect via USB to FLORA to both power it up and store compass and GPS information.
Is it possible? I've been trying to adapt some solutions for Arduino Uno, but nothing seems to read from the serial port.

Any help would be appreciated.
Thanks!

User avatar
adafruit_support_mike
 
Posts: 67459
Joined: Thu Feb 11, 2010 2:51 pm

Re: FLORA communicating via USB with Android

Post by adafruit_support_mike »

It's possible in theory, but you'd need to decide what kind of data connection you'll use between the Flora and Android device.

To catch a raw Serial stream, you need a program on the Android side that knows how to read those signals. The Arudino IDE does that on a PC, but I don't know what would do the same job on a smartphone.

The most likely alternative would be to program the Flora to act like a USB keyboard. The microcontroller it uses is capable of doing that. Then your phone would just see the equivalent of someone typing information into any program that can read keypresses.

This tutorial page also has information that might be useful: https://learn.adafruit.com/programming- ... id-tablets

User avatar
jcolnago
 
Posts: 5
Joined: Fri Jan 24, 2014 3:11 pm

Re: FLORA communicating via USB with Android

Post by jcolnago »

I would like for it to catch raw serial data. But that seems to not be working.
I'm going to investigate using it as a keyboard.

Thanks.

User avatar
javamind
 
Posts: 2
Joined: Mon Jun 09, 2014 2:14 pm

Re: FLORA communicating via USB with Android

Post by javamind »

Like jcolnago, I am also having trouble communicating with Flora and Teensy 2.0 via USB cable from an Android tablet.
What I did was modify code from both https://github.com/mik3y/usb-serial-for-android and https://github.com/jeppsson/Arduino-Communicator-Client code to use vendor and product ids of both Flora and Teensy. I use the OTG cable from Adafruit to connect to the Flora from a HiSense Sero 7 pro tablet.
The result is only partial success as I am able to send data to the Flora over USB, but cannot read any data. The Flora and Teensy show up as CDC USB devices when queried by apps like USB Host Viewer. I also tried this on Android phones and got same results.

I am learning more about USB, as a result of my quest to get this to work. The issue might be the initialization of the USB interface on the Android side. The same code I use is reportedly working fine with Arduino UNO. I noticed Adafruit's Tony Dicola tutorial for his cocktail mixing Android app had USB cable success. https://learn.adafruit.com/smart-cockta ... r/overview. Could he can look at using the Flora instead of UNO for his project to see if USB can work?

Should I use alternative USB Serial library code in the Flora so it acts more like a UNO? What would you suggest?

Would Adafruit support please escalate this problem to Lady Ada.
Thanks, I like what Adafruit is doing!

User avatar
javamind
 
Posts: 2
Joined: Mon Jun 09, 2014 2:14 pm

Re: FLORA communicating via USB with Android

Post by javamind »

After more analysis I finally found the solution!
The Android code needs to set RTS and DTR, which the github code reference source code do not perform as written.
I added a line
// set RTS and DTR for Flora and Teensy
mUsbConnection.controlTransfer(USB_RT_ACM, SET_CONTROL_LINE_STATE, 3, 0, null, 0, 0);
USB_RT_ACM = 0x21
Verified working Serial USB communication with Flora from an Android tablet using reference code from https://github.com/jeppsson/Arduino-Communicator-Client

jpprietobaez
 
Posts: 3
Joined: Fri Apr 05, 2013 3:57 pm

Re: FLORA communicating via USB with Android

Post by jpprietobaez »

Hi javamind,

I'm also trying to get a FLORA and an android phone to talk via Serial (Trying to capture Serial output onto my phone). I've tried ArduinoDroid and other apps but the results are exactly the same as the ones you had.

Could you please PM or share a copy of the Githubs that you modified please?

Thanks a lot! I'm a bit clueless when it comes to USB.

jpprietobaez
 
Posts: 3
Joined: Fri Apr 05, 2013 3:57 pm

Re: FLORA communicating via USB with Android

Post by jpprietobaez »

javamind wrote:After more analysis I finally found the solution!
The Android code needs to set RTS and DTR, which the github code reference source code do not perform as written.
I added a line
// set RTS and DTR for Flora and Teensy
mUsbConnection.controlTransfer(USB_RT_ACM, SET_CONTROL_LINE_STATE, 3, 0, null, 0, 0);
USB_RT_ACM = 0x21
Verified working Serial USB communication with Flora from an Android tablet using reference code from https://github.com/jeppsson/Arduino-Communicator-Client

jpprietobaez
 
Posts: 3
Joined: Fri Apr 05, 2013 3:57 pm

Re: FLORA communicating via USB with Android

Post by jpprietobaez »

Just wanted to share the steps to get Android 5 to talk receive serial data (USB) from THE FLORA.

Here is a list of steps that worked for me..

1. Made an OTG usb cable
2. Download and setup Android Studio for your phone and OS.
3. Download and import usb-serial-for-android library via the main cradle file into Android Studio (You will need to modify a couple of properties to fully import..once was replacing testPackageName(), for testApplicationId(). Google is your friend
4. Go back to usb-serial-for-android Git page and make sure you do all the steps of the installation. i.e copy device_filters.xml to the right location
5. Once usb-serial-for-android and it's examples are imported you need to modify a couple of the source files to add the FLORA references to the CDC driver. Here is a good explanation of the process http://qnalist.com/questions/4989360/arduino-pro-micro (for the FLORA I had to do it slightly differently. Instead of defining it as ARDUINO_FLORA under the arduino general classification I had to define a new Vendor/Product instance. ADAFRUIT_FLORA.

I added to usbId.java:

public static final int VENDOR_ADAFRUIT = 0x239A;
public static final int ADAFRUIT_FLORA = 0x8004;


added to CdCAc......java file:

supportedDevices.put(Integer.valueOf(UsbId.VENDOR_ADAFRUIT),
new int[] {
UsbId.ADAFRUIT_FLORA,
});


...

6. Enable DTR by adding the following line to the SerialConsoleActivity.java file

sPort.setDTR(true);

Add it just after the line "sPort.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE);"

7. Save, build and run. Have fun.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”