The first byte is called Sync Flag which is used to
synchronize the communication between ROS and the
device. Its value will be always 0xff. The second byte or
Protocol Version/Sync Flag tells you if the ROS version we
are using is before ROS Groovy or after Groovy. The value
will be 0xfe after ROS Groovy and will be 0xff up until
Groovy. The third and fourth bytes represent the length of
the message which is on the packet, and the fifth byte is a
checksum of the message length. The sixth and seventh
bytes are dedicated for Topic ID. The Topic ID from 0-100 is
reserved for system functions. The remaining bytes are used
for serial data and its checksums.
The checksums of the length of the packet and data is
computed using the following equation:
255 - ( (Topic ID Low Byte + Topic ID High Byte + data byte
The communication between the serial device and PC
will start from the PC side, which will send a query packet
for getting the number of topics, names, and types of
topics from the Arduino/serial device side. When the
Arduino gets this query packet, it will reply to the PC with a
series of response packets. The response packet will consist
This series of responses will be in the rosserial_msgs/
TopicInfo messages. When a response is not getting
answered from the serial device, the query will resend from
the PC side. The synchronization between ROS and the
serial device is handled by sending timing information from
the PC to the particular device.
The rosserial_client Libraries
The rosserial_client libraries ( http://wiki.ros.org/
rosserial_client) have a client side implementation of the
rosserial protocol. The client can be an embedded
microcontroller platform such as with an Arduino, ARM, or
another serial device such as Xbee. It can run on any
processor which has an ANSI C++ compiler and serial
interfacing to a computer running ROS. There are several
rosserial_client library packages out there for specific
platforms. Here are some of those rosserial_client libraries:
• rosserial_arduino: This package helps you build an
Arduino library called ros_lib which can work as a
rosserial_client library for Arduino. We can include this
library for writing Arduino-ROS client nodes. This package
helps us create a rosserial client on most of the Arduino
platforms – especially the Uno, Mega, and Leonardo.
• rosserial_embeddedlinux: This package enables us
to run rosserial_client on embedded Linux systems (like
• rosserial_windows: ROS is not completely ported to
Windows. If we have to communicate with any Windows
application, we can use this package to communicate from
the Windows client to ROS.
• rosserial_mbed: Most of the ARM controller based
boards support mbed (hardware abstraction layer)
programming, which is similar to Arduino programming.
We can either program mbed boards using an online
compiler, or offline using a gcc4embed (https://github
.com/adamgreen/gcc4mbed) project. The offline compiler
can only work with a limited number of boards, but the
online compiler can use new boards which support mbed.
• rosserial_tivac: The Tiva C Launchpad is another
controller board from Texas Instruments which runs on 80
to 120 MHz. The latest boards are 123GXL and 129XL, and
support the Arduino-like IDE (integrated development
environment) called Energia ( http://energia.nu). We can
program Tiva C using the Arduino programming language
called Wiring ( http://wiring.org.co).
After writing the rosserial node into a serial device, we
have to run another node on the PC side to encode/decode
the serial data. There are some packages for doing this
process. Those are:
• rosserial_python: This package is commonly used
for rosserial communication. You have a Python node which
can connect to the serial device and receive serial values
from the device. It will decode serial packets and generate
ROS topics and services which will be available on the PC
side. This package is stable and recommended for PC
• rosserial_server: This is actually a C++
implementation of a rosserial receiver and can be used for
high performance applications. The features of this node
are less compared to rosserial_python.
• rosserial_java: If you want to interface ROS with an
Android, this is the best choice.
We are going to use rosserial_python on the PC side.
These are the two hardware components we need to
start with our Arduino-ROS programming:
• Arduino Mega 2560 ( https://www.arduino.cc/
• USB B-type cable ( https://amzn.com/ B00UNZ9KBM)
To start interfacing our Arduino to ROS, the first
procedure is to install ROS on the PC itself.
Installing ROS on Ubuntu 16.04
For working with an Arduino, we can set up a new
30 SERVO 11.2016