Ask Your Question

Connecting ROS to Arduino Serial Port

asked 2018-06-13 16:14:07 -0600

Prasanth Suresh gravatar image

updated 2018-06-13 19:05:08 -0600

jayess gravatar image


I'm using ROS-Indigo on Ubuntu 14.04. I have ROS properly installed, sourced and dependencies configured properly ( I have arduino installed and ROS libraries setup perfectly ( ) ( (

Now, my arduino stand-alone works perfectly, I tested that with a servo motor.

I did the following steps:

  1. Dumped the example servo motor program into arduino without any changes.
  2. Started roscore.
  3. When I tried connecting ROS with arduino using this command:

    rosrun rosserial_python /dev/ttyUSB0

I get this error:

[INFO] [WallTime: 1528924023.535404] ROS Serial Python Node
[INFO] [WallTime: 1528924023.543175] Connecting to /dev/ttyUSB0 at 9600 baud
Traceback (most recent call last):
  File "/home/prasanth/catkin_ws/src/rosserial/rosserial_python/nodes/", line 88, in <module>
    client = SerialClient(port_name, baud, fix_pyserial_for_test=fix_pyserial_for_test)
  File "/home/prasanth/catkin_ws/src/rosserial/rosserial_python/src/rosserial_python/", line 358, in __init__
    self.port = Serial(port, baud, timeout=self.timeout, write_timeout=10)
TypeError: __init__() got an unexpected keyword argument 'write_timeout'

I tried using this alternate command:

rosrun rosserial_python /dev/ttyACM0

and adding different baud rates to the end like:

rosrun rosserial_python /dev/ttyACM0 _baud:=38400

I couldn't find any help for this problem online. Without crossing this step, I cannot progress to

rostopic pub servo std_msgs/UInt16  <angle>

I'm following this tutorial for the steps:

Kindly help, Prasanth.S.S

edit retag flag offensive close merge delete


Could you show the setup part of your code, I had a similar issue due to a bad configuration of the serial communication(s). Also you can try rosrun rosserial_python _port:=/dev/ttyACM0 to launch the node.

RicHykkie gravatar image RicHykkie  ( 2018-06-15 02:26:00 -0600 )edit

Hi Ric,

Assuming you mean the setup of the arduino code, I'm using the exact sample code that is in the library:

void setup(){ pinMode(13, OUTPUT);

nh.initNode(); nh.subscribe(sub);

servo.attach(9); //attach it to pin 9 }

Prasanth Suresh gravatar image Prasanth Suresh  ( 2018-06-15 14:48:30 -0600 )edit

Try adding


This should open the serial connection with the Arduino.

RicHykkie gravatar image RicHykkie  ( 2018-06-17 00:45:51 -0600 )edit

Hi Ric, I tried that, it didn't make any difference, so just for debugging sakes, I tried commenting out the line that was mentioned in the error above and now I get this: self.port.flushInput() AttributeError: 'SerialClient' object has no attribute 'port'; Does any of this mean anything to you?

Prasanth Suresh gravatar image Prasanth Suresh  ( 2018-06-17 15:48:41 -0600 )edit

Regarding what you've done, it's normal. Line 358 of goes:

self.port = Serial(port, baud, timeout=self.timeout, write_timeout=10)

If you comment it, the class SerialClient has no more port data defined, hence the error.

I'm still looking at your issue.

RicHykkie gravatar image RicHykkie  ( 2018-06-19 00:05:05 -0600 )edit

This same line in my is: self.port = Serial(port, baud, timeout=self.timeout*0.5)

Be aware that I'm using lunar and 16.04, but that might be related to your issue.

RicHykkie gravatar image RicHykkie  ( 2018-06-19 00:07:08 -0600 )edit

try changing write_timeout to writeTimeout. I am not sure about this but you can try. From what I read its different for py2.7 and py3.0. Try it and let me know.

PratNag gravatar image PratNag  ( 2018-06-19 13:49:18 -0600 )edit

I shall try that asap and get back to you, thanks.

Prasanth Suresh gravatar image Prasanth Suresh  ( 2018-06-19 13:53:11 -0600 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2018-06-14 01:22:06 -0600

saurabh gravatar image
  1. Please confirm your cable is working.
  2. Arduino usually makes ttyACM0 only, as much as I know.
  3. Give permission to this interface using below command:

    sudo chmod 777 /dev/ttyACM0

  4. Were you able to flash the code?

  5. You have to run roscore in a separate tab as well.


edit flag offensive delete link more


Hi, thank you for the prompt reply, here are the answers to your questions:

1.) Yes, my cable is working, because I used the same cable to test arduino stand-alone to control a servo motor. 2.) Yes, you are right, I tried both ACM0 and USB0, but neither of them cause any change in the error.

Prasanth Suresh gravatar image Prasanth Suresh  ( 2018-06-14 10:13:34 -0600 )edit

I also tried adding baud rate to the end, like, rosrun rosserial_python /dev/ttyACM0 _baud:=9600. That doesn't help either. 3.) I did give it all the permissions now, that didn't change anything. 4.) Yes, I was able to flash the code successfully. 5.) Yes, roscore is in a seperate tab

Prasanth Suresh gravatar image Prasanth Suresh  ( 2018-06-14 10:14:43 -0600 )edit

Are you sure that arduino is connected to ACM0? You can see the serial port name as /dev/USBx or /dev/ACMx in the arduino IDE. Please check that once and use that.

PratNag gravatar image PratNag  ( 2018-06-19 13:30:24 -0600 )edit

@PratNag, yes, I made sure of that.

Prasanth Suresh gravatar image Prasanth Suresh  ( 2018-06-19 13:33:20 -0600 )edit

answered 2018-06-21 04:32:56 -0600

PratNag gravatar image

So that happens due to differences in libraries for Python 2.7 and Python 3.0. The tutorials are based on Python 2.7 so be careful of that.

edit flag offensive delete link more

answered 2019-06-11 01:33:19 -0600

ojboba gravatar image

ROS-Indigo on Ubuntu 14.04 is a pain. The reason it doesn't work is because in Indigo "write_timeout" was in camel case being "writeTimeout". If you change the code and replace "write_timeout" with "writeTimeout" that should do the trick. You could also just upgrade to kinetic or higher and that should solve your problem as well.

Have a nice day.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2018-06-13 16:14:07 -0600

Seen: 2,997 times

Last updated: Jun 21 '18