compass.calibrate()

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
DrOrthogonal
Posts: 2
Joined: Sun Sep 11, 2016 7:13 am

compass.calibrate()

Post by DrOrthogonal » Sun Sep 11, 2016 7:20 am

I'm trying to utilise the on-board magnetometer and although I can get readings they're clearly way off course.
I tried using the compass.calibrate() function and I understand I should be prompted to rotate the Micro:bit until a circle is drawn on the screen but I don't seem able to get that to run...at least, I'm not prompted to do anything. The Micro:bit seems to run the compass.calibrate() function without actually doing anything.
What am I dong wrong?
Anyone got this working?

User avatar
pintman
Posts: 4
Joined: Fri Sep 02, 2016 12:56 pm

Re: compass.calibrate()

Post by pintman » Sun Sep 18, 2016 12:54 pm

How does your code look like?

Did you try to make some debug outputs before or after the call to calibrate() - like with display.show("...").

DrOrthogonal
Posts: 2
Joined: Sun Sep 11, 2016 7:13 am

Re: compass.calibrate()

Post by DrOrthogonal » Sun Sep 18, 2016 9:57 pm

I displayed an image before the compass.calibrate() function then displayed a new
Image after it so I could be sure the command was being executed.
My images displayed as expected but the compass.calibrate() function did nothing.
Is this actually working for anyone?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: compass.calibrate()

Post by pythoncoder » Mon Sep 19, 2016 6:49 am

Alas I don't have a micro:bit to test. But to make a general point on calibrating magnetometers there are a lot of confusing instructions on the web. You need to do it well away from sources of magnetic fields - check with a real compass before moving the real compass away. The technique is normally to put the software into calibrate mode, then to slowly rotate the hardware around each of the three orthogonal axes.
Peter Hinch
Index to my micropython libraries.

User avatar
pintman
Posts: 4
Joined: Fri Sep 02, 2016 12:56 pm

Re: compass.calibrate()

Post by pintman » Mon Sep 19, 2016 12:04 pm

For me the following code from the tutorial was working perfectly.

Code: Select all

from microbit import *

compass.calibrate()

while True:
    nadel = ((15 - compass.heading()) // 30) % 12
    display.show(Image.ALL_CLOCKS[nadel])
When calibrate() is executed there is one led that moves while tilting the board. You have to draw a circle with that LED. Afterwards the compass can be used.

Post Reply