Most recent activity
-
Here's a fun way to visualize live gyro data for the z axis - especially fun to roll the puck along a desk! Also fascinating to swing it around fast and film it in slow motion, shows a really nice fast response.
Gyro is quite power hungry so you can tap the puck to toggle it on and off.
let callbackCount = 0; Puck.on('accel', function(a) { callbackCount++; if(a.gyro.z > 0) { analogWrite(LED1, a.gyro.z / 32764); analogWrite(LED2, 0); } else { analogWrite(LED1, 0); analogWrite(LED2, -a.gyro.z / 32764); } }); let gyroOn = false; function toggleGyro() { if(gyroOn) { Puck.accelOff(); digitalWrite([LED1, LED2], 0); } else { Puck.accelOn(104); // Set max range to 2000 degrees per sec, 104 Hz Puck.accelWr(0x11, 76); } gyroOn = !gyroOn; } setWatch(toggleGyro, BTN, {edge:"rising", debounce:50, repeat:true}); digitalWrite([LED1, LED2], 0); /* let lastCount = 0; setInterval(() => { let change = callbackCount - lastCount; print((change / 5).toFixed(1) + ' callbacks / sec'); lastCount = callbackCount; }, 5000); */
@Gordon - I did notice the callback seems to be called frequently (about 280 times / sec), regardless of the rate passed in to accelOn() - bug?
-
On power usage - the gyroscopic effect requires motion, so that's why gyro is significantly higher power than accelerometer. Accelerometer is just a mass on a spring, I think MEMS gyros tend to be tuning-fork type arrangements that are induced to vibrate at a certain frequency.
Therefore it's also likely there's a bit of a warm-up time, and the one-shot call will probably never return reasonable values for the gyro.
@BrianH - if your spindle is fixed, ie there will never be linear motion of it, and you can mount the puck so the Z axis is aligned with the spindle axis, then using purely the accelerometer might be best. In that setup it should measure gravity without any other accelerations (if it's not on the axis you'd get some centripetal acceleration mixed in).
For each rotation the accelerometer value (in either x or y) will basically be a sinusoid - so you can just count a rotation each time there's a sign change from -ve to +ve in acc.x for example. No drift to worry about, power will be lower (if you manually turn off gyro via register), and I suspect maximum supported rotational speed is higher (2000 dps max scale for gyro is still "only" 5.5 full rotations per second, so with an accelerometer at 12.5Hz or above you should be able to beat that).
Ah yes, works as expected after a power cycle. I thought I'd only been setting that 0x11 register for full scale modes as shown in the code but it's possible I poked something else at some point.