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?
compass.calibrate()
Re: compass.calibrate()
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("...").
Did you try to make some debug outputs before or after the call to calibrate() - like with display.show("...").
-
- Posts: 2
- Joined: Sun Sep 11, 2016 7:13 am
Re: compass.calibrate()
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?
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?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: compass.calibrate()
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.
Index to my micropython libraries.
Re: compass.calibrate()
For me the following code from the tutorial was working perfectly.
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.
Code: Select all
from microbit import *
compass.calibrate()
while True:
nadel = ((15 - compass.heading()) // 30) % 12
display.show(Image.ALL_CLOCKS[nadel])