ADXL345 with Free Fall detection

Posted on
  • I have connected puck to an external ADXL345 accelerometer and reading the values XYZ works just fine. I am now trying to detect a free fall, which seems a bit more complicated.

    INT1 is connected to D30, but is never triggered. I assume my accel.interrupts call is wrong, but I cannot figure it out how to enable it correctly.

    Anyone?

    var i2c = new I2C(); i2c.setup({sda:D1, scl:D2});
    
    var accel = require("ADXL345").connect(i2c,D31); accel.ff(300,25); accel.measure(true); accel.read();
    
    accel.ff(600,10);
    accel.interrupts(2,0); //INT1
    
    setWatch(function() {   console.log("Free Fall"); }, D30, {edge:"rising", debounce:10, repeat:true});
    
    
    
  • http://www.espruino.com/modules/ADXL345.­js

    Several of the functions refer to a variable thresh, likely an abbreviation for threshold.
    The tap function looks promising.
    Accelerometer interrupts generally are tripped by a change larger than the threshold and exceeding a period of time.

    The datasheet for the ADXL345 might help you figure it out.
    http://www.analog.com/en/products/mems/a­ccelerometers/adxl345.html#product-overv­iew

  • Looks like the ff function free fall is the right track.
    There are two different interrupt pins on the chip a register controls which one is used
    and a different register controls polarity.
    Which interuppt pin is being used?

    ADXL345.prototype.interrupts = function(enable,map) {
        this.i2c.writeTo(this.a,[0x2E,enable,map­]);
    }
    

    http://www.analog.com/media/en/technical­-documentation/data-sheets/ADXL345.pdf
    page 27

    Register 0x2F—INT_MAP (R/W)

    D7 D6 D5 D4 D3 D2 D1 D0
    DATA_READY SINGLE_TAP DOUBLE_TAP Activity Inactivity FREE_FALL Watermark Overrun

    Any bits set to 0 in this register send their respective interrupts to
    the INT1 pin, whereas bits set to 1 send their respective interrupts
    to the INT2 pin. All selected interrupts for a given pin are OR’ed.

  • Thx all, it looks like

    accel.interrupts(4,0) would enable free fall on INT1. Will try at home tonight.

  • So, got the latest results for my free-fall trials. It's working, but it's a tiny bit strange. The behavior is like this:

    I let the puck with ADXL345 fall for like 1.5 meters or so
    IF I pick it up soon thereafter, I get the Free Fall event
    IF I let it be, pick it up after some seconds, nothing is triggered.

    To me it looks like the interrupts are only activated once new accelerometer data is received. Would that make somehow sense? Below is the latest code for reference.

    var i2c = new I2C();
    i2c.setup({sda:D1, scl:D2});
    
    var accel = require("ADXL345").connect(i2c,D31);
    accel.ff(600,10);
    accel.interrupts(4,0); //INT1
    accel.measure(true);
    
    setWatch(function() {
      console.log("Free Fall");
    }, D30, {edge:"rising", debounce:250, repeat:true});
    
    setWatch(function() {
      console.log("BTN");
    }, BTN, {edge:"rising", debounce:50, repeat:true});
    
  • Do you have it set up to automatically sample itself? I guess that'd probably be needed for the freefall detection to work,

  • Here are some things to try.

    page 26
    Register 0x28—THRESH_FF (Read/Write)
    The THRESH_FF register is eight bits and holds the threshold
    value, in unsigned format, for free-fall detection. The acceleration on
    all axes is compared with the value in THRESH_FF to determine if
    a free-fall event occurred. The scale factor is 62.5 mg/LSB. Note
    that a value of 0 mg may result in undesirable behavior if the freefall
    interrupt is enabled. Values between 300 mg and 600 mg
    (0x05 to 0x09) are recommended.
    Register 0x29—TIME_FF (Read/Write)
    The TIME_FF register is eight bits and stores an unsigned time
    value representing the minimum time that the value of all axes
    must be less than THRESH_FF to generate a free-fall interrupt.
    The scale factor is 5 ms/LSB. A value of 0 may result in undesirable
    behavior if the free-fall interrupt is enabled. Values between 100 ms
    and 350 ms (0x14 to 0x46) are recommended.

    • The interrupt polarity could be flipped.
      Register 0x31 bit D5
      INT_INVERT Bit
      A value of 0 in the INT_INVERT bit sets the interrupts to active
      high, and a value of 1 sets the interrupts to active low.
  • Hi @Gordon, I've not set "automatic sampling" - to be honest I've got no idea. Can you point me to some sample code somewhere?

  • I might be wrong of course, but I was expecting the ff function to convert my values. The docs on Espruino ADXL345 mention that the values are mg. It's also kind of working, it just happends the free fall event is only triggered once the device moves again.

  • Try this as the datasheet mentions that setup has to come before enable
    accel.interrupts(0,0);
    accel.interrupts(4,0);

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

ADXL345 with Free Fall detection

Posted by Avatar for hansamann @hansamann

Actions