How can i send a message from ROS to arduino using rosserial?
I want LED 13 on my Arduino Uno board to glow when I pass the number 100 as command line argument from ROS. Here is my arduino code:
#include <ros.h>
#include <Arduino.h>
#include <std_msgs/Int8.h>
ros::NodeHandle nh;
void ledGlow(const std_msgs::Int8& val){
if(val.data==100){
digitalWrite(13, HIGH);
}
else{
digitalWrite(13, LOW);
}
}
ros::Subscriber<std_msgs::Int8> led("led/start", &ledGlow);
void setup() {
pinMode(13, OUTPUT);
nh.initNode();
nh.subscribe(led);
}
void loop() {
nh.spinOnce();
delay(10);
}
I am giving the following commands in the terminal:
- roscore
- rostopic pub led/start std_msgs/Int8 100
After giving the second command LED 13 doesn't glow, also RX led on arduino board doesn't blink.
Try adding serial output to your Arduino program to determine if the ledGlow callback is being called, if yes check what value is in the message
I tried adding Serial.println("Hello"); inside the callback function but I'm not getting any output on serial output screen. Also, when I try printing something inside the loop, I get garbage value on serial output screen. Please help! @VictorLamoine
Make sure to adjust the baudrate of the serial terminal