Ask Your Question

Joy node with Arduino

asked 2016-11-11 05:37:36 -0600

marcoresk gravatar image

updated 2016-11-11 10:35:44 -0600

Hi, I'm very confused.

With ROS Indigo, i managed to set up the rosserial communication with Arduino and all works. I am trying to use the Joy node as input for Arduino but nothing occurs.

This is my code. The purpose is: if a certain button is pressed, the led should turn on as output of pin 3.

#include <stdint.h>
#include <stdlib.h>  
#include <ros.h>
#include <std_msgs/Float32.h>
#include <sensor_msgs/Joy.h>

void joydata ( const sensor_msgs::Joy& joy){

  if ((joy.axes[14]) >= 0.5){


ros::NodeHandle  nh;
ros::Subscriber<sensor_msgs::Joy> sub1("joy", joydata);    

void setup()
    pinMode(3, OUTPUT); //set up the LED

void loop()   {

And I don't understand what I am doing wrong. Joy node works (checked it with rostopic echo) and rosserial works (checked it with another subscriber program). The led and all electrical things work (checked it with an alternative arduino sketch). What is the proper way to read data from Joy node? Thanks in advance!

UPDATE I tried to mirror the signal reading it in Arduino and publishing it from Arduino. If the Joy signal has this structure

  seq: 163
    secs: 1478877490
    nsecs: 840985264
  frame_id: ''
axes: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.0, 0.08682194352149963, 0.0]
buttons: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

my mirrored signal is empty like this (except for "seq" value. Numbered are different because copy&paste in different times).

  seq: 3744
    secs: 0
    nsecs:         0
  frame_id: ''
axes: []
buttons: []

I'm still confused, I'll hope someone will help. Thank you

edit retag flag offensive close merge delete


Does rqt_graph (rosrun rqt_graph rqt_graph) show you that rosserial is subscribed to the joy topic?

gvdhoorn gravatar image gvdhoorn  ( 2016-11-11 05:46:35 -0600 )edit

@gvdhoorn: Yes, This is my graph Also the terminal states that

[INFO] [WallTime: 1478868186.772826] Setup subscriber on joy [sensor_msgs/Joy]
marcoresk gravatar image marcoresk  ( 2016-11-11 06:47:10 -0600 )edit

Same problem faced here. Any help? :'(

Jarvis_007 gravatar image Jarvis_007  ( 2016-12-15 05:18:00 -0600 )edit

I'm not sure, but by default, the arduino implementation of rosserial has a rather small receive and send buffer. Perhaps you could see whether increasing that improves things. The Joy message can be large.

gvdhoorn gravatar image gvdhoorn  ( 2016-12-15 05:49:14 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2016-12-15 13:14:44 -0600

marcoresk gravatar image

updated 2016-12-15 13:15:26 -0600

I actually solved my problem with a node that extracts some values from Joy and publish them as an array (Float32MultiArray type) in a topic. Arduino reads that topic. I think gvdhoorn's observation is correct, but I don't know how to increase the buffer.

edit flag offensive delete link more


Can you put the full code , i have the same problem. thanks in advance.

NickyDuDe gravatar image NickyDuDe  ( 2018-07-17 10:54:51 -0600 )edit

Can you publish full code?

serhatzengin gravatar image serhatzengin  ( 2019-10-16 03:13:19 -0600 )edit

answered 2016-12-16 07:55:28 -0600

gvdhoorn gravatar image

Some probably related questions (and answers):

Looking at rosserial_arduino/ros.h the buffer is set to 150 or 280 bytes. That isn't very much. You should be able to chance it by defining your own NodeHandle type.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-11-11 05:37:36 -0600

Seen: 1,270 times

Last updated: Dec 16 '16