Adding usb host abilities to qpython on android to talk to arduino

436 views
Skip to first unread message

xp_prg

unread,
Dec 23, 2014, 8:45:02 PM12/23/14
to python-fo...@googlegroups.com
Hi All,

I am making cell phone robots that talk to arduino.  I know how to do this in java:


Can I write a java fascade that interfaces with python for android to accomplish the goal of doing the same thing in python proper?  If so, where in the source code would I do this?  I am teaching boy scouts how to make cell phone robots if that makes you want to help me more :>

-Tim

P.S.

Here is the code in java:

line: 416

public void sendArduinoCmd(String cmd) {
// Get UsbManager from Android.
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
// Find the first available driver.
UsbSerialDriver driver = UsbSerialProber.acquire(manager);
try {
if (driver != null) {
driver.open();
try {
driver.setBaudRate(9600);
byte buffer[] = new byte[2];
byte[] cmd_array = cmd.getBytes();
//buffer[0] = 'r';
buffer[0] = cmd_array[0];
Log.d("_dbg", "sending arduino command: " + buffer[0]);
buffer[1] = '\n';
int numBytesWrite = driver.write(buffer, 1000);
Toast.makeText(getApplicationContext(),
"Read " + numBytesWrite + " bytes.", Toast.LENGTH_LONG).show();
} catch (IOException e) {
// Deal with error.
Toast.makeText(getApplicationContext(),
"IOException occurred", Toast.LENGTH_LONG).show();
} finally {
driver.close();
}
} else {
Log.d("_dbg", "arduino driver null");
}
} catch (IOException e) {
// Deal with error.
Toast.makeText(getApplicationContext(),
"IOException occurred 2", Toast.LENGTH_LONG).show();
}
}

sinku...@gmail.com

unread,
Dec 23, 2014, 11:06:25 PM12/23/14
to python-fo...@googlegroups.com
‎Hi Tim

Here is my usb facade for PL2032 chip.
This is just for USB serial facade sample, but
‎you can make same facade for arduino.

 

送信者: xp_prg
送信: 2014年12月24日(水曜日) 11:21
件名: [Py4A] Adding usb host abilities to qpython on android to talk to arduino

--
You received this message because you are subscribed to the Google Groups "Py4A" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-for-andr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages