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

Arduino (rosserial) node hangs during I2C reading + PWM

asked 2016-12-19 14:10:23 -0600

david.1982 gravatar image

I've been trying to troubleshoot a strange problem for a few days now. I've got a ROS Kinetic node running on a Raspberry Pi 3 (Ubuntu Mate). I'm utilizing the rosserial_arduino package to handle communication between the Arduino and my master node. Current setup is basically an Arduino Mega 2560 with a SEED Studio Motor Shield powering 2 wheels, plus an ITG3205/ADXL345/HMC5883L 9-DOF chip. I currently have two publishers set up - one outputting twistStamped messages and one chatter topic outputting loop iterations and debug information. I've got one subscriber set up receiving an int16 message from a homespun teleop script - basically listening for keys 2,4,5,6,8.

Everything works perfectly if there is no power to the motor shield (I'm using an external 6v pack). I am able to echo out twist messages which are directly linked to the xyz axis on my gyro and accel. My chatter topic shows me my current loop iteration and when I send key commands I see them echoing out as well. Similarly, if the motor power is off, I still get LED signals on the shield showing the current motor states.

If I turn on power supply to the motors and send a signal other than "full stop" which is key 5, everything hangs up. it might take a few loops but it will hang within 1-4 seconds of the motor signal being sent and received. Resetting the board alleviates the issue and all my topics begin to send/receive again.

I have traced this problem down to the ITG3205 portion that performs the I2C communication (itgRead function) - specifically after the first call to Wire.endTransmission().

Any ideas? I've tried swapping out the arduino, the shield, and the 9-dof chip with no success. As long as i've got wheels are spinning, everything hangs on gyro read. I've included relevant code snippets below.

Motor Shield code. Only included forward for brevity.

void SeeedMotorV2::allStop()


void SeeedMotorV2::forward(int speed)
  analogWrite(leftmotorspeed,speed); //pin 10
  analogWrite(rightmotorspeed,speed);//pin 9
  digitalWrite(leftmotorBackward,LOW);//pin 13
  digitalWrite(rightmotorBackward,LOW);//pin 11
  digitalWrite(leftmotorForward,HIGH);//pin 12
  digitalWrite(rightmotorForward,HIGH);//pin 8

ITG3205 code snippet.

unsigned char ITG3205::itgRead(char address, char registerAddress)
  //This variable will hold the contents read from the i2c device.
  unsigned char data=0;

  //Send the register address to be read.
  //Send the Register Address

  //End the communication sequence.

  //Ask the I2C device for data
  Wire.requestFrom(address, 1);

  //Wait for a response from the I2C device
    //Save the data sent from the I2C device
    data =;

  //End the communication sequence.

  //Return the data read during the operation
  return data;

//itgAddress = 0x68
//GYRO_XOUT_H = 0x1D
int ITG3205::readX(void)
  int data=0;
  data = itgRead ...
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-06-27 11:25:47 -0600

Void gravatar image

From my testing, it appears rosserial_arduino can subscribe to both Twist and TwistStamped messages correctly; but, the callback will not work if the message type is TwistStamped.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-12-19 14:10:23 -0600

Seen: 799 times

Last updated: Jun 27 '19