Puck.js v2 Accelerometer/Gyroscope (LSM6DS3TR-C)

Posted on
  • Hello everyone,
    I'm trying to work with the accelerometer/gyroscope in the puck.js v2.

    I wrote a small script to transmitt accelerometer data over bluetooth as follows:

    var running = false;
    
    function accelHandlerTrigger(data) {
      console.log(data);
      var d = [
        "A",
        Math.round(data.acc.x),
        Math.round(data.acc.y),
        Math.round(data.acc.z)
      ];
      Bluetooth.println(d.join(","));
    }
    
    setWatch(function() {
      if (running) {
        Puck.accelOff();
        Puck.removeListener('accel', accelHandlerTrigger);
        running = false;
      } else {
        running = true;
        Puck.accelOn(52);
        Puck.on('accel', accelHandlerTrigger);
      }
    }, BTN, {repeat:true});
    

    However, the sensor measurements that I get seems to be too high. For example:

    "acc": { "x": -342, "y": 398, "z": 8270 }, 
    "gyro": { "x": 313, "y": -299, "z": -92 }
    
    "acc": { "x": -319, "y": 371, "z": 8098 }, 
    "gyro": { "x": 167, "y": -290, "z": -69 }
    

    From my understanding, the accelerometer default is ±2g and the gyroscope default is ±125 dps.

    Is this correct? or why are the values too high?

  • Hi,

    The values reported there are actually the raw values off the chip. Honestly, they should really have been scaled already, but now the Puck.js v2 is out there it's going to hard to change it without it being really confusing.

    • accelerometer: full-scale (32768) is 4g, so you need to divide by 8192 to get correctly scaled values
    • gyro: full-scale (32768) is 245 dps, so you need to divide by 134 to get correctly scaled values
  • Hi Gordon,

    If I divide the raw gyroscope values by the numbers you mentioned above, will that give me the scaled output in degrees per second? Or is it radians per second, maybe?

    Also, is there a way to change the full-scale sensitivity setting for the accel or gyro programmatically? The default setting sensitivity setting is too high for my project as I'm working with slightly higher RPMs.

    Thanks!

  • I believe the gyro full range is 245 degrees per second, so yes, if you divide by 134 you should get degrees per second values.

    And yes, you can reconfigure it. This is the reference for the chip: http://www.espruino.com/files/LSM6DS3TR-­C.pdf and CTRL2_G is the register that handles the scale.

    You can use Puck.accelWr(reg, data) to write to it directly - the default value is 0b00010000 (245dps, 12.5Hz) so Puck.accelWr(0x11, 0b00011100); will set it to 2000dps, not 245 - then you just need to divide by 16.384 to get degrees per second

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Puck.js v2 Accelerometer/Gyroscope (LSM6DS3TR-C)

Posted by Avatar for user116256 @user116256

Actions