Accelerometer sensor LIS2DW12 output error

Hi everyone,
I use LIS2DW12 with I2C interface. I can scan the address was 0x18. But the output always consistency when I move the sensor, see the code as below.

#include <LIS2DW12.h>
#include "Wire.h"
#include "SPI.h"

//Create one instances of the driver class
LIS2DW12 Sensor( I2C_MODE, 0x18, SPISettings(0, MSBFIRST, SPI_MODE0) );

void setup() {
  // put your setup code here, to run once:
  // put your main code here, to run repeatedly:
  Serial.begin(9600);
  delay(1000); //relax...
  Serial.println("Processor came out of reset.\n");
  
  //Call .begin() to configure the IMUs
  if( Sensor.begin() != 0 )
  {
    Serial.println("Problem starting the sensor at 0x18.");
  }
  else
  {
    Serial.println("Sensor at 0x18 started.");
  }
}

void loop() {
  Serial.print(" X1 = ");
  Serial.println(Sensor.readFloatAccelX(), 2);
  Serial.print(" Y1 = ");
  Serial.println(Sensor.readFloatAccelY(), 2);
  Serial.print(" Z1 = ");
  Serial.println(Sensor.readFloatAccelZ(), 2);
  delay(2000);
}

Result:

-> Processor came out of reset.

-> Sensor at 0x18 started.

-> X1 = -1061.58

-> Y1 = -1061.58

-> Z1 = -1061.58

-> X1 = -1061.58

-> Y1 = -1061.58

-> Z1 = -1061.58

If you have any comment, please let me know.

Thanks
kevin

Have you considered that the library you are using may be the wrong one?

I ask because I see lots of reference to the library listed that OP is using but those libraries are for the STM32.

OP did you try the SPARKFUN library?

Hi Idahowalker,

Thanks for advice.

I try SPARKFUN library, but stuck on "if (accel.begin() == false)".
It can't detect the device, but I can get 0x18 addr from I2C scanner.

Thanks
kevin

Manufacturer's page of the LIS2DW12: https://www.st.com/en/mems-and-sensors/lis2dw12.html with datasheet.
If the SA0 pin is not connected (or connected to 3.3V), then it is internally pulled up and the I2C address is 0x19.
If the SA0 pin is connected to GND, then the I2C address is 0x18.

It is possible that a I2C Scanner can detect a I2C device, and when data is transferred then things go wrong. However, it is not likely. Can you try again with the Sparkfun library ?

The Sparkfun library calls isConnected() from the accel.begin().
That function checks the I2C address for 0x19 and reads the WHO_AM_I register.

Select your 0x18 with: accel.begin(0x18)

if (accel.begin(0x18) == false)
  ...

Use that for example with Example3_ReadRaw.ino.

Hi Koepel,

Thanks for comment.

The SA0 is connected to GND in my board.
I add 0x18 with accel.begin, but still stuck on false condition.

You might have found a bug.

The WHO_AM_I is 0x44 according to the datasheet and according to others.
The Sparkfun library checks if the WHO_AM_I is 0x33.

Here is the definition of the 0x33: SparkFun_LIS2DH12_Arduino_Library/lis2dh12_reg.h at master · sparkfun/SparkFun_LIS2DH12_Arduino_Library · GitHub.

And here is the check for it: SparkFun_LIS2DH12_Arduino_Library/SparkFun_LIS2DH12.cpp at master · sparkfun/SparkFun_LIS2DH12_Arduino_Library · GitHub.

I don't understand what is going on. The library did work at some moment.
Does Sparkfun buy a sensor with a different value, or am I looking at the wrong datasheet. I don't know :confused:

Could you read register 0x0F and check if you have 0x33 or 0x44 ?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.