Something wrong with my arduino code? Lost sync with device, restarting...
Hi guys. I'm using an arduino mega with the rosserial stack. I tried to write a code to read the voltage of a LI-FE accumulator. Rosserial should show me the measured voltage in a terminal. The last step of my project was to sum two characters, so that i can connect more accumulators and see which accumulator has which voltage. The crazy thing about that is that it worked as I used this order: "measured voltage, text" but when I change the order to "text, measured voltage" my terminal says: lost sync with device... after i typed "rosrun rosserial_python serial_node.py /dev/ttyACM0" and "rostopic echo chatter".
Here is the code that worked:
int spgn1 = A5;
int ledpin = 13;
int Spannung1=0;
double Spgn1=0.0;
#include <ros.h>
#include <std_msgs/String.h>
ros::NodeHandle nh;
std_msgs::String str_msg;
ros::Publisher chatter("chatter", &str_msg);
char Text[17]=" Volt an Zelle 1";
char Zelle1[32]="";
void setup() {
// put your setup code here, to run once:
pinMode(ledpin, OUTPUT);
nh.initNode();
nh.advertise(chatter);
}
void loop() {
Spannung1 = analogRead(spgn1);
Spgn1 = ((0.005*Spannung1)-0.0703);
dtostrf(Spgn1,10,2,Zelle1);
strcat(Zelle1,Text);
str_msg.data = Zelle1;
chatter.publish( &str_msg );
nh.spinOnce();
delay(5000);
}
And here is the code that did not work:
int spgn1 = A5;
int ledpin = 13;
int Spannung1=0;
double Spgn1=0.0;
#include <ros.h>
#include <std_msgs/String.h>
ros::NodeHandle nh;
std_msgs::String str_msg;
ros::Publisher chatter("chatter", &str_msg);
char Text[]="Zelle 1: ";
char Zelle1[32]="";
void setup() {
// put your setup code here, to run once:
pinMode(ledpin, OUTPUT);
nh.initNode();
nh.advertise(chatter);
}
void loop() {
Spannung1 = analogRead(spgn1);
Spgn1 = ((0.005*Spannung1)-0.0703);
dtostrf(Spgn1,10,2,Zelle1);
strcat(Text,Zelle1);
str_msg.data = Text;
chatter.publish( &str_msg );
nh.spinOnce();
delay(5000);
}
I hope you could understand what my problem is and i also hope that you can help me with that.
Thank you