Go Down

Topic: Sparkfun ADXL337 (Read 346 times) previous topic - next topic

vexxejr

Jan 12, 2019, 09:49 pm Last Edit: Jan 12, 2019, 10:07 pm by vexxejr
Hi,

I am trying to setup a sparkfun adxl337, I am using the following code but I do not understand the readings I am getting. If i twist the accelerometer so Z is pointing roughly down i get readings X:391 Y: 390 Z:342. If i then make it so Z is pointing roughly upwards i get readings X:440 Y: 441 Z: 511.

I don't understand why all 3 values are changing, surely it should only be the Z axis?

I am also finding that when holding the accelerometer against a surface (still) it sometimes jumps around with values, sometimes it'll settle on EG. 390, then if i do the same experiment again it'll settle on EG. 440. Despite being held in the same position.

I am also finding that when moving the accelerometer as much as i can (flicking it, shaking etc), i am only able to produce values between about 300 and 710 on any of the axes.

I have it connected to 3.3V on my Arduino.

I have tried connecting the AREF pin and using the code 'analogReference(EXTERNAL);' but this just seemed to replicate the problem just with different values.

Thanks very much

Code: [Select]
// Pin Definitions
#define ADXL335_PIN_XOUT  A3
#define ADXL335_PIN_YOUT  A5
#define ADXL335_PIN_ZOUT  A1

void setup() {

  Serial.begin(9800);
}

void loop(){

  //analogReference(EXTERNAL);

  int rawX = analogRead(ADXL335_PIN_XOUT);
  int rawY = analogRead(ADXL335_PIN_YOUT);
  int rawZ = analogRead(ADXL335_PIN_ZOUT);

  Serial.print("X Raw: "); Serial.print(rawX);
  Serial.print("  Y Raw: "); Serial.print(rawY);
  Serial.print("  Z Raw: "); Serial.println(rawZ);

  delay(100);
}

MorganS

Did you connect the ground?
"The problem is in the code you didn't post."

Idahowalker

Well. For starters the earth rotates, which is an acceleration.

Moving the accelerometer off of the 0,0 X/Y axis will produce accelerations. Placing the X or Y into the plane of the earths rotations will produce accelerations.

vexxejr

#3
Jan 14, 2019, 11:26 am Last Edit: Jan 14, 2019, 11:57 am by vexxejr
Yes, the ground is connected.

Adahowalker - What i expected to happen was that when holding the sensor parallel with the ground, it would read X: 511 Y: 511: Z: 341, since i believe the sensor should return values between 0 and 1023 where 0 is -3G and 1023 is +3G.

This would mean 0G in X and Y, and 1G in the Z direction due to gravity. Is this not the case?

vexxejr


jremington

#5
Jan 16, 2019, 09:54 pm Last Edit: Jan 17, 2019, 12:18 am by jremington
Quote
What i expected to happen was that when holding the sensor parallel with the ground, it would read X: 511 Y: 511: Z: 341, since i believe the sensor should return values between 0 and 1023 where 0 is -3G and 1023 is +3G.
Sorry, no, it is not that simple. This is an analog device and the sensor returns voltage values.

You forgot to mention what Arduino are you using, and how it is being powered.

The ADXL337 is a 3.3V device. If you are powering it from 3.3V, then for zero g on any axis, the output voltage should be about 3.3/2 = 1.65 V.  The default sensitivity (see the data sheet) is about 300 mV for 1 g. So, you should expect to see outputs ranging from 1.95V to 1.35V for +/- 1g acceleration on any axis. Any axis that is not perfectly horizontal will measure a component of g.

Now, if you measure the output voltage using a 5V Arduino, with 5V as the ADC reference, then you would expect 1024*1.65V/5.0V = 337 for zero g on any axis.

If you are powering the Arduino from USB, then Vcc = AREF is probably 4.5V, and you would expect 1024*1.65V/4.5V = 375 for zero g on any axis.

It would be more sensible to use 3.3V as AREF, google for more info.

