Context: I'm trying to read a simple sensor that uses RS232 protocol to send data.
The sensor is a maxbotix US distance sensor (https://www.maxbotix.com/documents/HRXL-MaxSonar-WR_Datasheet.pdf). Documentation says:
Pin 5-Serial Output: The MB736X/MB7375 sensors have an RS232 data format (with 0V to Vcc levels) and the MB738X/MB7395 sensors have a TTL outputs. 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 maximum range reported is 4999 mm (5-meter models) or 9998 mm (10-meter models). A range value of 5000 or 9999 corresponds to no target being detected in the field of view. 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.
To model I own has RS232 data format. I did all the previous configurations (disable BT, activate UART, etc), and I can read data, but I can't decode the values.
As docu says, I should receive something like
R0300 (for 30 cm measure, the the lower limit). I'm using python to read data:
import serial ser = serial.Serial('/dev/ttyAMA0', 9600, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE, timeout=1) ser.flushInput() ser.flushOutput() ser.flush() message =  for i in range(0,8): message.append(ord(ser.read(1))) print(message) # [43, 240, 134, 51, 62, 159, 229, 0] ser.flushInput() ser.flushOutput() ser.flush() message =  for i in range(0,8): message.append(ser.read(1)) print(message) # [b'+', b'\xf0', b'\x86', b'3', b'>', b'\x9f', b'\xe5', b'\x00']
I have used Arduino with this sensor and everything works allright. But now with RPI I can't read the data properly.
Raw byte data I receive (for 8 bytes):
After the 8 bytes, the signal starts with
Sensor | RPI 3B+ Pin 5 (RS232) | Pin 10 (GPIO15) VCC | 5V GND | GND
I checked Using Serial to Read Ultrasonic Sensor?, but that approach works with TTL, not with RS232.
I can't decode this data (I have tried multiple translators without success). Am I missing something?