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

Value received in Arduino is always 0 [closed]

asked 2017-03-30 04:22:09 -0500

jonagf gravatar image

updated 2017-04-20 03:14:45 -0500

Hi all,

So I have two ROS nodes, one in c++ and another in Arduino. I built a custom message (DataToArduino.h) in the c++ node in which i send two int arrays and one string to the arduino:

Then, in the arduino node I wanted to be able to take those values out, like intensity[0], intensity[1], etc, so I did the following:

#include <projecto/DataToArduino.h>
#include <ros.h>
#include <std_msgs/Int64.h>

ros::NodeHandle nh;

int duration[10]; 
int location[10];
int x;

void messageCb( const projecto::DataToArduino& subscMsg){
  for(int j=0;j<10;j++)
    duration[j] = subscMsg.intensity[j];
    location[j] = subscMsg.location[j];
  x = duration[5];

std_msgs::Int64 test;

ros::Subscriber<projecto::DataToArduino> s("chatter", &messageCb);
ros::Publisher p("my_topic", &test);

void setup()


void loop()
{ = x;
  p.publish( &test );

I created a publisher topic so I could see some data to check if what I was receiving was ok. However, when I checked the echo of the topic in the terminal the result was always data 0 and I don't understand why.

Do you have any idea in what the problem can be and any suggestions?

Thank you so much!

Update: I thank that what happened is that my communication with ROS and Arduino stopped working, but I don't know why, since it worked fine before...

My c++ code works well with another c++ node, so I assume the problem is in the arduino part.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by NEngelhard
close date 2017-04-20 04:00:31.172730

1 Answer

Sort by ยป oldest newest most voted

answered 2017-04-03 04:19:33 -0500

jonagf gravatar image

Solved! So apparently the problem was that even thought that another ros node could receive two int64 arrays, the arduino couldn't (it was probably too big). What I did after reinstalling ros and rosserial, was change the message type to uint8[] instead and now it works fine :) I didn't know there was some kind of limitation on data that we could sent (still don't know if its true), but well, since it works perfectly now I'm gonna leave it this way!

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2017-03-30 04:22:09 -0500

Seen: 286 times

Last updated: Apr 20 '17