Finally, for accurate measurements, you must calibrate the device. Overview on calibration here.

vexxejr

Hi,

Thanks for your response, I am powering the arduino through the USB cable to my PC and using the 3.3V to power the ADXL337. Your explanation certainly helps me understand the values i should be expecting to see, thanks.

I have just plugged the arduino on to have a play around and see what I can get from it, and immediately it starts doing what I have previously noticed. The sensor is in a relatively fixed position, I tapped it a few times to generate movement and this is what the graph of the readings show.

I am confused as to why after tapping it, the sensor will read almost exactly the same values as before tapping it, but with about 60 added on to all the readings? Surely after tapping it, it should go back to roughly the original values since it is held in a fixed position?


Idahowalker

#7
Jan 20, 2019, 02:15 pm Last Edit: Jan 20, 2019, 02:26 pm by Idahowalker
Yes, the ground is connected.

Adahowalker - What i expected to happen was that when holding the sensor parallel with the ground, it would read X: 511 Y: 511: Z: 341, since i believe the sensor should return values between 0 and 1023 where 0 is -3G and 1023 is +3G.

This would mean 0G in X and Y, and 1G in the Z direction due to gravity. Is this not the case?
OK. If an accelerometer was held parallel to the ground, held being the key word, on a geodesic planet, the amount of acceleration felt would be equal to the offset, of a perfect accelerometer, of the holding platform to the center of the geodesic.


On the real earth, which is not a perfect geodesic, with an accelerometer held on a platform, the materials between the center of the earth and the accelerometer would cause gravity felt to be skewed at the held platform resulting in some acceleration felt at the held platform.


If the platform was allowed to float in the x and y axis, the platform would settle to the local gravity being felt on the surface of the earth and near 0 acceleration could be felt, discounting the noise produced within the accelerometer module.

Better yet, if the platform was torqued in oppisition to the accelerations being felt an even closer to zero acceleration could be felt, discounting the noise of the accelerometer module.

Also, the acceleromter would feel, discounting the noise of the acceleromter module, the acceleration of the spinning earth when the platform is on a non geodesic earth. Such as where you live is not on the perfect deodesic. Your location may stick further out into space or closer to the earths center which will give, on a spinning earth false accelerations.

Also, the position of the moon, discounting the noise from the acceleration module, will add to or subtract from the accelerations that will be felt, especially on a held platform, by the accelerometers.

There are other factors, discounting the noise from the acceleration module, that will cause the module to feel accelerations. Consider that a rod placed on the surface of the earth that simulates the length of the diameter of the earth will oscillate at a rate based upon the earths rotation frequency.

There are also factors, discounting the noise from the acceleration module, that will cause false accelerations to be felt, when the held or free floating platform is moved.

I found that the DLPF in the MPU9250 works fairly well to offset some of the noise acceleration felt. I then use a complementary filter + low pass filter to further dampen the noise levels. The complementary filter integrates time current acceleration from the accelerometers, past gyro rate and current gyro rate to produce a smoothed X/Y readings. I use those readings to convert the accelerations felt into counter torque readings to send servos to hold the platform level that the MPU9250 and other sensors are mounted on.

jremington

#8
Jan 20, 2019, 05:21 pm Last Edit: Jan 20, 2019, 06:58 pm by jremington
Quote
Also, the position of the moon, discounting the noise from the acceleration module, will add to or subtract from the accelerations that will be felt, especially on a held platform, by the accelerometers.
Surely you jest, to suggest that a consumer grade accelerometer would be so ridiculously sensitive and noise free as to detect that effect.

Quote
Surely after tapping it, it should go back to roughly the original values since it is held in a fixed position?
The first time you "tapped" the accelerometer, it did return to the original values. The second time, it did not.

So what else changed? Did you wiggle the wires? Are they soldered to the board(s)? Perhaps you have bad connections.

Hint: do a bunch of experiments before you draw hasty conclusions.


Go Up