Trying to use serial communication to receive measurements from this sensor
All documentation is included free on the website.
The sensor requires bytes of hex to be sent and then it will reply with more bytes of hex information that must be converted to 11 distance measurements. The sensor is connected to my laptop via an RS232 to USB convertor.
Here is the code that I have
--------------------------------------------------------------------------
s = serial('COM4', 'BaudRate', 115200, 'DataBits',8,'StopBits',1);
flushoutput(s);
flushinput(s);
fopen(s);
h = hexToBinaryVector(['0xde','0x01','0x05','0x59','0x83'],40);
h1 = mat2str(h);
fwrite(s, h1,'uint8');
pause(0.05)
a = fread(s);
pause (2);
fclose(s);
-----------------------------------------------
I am of the understanding that MATLAB cannot send hex so this is why I have converted the data to binary.
When I open (a) which I thought would be the data I get a list of 225 numbers that range from 91 to 191.
Does anyone have any advice on how I can get it working properly?
Thanks..