I'm back asking for help please with another problem which is again causing me stress. I've been trying to understand how a stream of data which is presented in binary data format can be correctly deciphered.
The data is coming from an HRXL-MaxSonar-WR device and the manual explains it is presented as follows:
Pin 5-Serial Output: The MB7366 sensors have an RS232 data format (with 0V to Vcc levels) and the output is an ASCII capital “R”, followed by four ASCII character digits representing the range in millimeters, followed by a carriage return (ASCII 13).
The serial data format is 9600 baud, 8 data bits, no parity, with one stop bit (9600-8-N-1).
Because the data is presented in a binary data format, the serial output is most accurate.
I've cobbled together the following sketch to see what is coming out of the sensor:
byte Bite;
void setup() {
// initialize both serial ports:
Serial.begin(9600);
Serial1.begin(9600, SERIAL_8N1);
}
void loop() {
// read from port 1, send to port 0:
if (Serial1.available()) {
Bite = Serial1.read();
Serial.print("Decimal \t:"); Serial.println(Bite, DEC);
Serial.print("HEX \t:"); Serial.println(Bite, HEX);
Serial.print("Bin \t:"); Serial.println(Bite, BIN);
Serial.print("Ascii \t:"); Serial.write(Bite);
Serial.println();
Serial.println("\n------------------\n");
if (Bite == 'R') Serial.println("Match");
delay(1000); // delay to check ouput
}
}
I've included the output below; the data stream repeats a set of 6 characters but although the received start and end characters are consistent they are not what is expected. The start-of-data character should be a capital R
Am I missing a fundamental point somewhere?
Dec :43
HEX :2B
Bin :101011
Ascii :+
------------------
Dec :99
HEX :63
Bin :1100011
Ascii :c
------------------
Dec :99
HEX :63
Bin :1100011
Ascii :c
------------------
Dec :99
HEX :63
Bin :1100011
Ascii :c
------------------
Dec :99
HEX :63
Bin :1100011
Ascii :c
------------------
Dec :121
HEX :79
Bin :1111001
Ascii :y
------------------
Dec :43
HEX :2B
Bin :101011
Ascii :+
------------------
Dec :99
HEX :63
Bin :1100011
Ascii :c
------------------
Dec :99
HEX :63
Bin :1100011
Ascii :c
------------------
Dec :99
HEX :63
Bin :1100011
Ascii :c
------------------
Dec :99
HEX :63
Bin :1100011
Ascii :c
------------------
Dec :121
HEX :79
Bin :1111001
Ascii :y
------------------