Ghica - my solution serves to illustrate a number of things:
- The mismatch in the BLE readInteger means you see 6 separate 8 bit integers, instead of 3 separate 16 bit integers
- You have to know they are supposed to be 16 bit, signed AND little endian to make sense - In fact, you have to know the answer in advance to set up the algorithms to get the correct answer - see below.
- I can, with extreme difficulty correctly read the values from a STATIC micro:bit, where the values are NOT changing
- I can convert the values into X,Y and Z coordinates which are CORRECT.
- As a method of reading changing Accelerometer coordinates, my solution has NO practical value!! Hopefully, the eagerly awaited new version of BLE will solve the problem.......
This is what I did:
- Lock the mocro:bit down on my desk.
- Use the micro:bit Blue App to read the accelerometer data and to set the refresh period to 640 mS - maximum.
- Wait for the values to stabilise and write them down
- Disconnect from micro:bit Blue and connect AI Companion to develop and run my very tortuous App
- I can calculate the same coordinates as I read in micro:bit Blue App
There is a misprint in the micro:bit Bluetooth profile at:
In the Accelerometer Service it says "Value contains fields which represent 3 separate accelerometer measurements for X, Y and Z axes as 3 unsigned 16 bit values in that order and in little endian format." --- WRONG
and in the Accelerometer Characteristic it says "Contains accelerometer measurements for X, Y and Z axes as 3 signed 16 bit values in that order and in little endian format. X, Y and Z values should be divided by 1000 "
And, indeed, depending on how you position the micro:bit, you do get 2s complement negative values, especially on the Z Axis - micro:bit Blue proves this!
I have tried to use the string method, with the weird characters for ASCII values below 32 in another situation, but I couldn't get it to work at all. I ended up using my own method, again based on repeated readInteger.
Neil