Detecting movement #2540
Replies: 10 comments
-
Posted at 2017-10-13 by user82265 I am trying to use this, but every now and then the magnet readings keep moving. Especially when I have a magnet close sometimes it doesn't come to a stop. The difference keeps reading at about 200-700. Anything you know I could do about this? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-10-16 by @gfwilliams You could try just increasing the threshold value Otherwise if the readings keep varying randomly you could try keeping a short term average of the readings and comparing that to work around noise? This isn't tested, but something like it should work:
You could also do a median filter, which is relatively easy to do with the built-in array.sort. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-02-28 by Ken I already have a couple Espruino wifi boards but am looking to get a Puck due to it's small form factor to use to track a persons movement. Something like a fitness tracker. Would using the magnetometer in the fashion described above allow you to track things like arm motions0 and get values that could be used like an accelerometers x,y,z values? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-03-05 by @gfwilliams Hi! You couldn't get something that was identical to the accelerometer, but you can tell reasonably well when someone is moving or not. You're basically getting values that tell you where North is - so you can detect changes in rotation but not lateral movements, in the same way the accelerometer won't detect rotation but will detect lateral movement. Honestly you'd have to try and see if it did what you needed - but worst case you could actually add an accelerometer - or there are devices like the Nordic Thingy that can run Espruino and are loaded with all the sensors you could possibly want (there should be docs and binaries for it in the next month or so). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-03-05 by Ken Cool, makes sense. That's what I figured but was not sure if I was missing something. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-04-12 by Pzr0 I noticed that when I stop moving my puck the magDiff value may start getting higher and after some seconds starts getting lower.. What can i do for that? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-04-16 by @gfwilliams If you've detected movement (magDiff is higher than your threshold) you can set However you're likely to then get some iterations when movement isn't reported when the device has actually moved. The other thing you can do is lower the period of the average (eg change |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-05-01 by user89458 The Puck.onMag function returns an orientation about once per second. Is it possible to speed that up somehow? I can get faster readings by repeatedly calling Puck.mag(), so it's possible. (Although if I ask for too many, too fast the program crashes.) That said, I would prefer the event-based polling. Is there a time constant somewhere that could be changed? Here is the code that generates the overflow, btw. var x=0; var zero = Puck.mag(); while(true){ |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-05-02 by @gfwilliams Sure - you just specify a number in What kind of overflow did you get? If you do |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-05-02 by user89458 Thank you! Works like a charm. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-03 by @gfwilliams
A few people have asked about having an accelerometer so they can detect movement - but it's not the only way.
For a lot of things you can still use the magnetometer. The magnetic field changes a lot, not just with angle, but with what other items the Puck.js is near. It's almost impossible to move Puck.js without changing the magnetometer's reading at least a little.
For instance try this code:
It looks for changes in the magnetic field about once a second, and will light the red LED if it has changed more than a little. After a few seconds of no movement the LED will turn off.
It's easy, low power, and seems to work pretty well.
Beta Was this translation helpful? Give feedback.
All reactions