USB Android Serial


#1

One of my students used a USB on the go cable

to hook an arduino up to his android cell phone to read serial output running the following Android to Serial App

https://play.google.com/store/apps/details?id=jp.ksksue.app.terminal&hl=en

Anyone have any ideas if this will work on the photon? I don’t see any reason why it wouldn’t. Just need to think of some simple .ino program to test it out. As far as powering the photon I think it is a bit dangerous as the mA that are used on your photon would have to be below about 500mA, but for just getting a serial printout, this would be very useful.


Android Serial and Photon problem
Teaching High School Robotics with the Spark Photon
#2

I wouldn’t see why it shouldn’t work, and the “danger” should be marginal becaus USB ports usually have an electronic fuse in case of excessive current draw. If you phone hasn’t you might want to bin it anyway :wink:


#3

Thanks @ScruffR

Got it working after a few bumps. Hooked the Data cable up the wrong way. It needs to be connected to the phone not the Photon.

The USB Serial Monitor Lite Worked on Android KitKat 4.4 but not on my Tablet version 5.1. (Lollipop} Simple to operate, hook up the cable. Gave an error message but then was OK.

Settings --> Open Device and it worked.

int analogValue = 0;    // Hold A0 value = 0-4095
int incomingByte = 0;   // for incoming serial data

void setup()
{
  Serial.begin(9600);
}

void loop() {
  
   analogValue = analogRead(A0);  // pin A0
   Serial.println(analogValue);      
  
  if (Serial.available() > 0) { // read the incoming byte:
   
     incomingByte = Serial.read();
     Serial.println(incomingByte, DEC);
     if (incomingByte == 97){  // ascii code for small letter 'a'
             Serial.println("Wow"); 
     }
  } 
  
  delay(2000);    // probably not a good idea but slows things down so I can see it.
}

What was fairly cool was that you could also send ascii codes. Every time the “Write” button is clicked it send Ascii 10.
The code above tests for Ascii 97 which is small letter “a”

Looks like it does not work

Then it was fine

Here is my setup.

The circled headings are important

Proof that it works

Click “WRITE” and see the number 97 which then prints “Wow”

The higher numbers are the analogRead.


#4

So the Photon can be used as a Cell Phone Dongle! That is fairly cool, except useless unless we can control it. So I thought I would look into a Phonegap (Cordova) App. Of course nothing is easy.

@peekay123

do these serial communication proticals mean anything to you?

CdcAcmSerialDriver
Ch34xSerialDriver
Cp21xxSerialDriver
FtdiSerialDriver
ProlificSerialDriver

The USB ANdroid App I used above on my Android Phone mentions these proticals:

The ARDUINO Supports(FTDI, CDC/ACM)

Looks like the best bet is FTDI but I am not sure.

.

.

I am now trying to get the usb serial stuff working from Phonegap using this blog.

and for particle I found out that the VID and PID was
vid: ‘2b04’,
pid: ‘c006’

using some App called USB DEVICE INFO

which is relevant at the cordovarduino serial plugin site at

Everything seems to work but I just can’t get any serial communication going. The App even connects. Any suggestions?


Teaching High School Robotics with the Spark Photon
#5

@rocksetta, FTDI is basically a device that converts RS232 or TTL Serial to USB signals. So in your case, it is the correct protocol. :wink:


#6

Thanks @peekay123. I got it working, In very draft form. The github site is at

It will be much better when cloud9 makes the Android-SDK docker image I have been asking for (they are working on it, I submitted the dockerfile three weeks ago)

Basically it is an entire Android-SDK, node, python, ant, gradle, apache2 online ubuntu server for free (limitations unless you want to pay, it shuts down every 24 hours, which is fine with me). I have used it to make a phonegap android app .apk ready to download from a webpage to install on your phone in about three clicks.

I will write it up better when I am less exhausted.

Basically anyone who knows how to make webpages should be able to use the photon as an Android Dongle to control whatever they are connected to.

