10 years, 10 months ago.

Data Accel

Please help me how can I read data accelerometer from this Library? I need use mbed read data LIS3DH by I2C. This is my code I try but it is not working.

include the mbed library with this snippet

#include "mbed.h"
#include "LIS3DH.h"
Serial pc(USBTX, USBRX);    //Tx, Rx


I2C i2c(p28,p27);
LIS3DH data(i2c, 0x19);
float dt_usr[3];
float x,y,z;

int main ()
{
pc.baud(115200);
while (1) {
    //x=data.read_data(*dt_usr[0]);
    //y=data.read_data(*dt_usr[1]);
    //z=data.read_data(*dt_usr[2]);
    data.read_data(dt_usr);
    x=dt_usr[0];
    //y=dt_usr[1];
    //z=dt_usr[2];
    printf(" %f \n\r", x);
    //printf(" %f \n\r", y);
    //printf(" %f \n\r", z);
    //wait(1.0);
    }
}

Thank you very much!

Question relating to:

2 Answers

10 years, 10 months ago.

You probably need to use the initialize method of the LIS3DH class.

10 years, 10 months ago.

Hi Hnp,
Thank you for your interest the lib.
I have tried your program on my Nucleo F411 mbed board with following modification.
It works (You don't need any additional initialize method).

modification

//I2C i2c(p28,p27);
I2C i2c(D14,D15);  // Pin names for F411 mbed
//LIS3DH data(i2c, 0x19);
LIS3DH data(i2c, 0x18 << 1); // SDO/SA0 = GND (my HW connection)

This means you need to set address "0x19 << 1".
My LIS3H SDO/SA0 pin connected to GND but I think you connected to VCC.
Please shift one bit or just use "LIS3DH_V_CHIP_ADDR".
Make sure your address pin, SDO/SA0 condition.
Kenji