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
--] }});
--] ^
Thanks for your help,
1) CS is set to high according to my schematic
2) Wiring is good as far as I can tell
3) I2C address is correct as far as I can tell too, although I have tried many different ones and still get the WHO_AM_I check fail
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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:
When using hardware I2C, I get a write error:
When using software I2C, I get a who_am_i error:
Thanks!