Jeremy


#7

@rocksetta, @peekay123,

I’ve been trying to get my Electron to communicate with my Android device (Lollipop) over the USB OTG cable with no luck. I started by following @rickkas7 tutorial here:

The Android Serial Monitor Lite app simply crashes when I plug in my Electron over OTG, no matter how many times I try it. I dug into the source code and found drivers like the ones mentioned above:

CdcAcmSerialDriver
Ch34xSerialDriver
Cp21xxSerialDriver
FtdiSerialDriver
ProlificSerialDriver

Created a POC Android app and tried all of them and none of them work. My Android phone recognizes the device with the proper Vendor/Product ID but any logic that tries to interact with it in these drivers fails.

I guess I need some help getting set in the right direction. Which of these drivers is supposed to work for the Electron? How does the driver work that allows the Electron to send serial messages to other platforms like Windows (i.e. particle serial monitor)? I’m wondering if I can make edits to the Android drivers above to get them working with the Electron.

Any insight would be greatly appreciated.

Thanks,
Mike


#8

I’ve seen an instance of this operating very recently, but my takeaway is very dubious in nature. My reason is that the Droid side support is sketch as I’ve not seen any indication that OTG enumeration makes a UART VCP?

I know FTDI has some silicon solutions (311/312) that utilize Android AOA and stream IO, so if anyone can cite the combination of things required for real OTG/Serial in Android I’d be highly appreciative.

Hoping someone here on this maker forum will jump in with this info? Having this connectable to Photon is a game changer for me.


#9

@jimini,

I got this working by using an external FTDI chip and connecting it to the serial pins on the Electron. I used this:

Connect orange to RX
Connect yellow to TX
Connect black to GND
Connect red to 3.3

The USB side of it connects to the OTG cable, which then connects to the Android device.

At this point the Android Serial Monitor Lite app works fine. I also tried this library and it worked:

It seems like there are a lot of library/driver options when using this FTDI chip. You can use the FTDI D2XX driver directly if you want.

I wish I could get it working connecting directly to the MicroUSB port on the Electron, but this method has its advantages because it frees up the MicroUSB port for charging the Electron while it’s connected to the Android device.

This solution should work the same on the Photon.

Mike


#10

Most interesting, Mike -

The cable you cite uses the FT232R USB/Serial silicon. I’ve used this chip on small “dongle boards” for enumerating VCP’s on PC hosts. I’m intrigued that it enumerates to Android when used with the Android USB Host API. I’ll look deeper at this lib and it’s underlying operation. Now if they only made this cable with a microB connector to avoid the OTG adapter?

I also just received the UMFT311EV which uses the FT311 silicon interface and enumerates to Android using the AOA API and streams in/out as a file like device (with many additional interface options).

Thanks for posting this, I like having choices!


#11

Bump…

Trying with no luck to implement the direct “Photon to Android” OTG serial connection as outlined here in the @rickkas7 tutorial: Serial Tutorial

I’ve tried multiple Android devices (S3 running v4.1.2 / S5 running 6.0.1) and I’ve tried all variants of potential USB configuration in my Android 6 device (charging, MTP, PTP, etc…).

I’ve also verified the cables are operational (connecting to other devices), and I’ve downloaded the cited Play Store app (and others) to no avail.

Does anyone have an operational tandem of Photon and Android software, and if so could you please share the particulars? Having a small serial debug terminal on a Smart Phone would be a great tool for my applications.

Thanks in advance.


#12

It’s really hit or miss whether OTG works or not. I wrote that section of the Serial Tutorial using a Moto G3 running Marshmallow 6.0. I tried a few other serial programs before getting Android USB Serial Monitor Lite to work, so you very well may find one of the others work better on a different phone/OS version.


Serial read through mobile phone
#13

Thanks @rickkas7… I’ll try some additional apps.
Hit or miss is unfortunate, but what is.