Trying to access the accelerometer service in android

I’d posted earlier about using the accelerometer with python. I eventually did have good success with that, but then found that the range was too short for the project I’m working on.

So I thought, what if I hack up an android app to get the xyz values and send them to the computer using Open Sound Control. Tried Python + Beeware – hiccups with android permissions (although I think those will be resolved pretty soon, with some assistance from Beeware devs).

To cover all the bases, I also asked a LLM for a Kotlin app template, which, on the second revision, turned out to be 99% correct actually. But I didn’t realize it was correct because it wasn’t connecting to the accelerometer service. This drove me nuts for a while, until I put in some logging to print out the service ids that the android app was reading from the microbit.

What I found then is that the accelerometer service (uuid = e95d0753-251d-470a-a062-fa1922dfa9a8) appears in the service list in python on the computer, but does not appear in the service list in android on the phone. The app is finding the device and requesting the service by ID, but the service list is not as I expected based on the python results.

:grimacing:

(Like, who would have guessed that? A service is a service, right? Nah.)

So that’s why I’m writing here – to see if anybody has any idea why the same hardware device would present different services in different environments.

Also, how to use UART? Android does see the microbit event service… that’s UART? Or am I mistaken… I had been avoiding UART because you get notifications from the device, but how to extract data from the notifications is still a mystery to me.

Any advised either about that weird android problem or about using UART, would be greatly appreciated – the project goes on stage in about three weeks and there’s also music to produce, time is getting short… really didn’t expect this much hassle.

hjh

1 Like

Have you tried a bluetooth browser app on the Android device, like nRF Connect: https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp&hl=en_US .

If nRF Connect can connect to the micro:bit and discover the accelerometer service, it would indicate there’s some bug with your app. If nRF Connect also can’t discover the service, it could mean either: a) the micro:bit isn’t actually running the service correctly or b) that your Android device is not passing the service through to apps (this seems unlikely though — iOS can do this with some services, but I’ve never seen iOS or Android do that with the micro:bit accelerometer service)