Connecting ROS and arduino using rosserial

Hello friends,

I found many troubles in setting up rosserial connection between ROS and Arduino IDE when I was a ROS beginner, so I am writing this tutorial for setting up rosserial_arduino in ubuntu. Assuming that you have installed ROS and Arduino IDE successfully on your system. We will begin with the setting up of rosserial_arduino on the system taking help from the official ROS page : http://wiki.ros.org/rosserial_arduino/Tutorials/Arduino%20IDE%20Setup


Step 1: First step is to update and upgrade your system by typing following steps in the terminal

sudo apt-get install update

    sudo apt-get install upgrade

Step 2: Install the rosserial_arduino by using the following commands in the terminal

sudo apt-get install ros-distro-rosserial-arduino

    sudo apt-get install ros-distro-rosserial

Note : ‘distro’ specifies the version of ros installed on your system e.g. hydro,indigo,jade etc. If you are using Ubuntu 14.04, then substitute ‘distro’ by ‘indigo’ and it should work.

Step 3: Cloning the rosserial from git and generate the rosserial_msgs needed for communication, and make the ros_lib library. For these, we need to type the following in theterminal

cd <catkin_workspace>/src

<catkin_workspace> is the path to your catkin workspace used for ros.

git clone https://github.com/ros-drivers/rosserial.git

    cd ..

    catkin_make

    catkin_make install

    source <catkin_workspace>/install/setup.bash

Step 4: Next step is to transport ros_lib library to arduino environment. The ros_lib folder generated in the last step needs to be transported to the Arduino library folder. We can do this by using the following commands.

cd <arduino_sketchbook>/libraries

<arduino_sketchbook> is the arduino sketchbook folder located in home where all arduino projects are saved. We are going to use the skectchbook folder of the home directory and then copy the files to root directory.

sudo rm -rf ros_lib

    rosrun rosserial_arduino make_libraries.py .

    sudo cp -a ros_lib /usr/share/arduino/libraries

This will place ros_lib folder in the sketchbook folder of the root directory.

Now, we can utilize rosserial_arduino by typing following in the terminal.

sudo arduino

This will open arduino with administrator permission so the sketchbook folder located in the root directory will be used.


In order to check the rosserial, we can do the following

In the arduino, Go to File > Examples > ros_lib > HelloWorld. Upload the code on arduino board, and check the correct board and port in the Tools menu. Once the code is uploaded do the following steps.

Step A: Open ROS for the system, for this type the following

roscore

Step B: Connect the arduino serial port to ROS by using following command.

    rosrun rosserial_python serial_node.py /dev/ttyUSB0

Note : Substitute ‘/dev/ttyUSB0’ by the port of your arduino board.

Step C: Check for the topic if anything is being read or not.

    rostopic echo chatter

If you can see the text like “Hello World” on your screen then you have successfully connected your ROS to Arduino.

Hope you do good with the rosserial_arduino in the future.