0

Question about LIS3DH
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Question about LIS3DH

by sk8rjess on Mon Apr 12, 2021 8:19 am

I'm using one of these in a vehicle inclinometer project that just needs to read X and Y angles and rotates an image based on a calculated angle from the sensor.
This is my first big solo arduino project and I know my code isn't up to par or standards but I'm upgrading and fixing as I learn.

I've been struggling to get accurate readings that weren't so jumpy and thought it just needed to be calibrated. I know there's always going to be data coming out of it, but I can have the sensor perfectly level and still with it still reading tons of varied values from the sensor. I understand it's the gravity, but I don't understand how to properly tackle that.
Googling seems to show that there's not really a calibration reset on these so now I'm at another crossroad thinking this isn't the best sensor for this project and I'm not really sure where to go for advice.
Is this sensor capable of that? Or would I be better going with something like an ADXL345?

Here's my code. Be easy on me lol
[removed by request]
Last edited by adafruit_support_bill on Mon Apr 12, 2021 11:58 am, edited 1 time in total.
Reason: code removed at request of OP

sk8rjess
 
Posts: 19
Joined: Thu Aug 11, 2016 2:57 pm

Re: Question about LIS3DH

by adafruit_support_bill on Mon Apr 12, 2021 9:13 am

What does the output look like with the example code from the library? Please post some examples of the raw output readings you are getting.

With the sensor level and perfectly stationary, you should get something close to a 1G reading in the Z axis and the X and Y should be close to zero. Some offset error is normal for MEMs sensors like these. But that can be handled in calibration. Also, keep in mind that vibrations are accelerations too, and what may look like random noise may be vibrations from nearby equipment, passing trucks or people walking across the floor.

adafruit_support_bill
 
Posts: 81594
Joined: Sat Feb 07, 2009 10:11 am

Re: Question about LIS3DH

by sk8rjess on Mon Apr 12, 2021 9:35 am

Sure, here's the output.

Code: Select all | TOGGLE FULL SIZE
LIS3DH test!
LIS3DH found!
Range = 2G
Data rate set to: 400 Hz
X:  15872     Y:  -992     Z:  144      X: 9.52    Y: -0.57    Z: 0.13 m/s^2

X:  16000     Y:  -944     Z:  432      X: 9.60    Y: -0.53    Z: 0.24 m/s^2

X:  15968     Y:  -928     Z:  272      X: 9.60    Y: -0.57    Z: 0.15 m/s^2

X:  15936     Y:  -912     Z:  560      X: 9.58    Y: -0.56    Z: 0.22 m/s^2

X:  16000     Y:  -880     Z:  448      X: 9.51    Y: -0.58    Z: 0.08 m/s^2

X:  15952     Y:  -880     Z:  448      X: 9.55    Y: -0.54    Z: 0.38 m/s^2

X:  16000     Y:  -976     Z:  416      X: 9.57    Y: -0.57    Z: 0.15 m/s^2

X:  15952     Y:  -1040     Z:  448      X: 9.57    Y: -0.47    Z: 0.26 m/s^2

X:  15952     Y:  -864     Z:  432      X: 9.59    Y: -0.51    Z: 0.32 m/s^2

X:  15920     Y:  -928     Z:  304      X: 9.59    Y: -0.50    Z: 0.29 m/s^2

X:  15936     Y:  -960     Z:  384      X: 9.53    Y: -0.53    Z: 0.27 m/s^2

X:  15936     Y:  -880     Z:  496      X: 9.46    Y: -0.52    Z: 0.28 m/s^2

sk8rjess
 
Posts: 19
Joined: Thu Aug 11, 2016 2:57 pm

Re: Question about LIS3DH

by adafruit_support_bill on Mon Apr 12, 2021 10:01 am

Looks like you have the sensor mounted with the X axis more-or-less vertical, so you are seeing almost 1G (9.8 m/s²) on that axis.

You are also seeing some on the Y and Z axis. I suspect part of that may be because the X axis is not perfectly vertical, so there is some gravitational acceleration detected on Y and Z. An, as mentioned above, some offset error is typical in this type of device.

How do you have the sensor mounted? Some photos of your setup would be helpful.

adafruit_support_bill
 
Posts: 81594
Joined: Sat Feb 07, 2009 10:11 am

Re: Question about LIS3DH

by sk8rjess on Mon Apr 12, 2021 11:42 am

At the time of testing that, yes it was mounted on its side. Currently in testing I have the sensor either loose or in alligator clips.
I didn't realize you were looking for level readings specifically, sorry! I'll set it back up properly later today.

sk8rjess
 
Posts: 19
Joined: Thu Aug 11, 2016 2:57 pm

Re: Question about LIS3DH

by adafruit_support_bill on Mon Apr 12, 2021 11:56 am

It doesn't necessarily need to be mounted flat, it is simple enough to re-map your axis in code if needed. I was just trying to get an idea of what your raw readings look like and how much variability you are seeing.
Currently in testing I have the sensor either loose or in alligator clips.

That would be consistent with the less than perfect alignment and 'noisy' readings.

adafruit_support_bill
 
Posts: 81594
Joined: Sat Feb 07, 2009 10:11 am

Re: Question about LIS3DH

by sk8rjess on Tue Apr 13, 2021 5:20 pm

It appears it was either a jumper, or the sensor itself. I did try numerous jumpers, but a set from a different brand and another LIS3DH and it wasn't as sporadic as previously. I wish I would have thought to try that before spending so much time trying to debug that previously working on this project haha.
Can you point me in the direction of learning more about remapping the axis on this? I don't see it covered anywhere

sk8rjess
 
Posts: 19
Joined: Thu Aug 11, 2016 2:57 pm

Re: Question about LIS3DH

by adafruit_support_bill on Tue Apr 13, 2021 6:10 pm

Remapping is pretty straightforward. The usual convention is for X to be the axis aligned with the direction of travel. Y is the right/left axis and Z is the vertical axis. But, sometimes it is more convenient to mount the sensor a different way, so you simply re-assign the axis values in your code.

Something like:

Code: Select all | TOGGLE FULL SIZE
  lis.read();      // get X Y and Z data at once
  // re-map as needed
  // depending on actual orientation of sensor
  X = lis.z;  // Forward/back axis
  Y = lis.y;  // Left/right axis
  Z = lis.X;  // vertical axis

adafruit_support_bill
 
Posts: 81594
Joined: Sat Feb 07, 2009 10:11 am

Re: Question about LIS3DH

by sk8rjess on Wed Apr 14, 2021 2:17 pm

I feel a little embarrassed that's all it was. I was thinking it was a function inside a library or something, not just renaming the variables, lol.

It seems my issues were jumpers or the sensor itself. I replaced the jumpers previously but a totally different brand seemed to be fine. This project has started and stopped so many times over the years and I was always just making work around thinking it was just my lack of knowledge on how this works.

sk8rjess
 
Posts: 19
Joined: Thu Aug 11, 2016 2:57 pm

Please be positive and constructive with your questions and comments.