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

Array data from arduino

asked 2016-01-06 04:17:39 -0500

starcu gravatar image

updated 2016-01-06 04:21:52 -0500

Hi i trying to send array data from arduino to my node but i have problems with it. I'm reading data from accelerometer and want to send xyz values in array message. Code compile properly but when i tryng to start serial connection with arduino it stucks even if i trying to send only one value. What is wrong here?

 * rosserial Publisher Example
 * Prints "hello world!"
#include "I2Cdev.h"
#include "MPU6050.h"
#include <Wire.h>
#include <ros.h>
//#include <std_msgs/Int16.h>
#include <std_msgs/Int16MultiArray.h>

MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;

ros::NodeHandle  nh;

//std_msgs::Int16 x;
std_msgs::Int16MultiArray xar;

//ros::Publisher inty("inty", &x);
ros::Publisher intyarr("intyarr", &xar);

void setup()

void loop()
  accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
  // = ay;

Also i want to resend data from my node to arduino to send it into robot but i dont know how to do it.

void messageCb( const std_msgs::Int16& msg){
  //digitalWrite(13, HIGH-digitalRead(13));   // blink the led

Code like this doesn't work in Arduino IDE.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-01-06 04:37:36 -0500

updated 2016-01-06 04:56:55 -0500 Part 1.4 talks about issues with arrays and the need to specify the length of the array explicitly - this may be the issue

example here of generating messages that contain arrays, and instructions on how to send them as messages shows how to read the data in a message

void messageCb(const std_msgs::Float64& msg)
  if( > 1.0)
    digitalWrite(13, HIGH-digitalRead(13));   // blink the led
edit flag offensive delete link more


how to access the array data from node to arduino. this is my code: int Arr[4]; void handle_motorspd( const std_msgs::Int32MultiArray::ConstPtr& motor_step) { for (std::vector<int>::const_iterator it = motor_step->data.begin(); it != motor_step->data.end(); ++it) { Arr[i] = *it; i++; }

Jishnu Pillai gravatar image Jishnu Pillai  ( 2017-07-15 07:14:09 -0500 )edit

Question Tools

1 follower


Asked: 2016-01-06 04:17:39 -0500

Seen: 4,500 times

Last updated: Jan 06 '16