Hello,
I am trying to receieve a data packet of 70 bytes from one board to another with serial.
What i get when printing the characters will be shown in attached picture.
I believe these are ASCII symbols.
The baud rate has been checked and the data has been verified correct through RealTerm. So the board that sends data is really working properly.
My question is how can i transform these symbols into useable numbers since the packet is like this:
I would like to have a value of pressure that i can use for calculation further.
Byte index Description
0 Frame character '#' uint8
1
2 Pressure0 float32
3
4
...
9
10 Pressure2 float32
11
12
...
So each 4 bytes should represent one value of pressure.
Hope the code that i have been using is correct and that any of you could help me achieve final objective. I would like to have a value of pressure that i can use for calculation further.
Thanks in advance.
char buf[70];
String readString;
#define read7hp Serial5
int readline(int readch, char *buffer, int len) {
static int pos = 0;
int rpos;
if (readch > 0) {
switch (readch) {
case '\r': // Ignore CR
break;
case '\n': // Return on new-line
rpos = pos;
pos = 0; // Reset position index ready for next time
return rpos;
default:
if (pos < len-1) {
buffer[pos++] = readch;
buffer[pos] = 0;
readString += readch;
}
}
}
return 0;
}
union {
float f;
char c[4];
} conv;
void setup() {
Serial.begin(115200);
read7hp.begin(115200);
}
void loop() {
if (readline(read7hp.read(), buf, 70) > 0) {
conv.c[0] = buf[33];
conv.c[1] = buf[34];
conv.c[2] = buf[35];
conv.c[3] = buf[36];
Serial.print("You entered: >");
Serial.print(buf);
// Serial.print(readString[33]);
// Serial.print(readString[34]);
// Serial.print(readString[35]);
// Serial.print(readString[36]);
// Serial.print(conv.f);
// Serial.print(buf[1],HEX);
// Serial.print(' ');
// Serial.print(buf[2],HEX);
// Serial.print(' ');
// Serial.print(buf[3],HEX);
// Serial.print(' ');
// Serial.print(buf[4],HEX);
Serial.println("<");
readString="";
}
}






