Arduino Communicator

The Arduino Communicator is a windows program I developed to communicate with an Arduino micro controller. More specifically, I wanted to use it to control my  robots. The program is developed in Delphi XE3. It was a nice exercise to learn the intricacies of Firemonkey programming (see duely impressive video here). It uses a slightly enhanced COMport component for serial communication with the Arduino. A very simple protocol is used over this serial communication. An ‘f’ means move forward, ‘b’ moves backward indeed, and so on. This of course requires a close interaction with the sketch controlling the Arduino and the Arduino communicator. In this article I want to go into the following subjects:

  • Why an Areduino Communicator?
  • What is the protocol being used?
  • Communication with a VoiceBox
  • Communication with motors
  • Telemetry

Why an Arduino Communicator?

I always dreamt of building an intelligent, autonomous robot. The Arduino makes this affordable. As soon as the robot was wheeling around I wanted it to give some goals, or to change its speed or to sing. That requires an online communication with the robot. I built the Arduino Communicator to do just that.

What is the protocol being used?

Communication requires to pieces of software and a protocol between them. The Arduino Communicator communicates from the PC and the Arduino requires software that is able to receive and understand the commands being sent. The software sends information back to the Arduino Communicator to tell about its exploits (see also the part about Telemetry).

The software on the Arduino side  contains a very simple loop () routine (download sketch acryBot):

void loop ()
  examine_speaking ();
  if (Serial.available ())
    process_command ( ());
  } // if
  // Do some other things...
} // loop //

It checks whether some info is ready at the serial port. If so a command is read and transferred to function process_command (). The structure of this function is:

void process_command (char command)
  int dir, delta, temp;
  const int SIZE = 65; // Buffer size of speakjet + 1 for extra space
  int n;               // Number of bytes read
  int index;
  char buffer [SIZE];  // buffer
  char c;

  while (command != 'c')
    switch (command)
      case 'A': // Strategy A
      case 'B': // Strategy B
      case 'C': // Strategy C
      case 'f': // forward small amount of time
      case 'b': // backward small amount of time
      case 'l': // turn left small amount of time
      case 'r': // turn right small amount of time
      case 'o': // allow motors to run
      case 'p': // switch off motors
      case 't': // talk to the VoiceBox
      case 'd': // direction command
      case '0': // zero and 's' are stop
      case 's': 
      case '1': // speed in 9ths of maximum speed, 9 = max
      case '2': 
      case '3': 
      case '4': 
      case '5': 
      case '6': 
      case '7': 
      case '8': 
      case '9':

// If command is not equal 'c' (continue), wait for 
// and read the next command 
    if (command != 'c')
       while (!Serial.available ());
       command = ();
    } // if/
  } // while
} // process_command //

Usually the Arduino sends some confirmation to the Arduino Communicator.
The communication between the Arduino Communicator and the Arduino is not perfect to say the least. A character can be lost or garbled. Information is not sent as logical ‘sentences’, when I the Arduino executes a statement like

Serial.println ("Hello");

The Arduino Communicator might receive this as “Hello”, or “He” followed by “llo” or whatever. Therefore it important to be sure when a command or message is completely received. I have implemented a different solution for each direction.

  • PC->Arduino – just send one character, if it is lost, no problem, if garbled: pity. This works well except for the talk (‘t’Smilie: ;) command. This command is followed by a string of byte codes and terminated by 0xFF. If the ‘t’ gets lost the byte codes are seen as commands which may have weird results.
  • Arduino->PC – the Arduino sends messages back to the PC enclosd in square brackets “[]”. Information received from the Arduino is aded to a global string variable until a bracket close “]” is detected. The program searches for a bracket open “[“. If none present all input is discarded. The bracket open is followed by a one character indication of message type, a colon and optional argument. All zero, newline and carriage return characters are discarded.  The ‘m’ character means a message. The string “[m:Ready]” sends the message “Ready” to the Arduino Communicator. “[s:0]” means that the VoiceBox has finished talking and “[d:<number> <number>]” sends direction information.

Maybe I should implement some error correction or CRC checks. For the moment this protocol works reasonanle well.

Communication with a VoiceBox

The command to make the Arduino talk is ‘t’ (talk). It is followed by maximally 64 bytes being the phonemes to be pronounced. The Arduino sends back as well the byte code it has received as a message preceded by the number of bytes it has received. When you want the VoiceBox to say hello, it translates this word into phonemes: HE EHLL LO OWWW. Translated to byte code this is: 183, 159, 146, 164. The Arduino communicator sends six (6) bytes: 116 (for ‘t’Smilie: ;), 183, 159, 146, 164, 255 (stop byte). The Arduino sketch sends back: “[m:5:183 159 146 164 255]” (note: the command ‘t’ is not sent). When is has finished speaking “hello” it sends “[s:0]”.

Communication with motors



About Arnold

I compose music and love to write software so I write software to compose music. Somewhere in that proces I got attracted to robots. Probably this all makes few sense but it is fun.

Category(s): Robots, Software

Leave a Reply