Serial, UART and Android, as a connection with microcontrollers


Our subjects:

Android 4.1.1 tablet “DNS AirTab M101w” and the following devices:
1. Tiva C Series TM4C123G LaunchPad
board 2. Stellaris LaunchPad EK-LM4F120XL
board 3. Arduino MEGA 2560
board 4. MSP430 LaunchPad, M430G2553 board

And now we will take turns connect all these boards via USB OTG to the tablet and try to establish a connection with them without resorting to root access.

Subject 1. Tiva C Series TM4C123G LaunchPad

The board has a micro-usb “DEBUG” connector, and an RGB LED, we will play with them.
The following sketch was uploaded with Energia IDE:
char data = ' '; //переменная для приёма символа
boolean rs, gs, bs = false; //статус каждого светодиода
void setup()
//Настройка выходов
  pinMode(RED_LED, OUTPUT);
  pinMode(BLUE_LED, OUTPUT);
  Serial.begin(9600); //открытие Serial соединения на скорости 9600
void loop()
  if (Serial.available()){ //если были получены данные
    data =; //прочитать их
    switch (data){ //и выполнить
      case '1':
        rs = !rs;
      case '2':
        gs = !gs;
      case '3':
        bs = !bs;
    //Зажигаем светодиод
    digitalWrite(RED_LED, rs);
    digitalWrite(GREEN_LED, gs);
    digitalWrite(BLUE_LED, bs);
    //Отправляем текущее состояние светодиодов

In my case, when connected to the tablet, the tty1-1: 1.0 file appears in the / dev / usb / directory. Let's try to register the following in the terminal emulator:
$ echo 2 > /dev/tty1-1:1.0
$ read s < /dev/tty1-1:1.0
$ echo $s

And then, unexpectedly for me, a green light comes on and I saw an output line. Why unexpectedly? Because I neglected to pre-configure the connection, poked my finger at the sky, but for how well! We will not dwell on this. But I will say that in different versions of the core, the boards will be defined differently, and you can’t imagine a single command line without crutches (yes, linux is ordinary) .

Having played a little with colors, sending different numbers to the so-called COM port, I started searching for a universal Android solution. There is a lot on Google Play for “Serial UART”, and most applications work as expected with a toy from Texas Instruments. But my attempts to find a thread compatible with Open Source ended in almost nothing. For Arduino I found a cool library, but more on that below ...

Subject 2: Stellaris LaunchPad EK-LM4F120XL Board

As I understand it, this is the previous version of our first test subject and behaves exactly the same with the android. But the current Energia 0101E0010, when trying to fill in the sketch, does not see this board (Windows 8).
No ICDI device with USB VID:PID 1cbe:00fd found!

Therefore, I just turned on the output of the final binary path to the console and loaded it manually using the LM Flash Programmer.

Subject 3: Arduino MEGA 2560 Board

Let's change the sketch a little and we will blink only with one LED.
Fill with the Arduino IDE
#define LED 13
char data = ' ';
boolean ls = false;
void setup()
  pinMode(LED, OUTPUT);
void loop()
  if (Serial.available()){
    data =;
    switch (data){
      case '1':
        ls = !ls;
    digitalWrite(LED, ls);

We connect to the tablet, again we see the tty1-1: 1.0 file in the / dev / usb / directory, we repeat the experiment:
$ echo 1 > /dev/tty1-1:1.0

and then I find that the LED blinks 2 times with a period of about 100 ms and goes out. Okay, I’m trying the following:
$ read s < /dev/tty1-1:1.0

And then the terminal froze in anticipation ... Okay, Ctrl + C
$ echo $s

It is logical that there is nothing in the output.

But this was just an introduction, there is one wonderful project Physicaloid Library . First, open the library as an ordinary android project in Eclipse. Now create a new project and in its properties in the item android, Library click Add ... and select Physicaloid Library. Now, to press the button to send the string “1” to the arduino:
public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
			mPhysicaloid = new Physicaloid(this);
			if( {
			    byte[] buf = "1".getBytes();
			    mPhysicaloid.write(buf, buf.length);

I don’t think I need to tell how to read the received data, because everything is in the library documentation.

Subject 4: Board MSP430 LaunchPad, M430G2553.

This board did not want to work with my hardware at all. It’s simply not determined by the system, and USB Device info just hangs when refreshed.


I would like such a library for working with Tiva C Series boards. Remake yourself while the skill is not enough.

Also popular now: