ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

rosserial_python can't connect to Arduino Leonardo

asked 2013-04-30 06:23:26 -0500

NikolasEngelhard gravatar image

updated 2013-04-30 07:07:57 -0500

I am trying to use an Arduino to connect two sensors to ROS Groovy on Ubuntu 12.04 but have problems to talk to it using rosserial. Since I have several sensors, I bought the Arduino Leonardo http://arduino.cc/en/Main/arduinoBoardLeonardo based on the ATmega32u4 since it has four interrupt pins that I need for my sensors.

The first problem was in ArduinoHardware.h

iostream = &Serial;

which I changed to

iostream = &Serial1;

as proposed here: https://github.com/ros-drivers/rosserial/issues/49

Now the HelloWorld.ino compiled and I could upload it to the Arduino. I started

rosrun rosserial_python serial_node.py /dev/ttyACM0

but only get this response:

[INFO] [WallTime: 1367338659.844329] ROS Serial Python Node

[INFO] [WallTime: 1367338659.858269] Connecting to /dev/ttyACM0 at 57600 baud

[ERROR] [WallTime: 1367338676.969867] Lost sync with device, restarting...

Has someone managed to use the Leonardo and can help me?

Nikolas

// update: I adapted by loop to:

void loop(){

Serial.println(1);

if (state){

digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)

}else{

digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)

}

state = !state;

delay(1000); // wait for a second

str_msg.data = hello;

chatter.publish( &str_msg );

nh.spinOnce();

}

The led (Pin 13) is blinks with a frequency of .5Hz (1s on 1s off). If (Iff) I start the rosserial_python, the TX-Led also flashes as the pin13-Led changes its state. Therefore there is at least some kind of communication, but no rostopic.

edit retag flag offensive close merge delete

5 Answers

Sort by ยป oldest newest most voted
1

answered 2013-05-01 17:22:40 -0500

hd271 gravatar image

To my knowledge, you can't use the Arduino Serial library while sending/receiving ROS topics.

Since your data will be sent in the chatter.publish call, the rosserial_python node will see this data, as well as data sent with the Serial.println call, which is probably whats causing it to lose sync.

Try commenting out that Serial.println line in loop() and see if it can connect stably.

Also, I noticed that in your python solution you're using a baud rate of 115200, whereas the rosserial node is attempting to connect at 57600. Are you setting the serial rate to 115200 in your void setup() on the Arduino? You'll probably want to remove that as well as it will conflict with the rosserial configuration.

Best of luck!

edit flag offensive delete link more

Comments

I first tried it without the serial.println but could also not connect properly. I experimented with different baudrates (and checked that both ends use the same rate) but was not able to connect.

NikolasEngelhard gravatar image NikolasEngelhard  ( 2013-05-01 23:57:34 -0500 )edit
2

answered 2014-01-25 05:05:26 -0500

bruno.hexsel gravatar image

The "Hello World" example seems to be working fine on Hydro. The only change you must to your Arduino code on Leonardo is to add

#define USE_USBCON

just before

#include <ros.h>

That's it.

edit flag offensive delete link more

Comments

This helped me a lot. Thank you!

honky gravatar image honky  ( 2014-05-21 10:37:47 -0500 )edit

This worked for me also.. Using ros kinetic..!!!! Thanks

ivan_calle gravatar image ivan_calle  ( 2017-10-16 09:04:21 -0500 )edit
1

answered 2013-05-01 10:37:53 -0500

NikolasEngelhard gravatar image

Alternative using python directly

I now stopped working on rosserial and implemented an own python based interface:

#!/usr/bin/env python
import rospy
from std_msgs.msg import String

import serial           
import time
ser = serial.Serial('/dev/ttyACM0', 115200)

pub = rospy.Publisher('chatter', String)
rospy.init_node('talker')


while 1:
 a = ser.readline()
 pub.publish(String(a))

If I have an arduino loop of

void loop() {
   Serial.println("OFF");
}

the frequency is enough for my needs:

rostopic hz chatter

gives be above 10kHz.

edit flag offensive delete link more
0

answered 2013-06-04 11:10:34 -0500

Zheng gravatar image

Hi there, I got this problem solved. What I did is changing the line 47th of ArduinoHardware.h into the following:

ArduinoHardware(Serial_* io , long baud= 57600){

And the 80th line into this:

Serial_* iostream;

I was trying Arduino Leonardo with ROS Fuerte under Ubuntu 12.04 32bit to do communication through rosserial. It's proved that the bug really exists with the above configuration. Changing "iostream = &Serial;" into "iostream = &Serial1;" got the uploading passed but also ruined the communication. That's why I did the modification like above.

edit flag offensive delete link more

Comments

Hey, so I was having the same problem (with the Arduino Uno and ROS Groovy) and tried your solution... It didn't make a difference; I'm still having the same exact problem. Suggestions?

asriraman93 gravatar image asriraman93  ( 2013-07-09 15:48:27 -0500 )edit

I tried this and now my arduino wont connect to the serial port at all. dosent show up in ubuntu or windows. Is there any way i can hard reset it and reprogram it ?

vivek rk gravatar image vivek rk  ( 2013-08-12 13:45:28 -0500 )edit

@asriraman93 I will suggest you have a look at the bottom lines of the file "HardwareSerial.h". It is where the "ArduinoHardware.h" gets the type of Serial***.

Zheng gravatar image Zheng  ( 2013-08-12 14:09:20 -0500 )edit

@vivek rk I cannot tell you what exactly you need to do to fix it based on your description. But I think you may need this (http://arduino.cc/en/Hacking/Bootloader?from=Main.Bootloader) to flash your Arduino. And about the Serial*** variable problem I suggest you have a look into the source files starting with HardwareSerial.h.

Zheng gravatar image Zheng  ( 2013-08-12 14:16:00 -0500 )edit
0

answered 2013-05-27 22:06:53 -0500

Hi!

I am having a similar problem with an Arduino Micro (it has the same microcontroller). Does anyone has a solution yet on how to use the arduino with rosserial? I am using Ubuntu 12.04 with ros fuerte. I changed the line as described in the first post for Serial but none off the ros examples work... It might has something to do with the virtual serial port? but I do not know how and where to change these settings if necessary. Many thanks in advance!

Jeroen

edit flag offensive delete link more

Comments

Hope my solution will help you.

Zheng gravatar image Zheng  ( 2013-06-04 11:26:17 -0500 )edit

Question Tools

Stats

Asked: 2013-04-30 06:23:26 -0500

Seen: 3,716 times

Last updated: Jan 25 '14