[Microbit-Python] Accelerometer orientation

M.-A. Lemburg mal at egenix.com
Thu Feb 18 09:13:20 EST 2016


On 18.02.2016 13:04, Loop Space wrote:
> Hi all,
> 
> Brief intro: I recently got a microbit as part of the initial roll-out to teachers.  I've no
> experience with python, but plenty of experience with other scripting languages so using micropython
> seemed the easiest of the various options available to me.  I'm using the mu editor to write and
> flash scripts to the microbit via USB serial link.
> 
> So far, so good.
> 
> I'm just testing stuff, and was trying to work with the readings from the accelerometer.  When the
> microbit is just resting, that should basically tell me what direction "down" is in.  I can use the
> following script to get its values:
> 
> from microbit import *
> 
> DELAY=100
> 
> while True:
>     sleep(DELAY)
>     x,y,z = accelerometer.get_x(),accelerometer.get_y(),accelerometer.get_z()
>     print(x,y,z)
> 
> Via the REPL interface in mu, I get a stream of values.  As I turn the microbit, obviously those
> values change.
> 
> With the microbit essentially flat (leds uppermost), the vector is heavily weighted negatively in
> its z-component (values of the order of -1000).  This says that the z-axis goes vertically up from
> the leds.  By turning the microbit, I can find where the other axes point.
> 
> This gets to my question.  It would appear that the x-axis runs across the microbit with positive
> x-axis running out towards the B button, whilst the y-axis runs from the leds to the pins.
> 
> As far as I can tell, that means that the microbit's orientation is left-handed as opposed to the
> almost universally accepted right-hand axes.
> 
> Is my analysis right?  Or am I misinterpreting what the numbers from the accelerometer mean?

The values of the meter go from -1024 to +1024.

Now, let's assume you are holding the MB horizontally,
with the LED panel up and the pins pointing to you.

For the x-axis, it's +1024, if you hold the MB vertically with
the B button pointing down and -1024 if you hold it in the
other direction, with button A down. It's 0 if you hold the MB
horizontally.

For the y-axis, you get -1024 if you turn the MB up, so that
the pins point to the sky, 0 when it's held horizontally and
+1024, when turning the MB so that the pins point down.

The "accelerate" part in accelerometer doesn't seem to
have much meaning for x- and y-axis, i.e. they don't seem to
measure acceleration, but instead orientation. Only the z-axis
appears to actually work in terms of acceleration, since it
changes its value depending on how you whether the MB up and
and down.

I haven't found a good use for the z-axis yet.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Feb 18 2016)
>>> Python Projects, Coaching and Consulting ...  http://www.egenix.com/
>>> Python Database Interfaces ...           http://products.egenix.com/
>>> Plone/Zope Database Interfaces ...           http://zope.egenix.com/
________________________________________________________________________

::: We implement business ideas - efficiently in both time and costs :::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/
                      http://www.malemburg.com/



More information about the Microbit mailing list