-
• #2
The senser will raise an event every time when a new measurement is available. There is no sensitivity or the like.
-
• #4
@Gordon
I'm new to puck js and this is just an amazing device, I'm glad with it and get it working in less than 5 minutes.
Working everyday with ESP32, Lopy, Sodaq and LoraWan devices, your little puck open me new doors for business.
I usually use accelerometer with IRQ detection with programmed thresold to get IRQ only when device is moved.
So according this post it's not possible yet, so what's the best deal to detect move of the device with best consumption usage ? (compare values between wakes ?)
Any example code would be welcome
thanks for your help -
• #5
I have a post here, which is what I've been using to detect movement:
http://forum.espruino.com/conversations/301185/
By default it measures the magnetic field at 0.63Hz, which keeps the wakeups to a minimum while still being fast enough to detect movement pretty well.
Hope that helps!
-
• #6
@Gordon
Thanks, I missed this one
I tried something similar with start/stop movement detection with button, when pressed, Green led indicate it's on and then blink Red in case of movement. another push stop detection by blue blink
New position is saved like this moving and leaving puckjs to another place will stop detection until it's moved again. Seems to works, need to play with threeshold.
Here the code, I'll try your since your math detection looks better than mine ;)var th = 10; var x =0; var y =0; var z =0; var accFirstRead = true; var acc = false; Puck.magOff(); function doJob(x,y,z) { var b = Puck.getBatteryPercentage(); var t = E.getTemperature(); var l = Puck.light()*100 ; console.log("Batt", b, " Temp",t, " Light",t ); console.log("Diff X:",x, " Y:",y, "Z:",z); } setWatch(function() { if (acc) { Puck.magOff(); acc = false; digitalPulse(LED3, 1, 100); console.log("Accel OFF"); } else { accFirstRead = true; acc = true; //Puck.magOn(0.31); Puck.magOn(); digitalPulse(LED2, 1, 100); console.log("Accel ON"); } }, BTN, {edge:"rising", debounce:50, repeat:true}); Puck.on('mag', function(xyz) { var diffx = xyz.x-x; var diffy = xyz.y-y; var diffz = xyz.z-z; x = xyz.x; y = xyz.y; z = xyz.z; //digitalPulse(LED3, 1, 5); //console.log(xyz); //doJob(xyz); if (accFirstRead) { accFirstRead = false; doJob(x,y,z); } else { if (Math.abs(diffx)>th || Math.abs(diffy)>th*2 || Math.abs(diffz)>th*2) { digitalPulse(LED1, 1, 250); doJob(diffx, diffy, diffz); } else { //console.log("Diff X:",diffx, " Y:",diffy, "Z:",diffz); } } });
-
• #7
Hi @Gordon,
I have a magnetometer related question and think this post could host it, if not please move it.
I need to reset the magnetometer upon my command, now can I do that ? Now when you upload a new code or restart the Puck, the magnetometer value is reset. Do you have a possibility somewhere to store the last value take it once restarted ? Can I do that custom implementation on my own ?
Thank you!
-
• #8
At the moment there's no 'built-in' calibration, so it all has to be done by your own code anyway.
A lot of code does something like this:
var zero = Puck.mag(); var doorOpen = false; function onMag(p) { p.x -= zero.x; p.y -= zero.y; p.z -= zero.z; var s = Math.sqrt(p.x*p.x + p.y*p.y + p.z*p.z); var open = s<1000; if (open!=doorOpen) { doorOpen = open; digitalPulse(open ? LED1 : LED2, 1,1000); } } Puck.on('mag', onMag); Puck.magOn();
So in that case, the calibration value is stored in the
zero
variable. If you want to reset the magnetometer value, all you have to do is runzero = Puck.mag();
again. -
• #9
Hi @Gordon,
I need first zero to be saved forever, my starting point for any calculations. So one approach could be, on first code upload to save externally the first zero, and also save it on the Puck which will survive during resets. If a new code is uploaded it must be saved, containing the first zero as value and discard the current Puck.mag() value. What do you think ?
Thank you!
-
• #10
I'm not quite sure I understand, but it sounds ok.
If you want to save just the value without doing a full
save()
, take a look at http://www.espruino.com/FlashEEPROM -
• #12
Right now, the data shouldn't ever get cleared - unless you call the
erase
function in the library.In future firmwares, doing a firmware update may clear it though - in a lot of cases it's a convenient way of resetting absolutely everything back to defaults.
-
• #14
It's actually reading all the data, but the console is truncating it so you don't accidentally print lots of stuff to your screen.
All you need to do is type
print(E.toString(f.read(0)))
to print the info - print won't truncate it for you.If you still need it escaped and in String form, try:
print(JSON.stringify(E.toString(f.read(0))))
Am I interpreting the docs correctly in that Puck can be woken up on a mag event. I can adjust the sample rate down but I still get readings even when the puck is stationary. I'm wondering if this is because the readings - despite the puck not moving - are actually changing. They differ each reading by a very small amount.
Which leads me to ask, if this is the case and the small changes trigger a reading, can the sensitivity be turned down so that when it is stationary the Puck can sleep.