Using BBC MicroBit accelerometer with Python

In these days I’m having a bit of fun with BBC MicroBit board and I’m learning how to use the different sensors available. The latest one I wanted to try was the accelerometer. The board can “sense” if you are moving it in any of the 3 dimensional axes: X, Y, Z. According to the documentation there are four methods available that can be used to get these values: microbit.accelerometer.get_values() will return you a tuple with all the 3 values, while microbit.accelerometer.get_x()microbit.accelerometer.get_y()microbit.accelerometer.get_z() will give you the single values.

The documentation on the official website doesn’t explain much and for example I didn’t even know what was the range of the values I can get back from these methods (by the way it’s between -1024 and 1024), so I decided to play with the code directly and write a very simple example. The small example I wrote, shows a smile on the board display if you keep it straight and shows a sad face if you bend it. This is the result:

and this is all the needed code of the application:

In the next days I will try to play with more sensors and to publish other examples.