• Espruino version: 2v03
    Using LIS2DH12 Module, I2C

    Hi Gordon,

    I'm struggling to read from the LIS2DH12 accelerometer. The error I get when using the hardware I2C is a bit cryptic (only info I found on this was an old forum post), but when I use software I2C I get a more descriptive error: WHO_AM_I check failed. I have confirmed that I've specified the correct pinouts when instantiating I2C... Was hoping you could give me more information on the errors?
    I'm just using the sample code, but here's what I have anyway:

    var i2c = new I2C();
    
    i2c.setup({sda: D25, scl: D26});
    var accel = require("LIS2DH12").connectI2C(i2c, {callback:function(xyz) {
       // callback whenever data is received
       console.log(xyz);
       // prints { "x": 3.90625, "y": -7.8125, "z": 984.375 }
    }});
    accel.setPowerMode(on?"low":"powerdown");
    
    

    When using hardware I2C, I get a write error:

    Connected
    --] >
    --]  ____                 _ 
    --] |  __|___ ___ ___ _ _|_|___ ___ 
    --] |  __|_ -| . |  _| | | |   | . |
    --] |____|___|  _|_| |___|_|_|_|___|
    --]          |_| espruino.com
    --]  2v03 (c) 2018 G.Williams
    --] 
    --] >
    --] Uncaught InternalError: I2C Write Error 33281
    --] 
    --]  at line 1 col 18
    --] b.writeTo(c,a|128);return b.readFrom(c,d)
    --]                  ^
    --] in function "r" called from line 1 col 96
    --] ...back;if(this.r(b.WHO_AM_I,1)[0]!=b.I_AM_MASK)throw"LIS2DH12 ...
    --]                               ^
    --] in function "f" called from line 2 col 118
    --] ...on(a,d){b.writeTo(c,a,d)},a)
    --]                               ^
    --] in function "connectI2C" called from line 10 col 3
    --] }});
    --]   ^
    
    

    When using software I2C, I get a who_am_i error:

    Connected
    --] >
    --]  ____                 _ 
    --] |  __|___ ___ ___ _ _|_|___ ___ 
    --] |  __|_ -| . |  _| | | |   | . |
    --] |____|___|  _|_| |___|_|_|_|___|
    --]          |_| espruino.com
    --]  2v03 (c) 2018 G.Williams
    --] 
    --] >
    --] Uncaught LIS2DH12 WHO_AM_I check failed
    
    

    Thanks!

  • Just quickly looking at the datasheet:
    Do you set CS to high?
    Is your wiring good?
    Is the I2C address correct?

    For example, have a bunch of INA226 modules that don't use the default I2C address, and SDA and SCL markings on the breakout board are swapped...

About

Avatar for user94249 @user94249 started