Arduino Library not working with ROS

asked 2015-06-24 22:27:37 -0500

evelynf gravatar image

Hi all. I am using an LED library (Adafruit_NeoPixel) with ROS & an Arduino UNO. My LED code works without being connected to ROS. But once I connect it to ROS, the Arduino will not setup the led strip to the pin I set it to. It will only set up the pin if I directly set it up using pinMode. However, I can't use pinMode for an LED strip. I have to use a library. I tried three different libraries and all of them had the same problem. I'm pretty confident that the problem is setting up the pin through a library since all of my messages are being received fine. Any ideas on how to get my LED strip to light up when it's receiving messages? I'm attaching the test code I've been running to try to get my strip to light up.

Thanks!!!

#include <ros.h>
#include <std_msgs/Bool.h>
#include <Adafruit_NeoPixel.h>

ros::NodeHandle  nh;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(240, 6, NEO_GRB + NEO_KHZ800);



void messageCb(const std_msgs::Bool& toggle_msg){
  strip.setPixelColor(1,strip.Color(0, 150,0));
  strip.show();
  }


ros::Subscriber<std_msgs::Bool> sub("toggle_msg", &messageCb );

void setup()
{ 

 strip.begin();
 strip.show();
 nh.initNode();
 nh.subscribe(sub);
}

void loop()
{ 
  nh.spinOnce();
  delay(1);
}
edit retag flag offensive close merge delete

Comments

Firstly, you might consider using std_msgs/Empty, unless you are actually sending data to it. Things to check: is there any initialization you need to do to get the code working? What is the output of rostopic list? How is the arduino connected to the computer? Which ROS version are you using?

allenh1 gravatar image allenh1  ( 2015-06-25 12:29:09 -0500 )edit

When it works fine without being connected, what does your code look like? Lastly, is the library in your library path?

allenh1 gravatar image allenh1  ( 2015-06-25 12:30:38 -0500 )edit