Help us with our project

Hi,

my classmates and I are trying to program the H3lis331DL accelrometer using the arduino mini pro board. We are having issues compiling data, the measurement of acceleration does not vary even when the accelerometer is in motion. We are trying to figure out why our accelerometer is not reacting to the movement.

This is our code that we found at https://www.hackster.io/Dcube/measureme … ino-899dd8

#include <wire.h>

// H3LIS331DL I2C address is 0x18(24)

#define Addr 0x18

void setup()

{

// Initialise I2C communication as MASTER

Wire.begin();

// Initialise Serial Communication, set baud rate = 9600

Serial.begin(9600);

// Start I2C Transmission

Wire.beginTransmission(Addr);

// Select control register 1

Wire.write(0x20);

// Enable X, Y, Z axis, power on mode, data output rate 50Hz

Wire.write(0x27);

// Stop I2C Transmission

Wire.endTransmission();

// Start I2C Transmission

Wire.beginTransmission(Addr);

// Select control register 4

Wire.write(0x23);

// Set full scale, +/- 100g, continuous update

Wire.write(0x00);

// Stop I2C Transmission

Wire.endTransmission();

delay(300);

}

void loop()

{

unsigned int data[6];

for(int i = 0; i < 6; i++)

{

// Start I2C Transmission

Wire.beginTransmission(Addr);

// Select data register

Wire.write((40+i));

// Stop I2C Transmission

Wire.endTransmission();

// Request 1 byte of data

Wire.requestFrom(Addr, 1);

// Read 6 bytes of data

// xAccl lsb, xAccl msb, yAccl lsb, yAccl msb, zAccl lsb, zAccl msb

if(Wire.available() == 1)

{

data = Wire.read();
}
}
delay(300);
// Convert the data
int xAccl = ((data[1] * 256) + data[0]);
int yAccl = ((data[3] * 256) + data[2]);
int zAccl = ((data[5] * 256) + data[4]);
// Output data to serial monitor
Serial.print("Acceleration in X-Axis : ");
Serial.println(xAccl);
Serial.print("Acceleration in Y-Axis : ");
Serial.println(yAccl);
Serial.print("Acceleration in Z-Axis : ");
Serial.println(zAccl);
delay(300);
}
We change the rate to 1000Hz.
Any suggestions on how to fix this issue?

Unfortunately, we cannot help you troubleshoot the code in that tutorial as it is not using a SparkFun board or our [Arduino library for the H3LIS331DL. If you are using the SparkFun breakout of this sensor, we recommend following our [Hookup Guide for this board. That will go over the hardware as well as an example circuit using the library.

A quick troubleshooting suggestion for your project would be to make sure the I2C bus on your Arduino is seeing the sensor by either adding some debug statements in your code or running an I2C scan to check if the H3LIS331DL is being seen on the bus at the address you are setting in your example.

If you are using the SparkFun board, try using our library and if you still have issues getting data, please take a few photos of your board and attach them to your reply.](https://learn.sparkfun.com/tutorials/h3lis331dl-accelerometer-breakout-hookup-guide)](GitHub - sparkfun/SparkFun_LIS331_Arduino_Library: Arduino library for LIS331 family accelerometers.)