I have been trying to follow this tutorial to read data output from my arduino using my android phone, they are connected via OTG.
https://code.google.com/p/usb-serial-for-android/
I am able to print the result in a text view, however the output is 0. This is the code snippet I am using:
// Get UsbManager from Android.
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
// Find the first available driver.
UsbSerialDriver driver = UsbSerialProber.acquire(manager);
if (driver != null) {
driver.open();
try {
driver.setBaudRate(115200);
byte buffer[] = new byte[16];
int numBytesRead = driver.read(buffer, 1000);
Log.d(TAG, "Read " + numBytesRead + " bytes.");
} catch (IOException e) {
// Deal with error.
} finally {
driver.close();
}
}
My error might be relating to driver.read, can't find much documentation on it. Any thoughts on how the data get's pulled from the Arduino through serial in this method? If not, better ways to do it?
Thanks! Arun