

You can find many different UART use cases, from live-debugging your application over USB to your computer (e.g. It’s all about read() and write().Īt this point (Android Things Developer Preview 2) where USB communication is not supported yet, it can be an alternative, as long as you send small payloads of data. Here is an implementation of this callback: private UartDeviceCallback mCallback = new UartDeviceCallback () Ĭommunicating via UART on Android Things is pretty easy. In the last line, we are registering a callback on a background thread that will be called each time UART receives some data. Pretty slow, so better transfer small payloads of data via UART. A 115200 baud rate is therefore equal to 14KBps.

registerUartDeviceCallback ( mInputHandler, mCallback ) setStopBits ( 1 ) // Finally, we register a callback on a background thread that will be // triggered when some data is received via UART. Make sure to configure the other device the exact same way. openUartDevice ( "UART0" ) // Some basic UART configuration. First things first, the UART device initialization: // We receive an instance of the "UART0" device. The best way to start playing with UART is to clone the official UART sample (sample-uartloopback) and import it on Android Studio. Before accessing UART from your app, we first have to mount the Android Things micro-SD card on our computer, modify the cmdline.txt file to remove the following statement: console=serial0,115200.Ĭonsult the official documentation for detailed instructions. Also, plug the Ground wire to the Ground pin (this one was easy).īy default, the Raspberry Pi UART port is mapped to the Linux console. We plug the USB cable into the computer, and the pins on the Raspberry Pi.Īs the ‘RT’ ( Receiver/ Transmitter) in UART suggests, I have to plug the Receiver ( Rx) cable wire to the Raspberry Pi Transmitter ( Tx) pin, and the Transmitter ( Tx) cable wire to the Raspberry Pi Receiver ( Rx) pin. To achieve that, I bought a PL2303HX USB to TTL cable: Yet, I have years practicing on a computer keyboard so, why not use my laptop to play Europe’s “The final countdown” song? I always wanted to be a rock star, but can’t play the piano. #1: Communication between a Raspberry Pi and a computer Over this blog post, we will discover the UART across two different Android Things use cases Now it’s still here and rocking, this time on nano-computers.

In ancient times, it was pretty useful, and seen under the form of a Serial port on a computer. the Raspberry Pi) that lets you perform a bi-directional communication between two devices. Welcome to 2017.Ī UART (Universal Asynchronous Receiver/Transmiter) is a small chip integrated on the board (e.g. We’re going to talk about what’s behind this interface today. If you can easily recognize the Serial port on this picture, let me first remind you that you are old.
