The latest versions of the Android operating system have provision for portable devices, such as tablet PCs and smartphones, to carry out control functions via the USB interface. Here Manuel Di Cerbo of Nexus-Computing and Dave Riness of Future Devices Technology International (FTDI) describe a simple example where an Android based tablet PC is used to operate remote control racing car. You can even see it in action at: http://www.youtube.com/watch?v=oVWMH6qAvO4
The application consists of:
1. A tablet PC which uses the Android operating system, which acts as a USB host.
2. A FTDI Vinco development board which is connected via a USB cable to the tablet PC. The board's dual channel USB host/device controller functionality (provided by a Vinculum II chip) allows it to act as a USB device in this particular scenario. To simplify the firmware a USB-to-serial driver is used on the device side.
3. The radio remote hardware, with data transfer through the GPIO interface.
There is only one speed for driving forward and one for reverse. The pressing of any button on the radio remote will result in a microcontroller pin being pulled down to ground level. This is how the Vinculum II controls the radio remote, but instead of manually pressing down buttons, here the respective pin is short-circuited to ground, thereby emulating a button press.
Since the radio control signal is rather simple, it can be broken down to bytewise serial transfers. For instance, the byte value "0x01" is used to steer right and "0x08" for going forward. Likewise, the combination of the two values "0x09" will result in the car going forward while steering to the right.
How to compile your own kernel module is explained at http://android.serverbox.ch/?p=285. If everything goes well, this will result in a device node similar to "/dev/ttyUSB0". This node could be used for serial communication, but only by rooting access to the tablet, since the default privileges act to prevent it. This approach is not very user friendly.
This is where the Racer application shines. You can simply need to install it http://www.nexus-computing.ch/files/Racer.apk, then plug in a Vinco board via the USB interface. There is no need to install additional kernel modules or root the tablet. The connection between Android tablet and Vinculum II still behaves like a commonly known serial communication interface. The firmware is set to emulate a USB-to-serial converter. It receives single bytes and accordingly pulls down the appropriate pins on the remote which ultimately controls the remote controlled car.
The following lines of Java code are used to initiate the serial communication:
UsbDeviceConnection conn = usbm.openDevice(dev);
conn.controlTransfer(0x40, 0, 0, 0, null, 0, 0);// reset
conn.controlTransfer(0x40, 0, 1, 0, null, 0, 0);// clear Rx
conn.controlTransfer(0x40, 0, 2, 0, null, 0, 0);// clear Tx
conn.controlTransfer(0x40, 0x03, 0x4138, 0, null, 0, 0);// set baudrate 9600
This code closely resembles the libftdi functions:
int ftdi_usb_reset(struct ftdi_context *ftdi)
int ftdi_usb_purge_rx_buffer(struct ftdi_context *ftdi)
int ftdi_usb_purge_tx_buffer(struct ftdi_context *ftdi)
int ftdi_set_baudrate(struct ftdi_context *ftdi, int baudrate)
Once the connection has been initialized, further bulk transfers are sent in a similar fashion through the Android operating system's USB API.
Leave a comment