Or you can literally just add Puck.magOn(); to your code.
What I think might be happening is the magnetometer is taking a little bit more time to power up than we're giving it - so Puck.mag() (which powers on the magnetometer, takes a reading, and powers it off unless Puck.magOn() had been called beforehand) is getting bad readings sometimes.
By calling Puck.magOn() you're leaving the magnetometer on, and it may fix this issue for you.
I've just tested here and while an 'old' batch of Puck.js 2.1a works fine, it seems the most recent batch must be using a slightly different batch of magnetometer (it's the exact same type) which takes a bit longer to start up. I'll make a firmware tweak here and see if I can fix it
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi! Sorry about this - that's an odd one. Just to confirm, what does your Puck's PCB say on the rear?
Puck.js 2.1a
?So I imagine right now you're doing something like:
But what happens if you do this instead?
Or you can literally just add
Puck.magOn();
to your code.What I think might be happening is the magnetometer is taking a little bit more time to power up than we're giving it - so
Puck.mag()
(which powers on the magnetometer, takes a reading, and powers it off unlessPuck.magOn()
had been called beforehand) is getting bad readings sometimes.By calling
Puck.magOn()
you're leaving the magnetometer on, and it may fix this issue for you.I've just tested here and while an 'old' batch of Puck.js 2.1a works fine, it seems the most recent batch must be using a slightly different batch of magnetometer (it's the exact same type) which takes a bit longer to start up. I'll make a firmware tweak here and see if I can fix it