Bluetooth + accelerometer

Hi, getting started with micro:bit here.

At this point, I’m only interested in accelerometer data.

Would it be preferable to access the accelerometer service directly, or through UART?

“Directly” as in https://github.com/alcir/microbit-ble/blob/master/python/accelerometerBall.py

    svc = p.getServiceByUUID("e95d0753-251d-470a-a062-fa1922dfa9a8")
    ch = svc.getCharacteristics("e95dca4b-251d-470a-a062-fa1922dfa9a8")[0]
    chper = svc.getCharacteristics("e95dfb24-251d-470a-a062-fa1922dfa9a8")[0]

... then, in the loop

coord = np.fromstring(ch.read(), dtype=np.int16, count=3)

The same repository has a UART collector example (https://github.com/alcir/microbit-ble/blob/master/python/uart_collector.py) – I can see where it’s waiting for a notification, but I don’t see where the data live, in this example.

So another way to ask the question is: The direct access approach looks superficially easier, but is that only shooting myself in the foot?

TIA,

hjh

Hi @jamshark70 and welcome to the forum,

I’m not sure I see where/how the bluetooth example is actually getting data. Does it work?

It’s setting the Client Characteristic Configuration to not send notifications. I think I’d first try using the Accelerometer service and notifications. You can look at the CODAL code (micro:bit v2 runtime) for the Accelerometer service here: https://github.com/lancaster-university/codal-microbit-v2/blob/master/source/bluetooth/MicroBitAccelerometerService.cpp . It looks like it will post a notification as soon as the accelerometer updates. A client that subscribes to the notification will probably get updates about as frequently as is possible via Bluetooth.

The UART example does appear to be using Notifications….doing something similar with the accelerometer service may be a bit better.

1 Like