Go Down

Topic: Sparkfun ADXL337 (Read 83 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?

Go Up