Search code examples
bbc-microbit

How can I access the light sensor value when using bbc:microbit over bluetooth?


I am playing around with bbc:microbit using bluetooth web api to access the microbit service data (button event, led, magnetometer, ...).

It looks like the light sensor information are not accessible from the javascript API. From the microbit documentation, light sensing are accessible from the led service, but it looks like the lib is missing them.


Solution

  • The micro:bit Bluetooth profile is defined at:

    https://lancaster-university.github.io/microbit-docs/resources/bluetooth/bluetooth_profile.html

    It does not expose the light sensor information by default over Bluetooth. My initial thought for a quick workaround is that you could send the value over the Bluetooth UART service. I used the editor at: https://makecode.microbit.org/#editor to create a hex file for the micro:bit that seemed to work:

    enter image description here