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

rosserial lost sync error

asked 2020-06-29 08:49:28 -0600

sohartma gravatar image

updated 2020-06-30 08:31:50 -0600


I'm getting this error "Lost sync with device, restarting..." after a few seconds starting rosserial. I'm getting it with this sketch:

#include <ros.h>
#include <geometry_msgs/Vector3.h>

ros::NodeHandle_<ArduinoHardware, 1, 1, 125, 125> nh;
geometry_msgs::Vector3 pub_msg;
ros::Publisher pub("/car/power", &pub_msg);

static int potenza_linear = 0;
static int potenza_angular = 0;

// True if the car is rotating, false if translating
bool rotating = false;

float mapf(const float& x, const float& in_min, const float& in_max, const float& out_min, const float& out_max)
{ return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;

/* =========== */
/* MPU6050 IMU */
/* =========== */

// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"

#include "MPU6050_6Axis_MotionApps20.h"
//#include "MPU6050.h" // not necessary if using MotionApps include file

// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
    #include "Wire.h"

// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for SparkFun breakout and InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 mpu;
//MPU6050 mpu(0x69); // <-- use for AD0 high

/* =========================================================================
   NOTE: In addition to connection 3.3v, GND, SDA, and SCL, this sketch
   depends on the MPU-6050's INT pin being connected to the Arduino's
   external interrupt #0 pin. On the Arduino Uno and Mega 2560, this is
   digital I/O pin 2.
 * ========================================================================= */

/* =========================================================================
   NOTE: Arduino v1.0.1 with the Leonardo board generates a compile error
   when using Serial.write(buf, len). The Teapot output uses this method.
   The solution requires a modification to the Arduino USBAPI.h file, which
   is fortunately simple, but annoying. This will be fixed in the next IDE
   release. For more info, see these links:,109987.0.html
 * ========================================================================= */

// uncomment "OUTPUT_READABLE_QUATERNION" if you want to see the actual
// quaternion components in a [w, x, y, z] format (not best for parsing
// on a remote host such as Processing or something though)

// uncomment "OUTPUT_READABLE_EULER" if you want to see Euler angles
// (in degrees) calculated from the quaternions coming from the FIFO.
// Note that Euler angles suffer from gimbal lock (for more info, see

// uncomment "OUTPUT_READABLE_YAWPITCHROLL" if you want to see the yaw/
// pitch/roll angles (in degrees) calculated from the quaternions coming
// from the FIFO. Note this also requires gravity vector calculations.
// Also note that yaw/pitch/roll angles suffer from gimbal lock (for
// more info, see:

// uncomment "OUTPUT_READABLE_REALACCEL" if you want to see acceleration
// components with gravity removed. This acceleration reference frame is
// not compensated for orientation, so +X is always +X according to the
// sensor, just without the effects of gravity. If you want acceleration
// compensated for orientation, us OUTPUT_READABLE_WORLDACCEL instead.

// uncomment "OUTPUT_READABLE_WORLDACCEL" if you want to see acceleration
// components ...
edit retag flag offensive close merge delete


Unless you've changed the serial/usb port rosserial is supposed to use on your Arduino, you cannot use Serial.print(..) or Serial.begin(..) or anything with Serial as it will interfere with rosserial's protocol.

Also: please link to any questions you've already found and the solutions you've already tried, so we can avoid suggesting the same things.

gvdhoorn gravatar image gvdhoorn  ( 2020-06-30 02:20:58 -0600 )edit

Thanks! Everything I've tried so far is in my question at the very end. So i just comment everything out that starts with serial Ok I will try!! However today i already tried reinstalling the newest version of the arduino ide, now im getting this rosserial error socket.error: [Errno 111] Connection refused... My bad! did'nt start the ros master ;) Update: I tried commenting everything with serial out, still get the same error.

sohartma gravatar image sohartma  ( 2020-06-30 08:26:58 -0600 )edit

I don't know why, but when I used Float64 with rosserial I always get a lost sync error, however, when changing it to Float32 everything get works. Try to find a message using float32 instead of float64 or create a custom one. I read the documents and there says the float64 message is converted into float32 (rosserial limitations(float64)) but I don't know why with explicit conversion to float32 works.

Teo Cardoso gravatar image Teo Cardoso  ( 2020-06-30 10:47:02 -0600 )edit

Had a bad feeling about the IMU. So i commented everything out of the sketch that has something to do with the IMU sensor. Now rosserial works fine. No sync error. Bad thing is, the y value of the vector3 message is empty, can't use that for navigation...

So today i tried a simple sketch just for the imu sensor. I also tried two different IMU sensors. I'm getting Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino Other sketches without the IMU are working fine, as soon as I add the IMU part i get this error.

sohartma gravatar image sohartma  ( 2020-06-30 15:54:28 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2020-07-02 06:46:31 -0600

sohartma gravatar image

In case someone else is having the same issue, I FOUND THE SOLUTION!

If you are getting "Unable to sync with device ..." you might have a connection problem: Sensor not connected, wrong sensor connected, sensor connected to wrong pins, ...

If you are getting "Lost sync with device ..." when trying to connect an IMU sensor: DO NOT CONNECT THE INT (Interrupt) PIN!

edit flag offensive delete link more

Question Tools


Asked: 2020-06-29 08:49:28 -0600

Seen: 623 times

Last updated: Jul 02 '20