stm32duino/LIS2DW12

No Example, doesn't compile

Closed this issue · 5 comments

Tried this library. there is no working example in the Repo, and the TwoWire(sda,sca); constructor is unsupported in current version of Wire.h

Any ideas on how to use this sensor would be cool.

Hello @bgatti ,
you can give a look at this example. You just need to extract the part relative to LIS2DW12. Pay only attention to the I2C address that you need to use according to the connection of the SA0 pin in your hardware design (LIS2DW12_I2C_ADD_H if SA0 pin is connected to Vdd or LIS2DW12_I2C_ADD_L if SA0 pin is connected to GND).
Let me know if it works on your side.
Best Regards,
Carlo

You can find below the sketch that you can try:

// Includes
#include <LIS2DW12Sensor.h>

#ifdef ARDUINO_SAM_DUE
#define DEV_I2C Wire1
#elif defined(ARDUINO_ARCH_STM32)
#define DEV_I2C Wire
#elif defined(ARDUINO_ARCH_AVR)
#define DEV_I2C Wire
#else
#define DEV_I2C Wire
#endif
#define SerialPort Serial

// Components
LIS2DW12Sensor Acc2(&DEV_I2C, LIS2DW12_I2C_ADD_H);

void setup() {
  // Initialize serial for output.
  SerialPort.begin(115200);
  
  // Initialize I2C bus.
  DEV_I2C.begin();
  
  Acc2.begin();
  Acc2.Enable_X();
}

void loop() {
  //Read accelerometer
  int32_t accelerometer2[3];
  Acc2.Get_X_Axes(accelerometer2);

  // Output data.
  SerialPort.print(" | Acc2[mg]: ");
  SerialPort.print(accelerometer2[0]);
  SerialPort.print(" ");
  SerialPort.print(accelerometer2[1]);
  SerialPort.print(" ");
  SerialPort.print(accelerometer2[2]);
  SerialPort.println(" |");
}

Please, pay attention only if replacing LIS2DW12_I2C_ADD_H with LIS2DW12_I2C_ADD_L according to your hardware setup.
Best Regards,
Carlo

Hello @bgatti ,
any update? Can I close this ticket?
Best Regards,
Carlo

We can close it, I was able to get it working.

Thanks a lot for the feedback.
Best regards,
Carlo