Hello guys! How are you?
So a little background on the project I'm trying to make work. I would like to use an Arduino Mega to act as a buffer between ROS and a very old (yet accurate) DSP board which provides encoder ticks and and motor control over serial port. This board sends encoder info as HEX numbers in a string format.
So right now, I'm facing a problem. The board sends the info in the form of "V=XXXXXXXX,YYYYYYYY", so I need to split the string line in two char arrays and use a convert function such as strtol. This is what I've done:
unsigned int X = 0;
unsigned int Y = 0;
char bufferX[8];
char bufferY[8];
String str = "";
String str_ = "";
Serial1.find('=');
str = Serial1.readStringUntil(',');
str_ = Serial1.readStringUntil('\n');
strcpy(bufferX, str.c_str());
X = (unsigned int)strtol(&bufferX[1], NULL, 16);
strcpy(bufferY, str_.c_str());
Y = (unsigned int)strtol(&bufferY[1], NULL, 16);
And then Serial.print(); to show the results on the serial console. My problem is that, if I only do one strcpy(); it works perfectly, but not with two, in which case the Mega just reboots and reboots interminably. My guess was that I have made a memory overflow of some sort, but I tried many other solutions like sprintf(); it's all the same.
Could someone lighten me on how I can make this work? I would be super grateful! Thanks!