BLE - Convert two bytes in one signed 16bit integer

Hi,

I'm facing an issue from several days and I can't find the solution !

I have a BLE device that send accelerometer data, over BLE.
My goal is to get them on Mit app inventor.

The data payload is like this : XXXXYYYYZZZZ (Ex: 0061 008A FF51)
Where XXXX is two bytes for the YAW, YYYY for the PITCH and ZZZZ for the ROLL of the accelerometer.

Whis this block I can't get all the 6 bytes :
blocks (5)
component_event

Issue is when I try to combine two bytes to one number (I can have negative number) :
blocks (4)

blocks (1)

For example :
"FF4C" give me "-180" : it's OK !
00B4 give me -76, it's wrong, I need to have 180.
-76 is because AI return me a signed 8 bit (only "B4") and not a signed 16bit as I want (00B4)

Do you know where is the issue ?

Thanks for your help !

1 Like

Why not use RegisterForShorts instead with signed = true?

1 Like

Because I'm also receiving another frame where I need to extract byte by byte.
But perheaps it's the wrong way...

(I just tried registerforshort but LSB and MSB seem to be inverted :thinking: )

I can't believe they have no way to combine two bytes to make a signed 16 bit, no ?

1 Like

You could try this:

Edit: You should be able to drag the picture in App Inventor to copy it into your project.

1 Like

It works !!!

Thanks a lot !

(I did not know that we can drap the picture in AI, nice feature !)

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.