Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Accelerometer ambiguous results

Status
Not open for further replies.

bsnayak

Newbie level 4
Newbie level 4
Joined
Aug 31, 2015
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
48
Hello ,

I have recently bought some sensors ADXL337 and ADXL 377 from Sprakfun. I have connected both the sensors with Arduino Mega KIIT. I am using the sample code given in Github. Here is it .

Code:
// Declaration of all necessary header file
// Inspired with example file of Sparkfun ADXL337/377
#include "Wire.h" 
#include <SPI.h> 

// Declarations of Parameters 
int scale_ADXL337 = 3;  // 3 (±3g) for ADXL337, 200 (±200g) for ADXL377
int scale_ADXL377 = 200;// 3 (±3g) for ADXL337, 200 (±200g) for ADXL377
float rawX_ADXL337, rawY_ADXL337, rawZ_ADXL337;  // Raw values for each axis of Sensor ADXL337
float rawX_ADXL377, rawY_ADXL377, rawZ_ADXL377;  // Raw values for each axis of Sensor ADXL377
float scaledX_ADXL337, scaledY_ADXL337, scaledZ_ADXL337; // Scaled values for each axis of Sensor ADXL337
float scaledX_ADXL377, scaledY_ADXL377, scaledZ_ADXL377; // Scaled values for each axis of Sensor ADXL377

boolean micro_is_5V = false; // Set to true if using a 5V microcontroller such as the Arduino Uno, false if using a 3.3V microcontroller, this affects the interpretation of the sensor data

void setup()
{
  // Initialize serial communication at 115200 baud
  Serial.begin(115200);
  Serial.print("The Accelerometer ADXL377 and ADXL337 are connected to the MEGA BOARD");
  Serial.println();
}

// Read, scale_ADXL337, and print accelerometer data
void loop()
{
  // Get raw accelerometer data for each axis
  rawX_ADXL377 = analogRead(A0);
  rawY_ADXL377 = analogRead(A1);
  rawZ_ADXL377 = analogRead(A2);
  
  rawX_ADXL337 = analogRead(A3);
  rawY_ADXL337 = analogRead(A4);
  rawZ_ADXL337 = analogRead(A5);
  
  scaledX_ADXL377 = mapf(rawX_ADXL377, 0, 1023, -scale_ADXL377, scale_ADXL377);
  scaledY_ADXL377 = mapf(rawY_ADXL377, 0, 1023, -scale_ADXL377, scale_ADXL377);
  scaledZ_ADXL377 = mapf(rawZ_ADXL377, 0, 1023, -scale_ADXL377, scale_ADXL377);
 
  
  scaledX_ADXL337 = mapf(rawX_ADXL337, 0, 1023, -scale_ADXL337, scale_ADXL337);
  scaledY_ADXL337 = mapf(rawY_ADXL337, 0, 1023, -scale_ADXL337, scale_ADXL337);
  scaledZ_ADXL337 = mapf(rawZ_ADXL337, 0, 1023, -scale_ADXL337, scale_ADXL337);
 
  

  Serial.println();
  Serial.println("--------------------------------------------------------------------");
    
  // Print out raw X,Y,Z accelerometer readings of ADXL337
  Serial.print("X_377: "); Serial.println(rawX_ADXL337);
  Serial.print("Y_377: "); Serial.println(rawY_ADXL337);
  Serial.print("Z_377: "); Serial.println(rawZ_ADXL337);
  Serial.println();
  
  // Print out scaled X,Y,Z accelerometer readings of ADXL337
  Serial.print("Scaled_X_377: "); Serial.print(scaledX_ADXL337); Serial.println(" g");
  Serial.print("Scaled_Y_377: "); Serial.print(scaledY_ADXL337); Serial.println(" g");
  Serial.print("Scaled_Z_377: "); Serial.print(scaledZ_ADXL337); Serial.println(" g");
  Serial.println();
  
  
  // Print out raw X,Y,Z accelerometer readings of ADXL337
  Serial.print("X_337: "); Serial.println(rawX_ADXL337);
  Serial.print("Y_337: "); Serial.println(rawY_ADXL337);
  Serial.print("Z_337: "); Serial.println(rawZ_ADXL337);
  Serial.println();
  
  // Print out scaled X,Y,Z accelerometer readings of ADXL337
  Serial.print("Scaled_X_337: "); Serial.print(scaledX_ADXL337); Serial.println(" g");
  Serial.print("Scaled_Y_337: "); Serial.print(scaledY_ADXL337); Serial.println(" g");
  Serial.print("Scaled_Z_337: "); Serial.print(scaledZ_ADXL337); Serial.println(" g");
  Serial.println();
  
  Serial.println("--------------------------------------------------------------------\n");

 
  
  
  delay(250); // Minimum delay of 2 milliseconds between sensor reads (500 Hz)
  
}

// Same functionality as Arduino's standard map function, except using floats
float mapf(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

However the output of this code is as follows.

Code:
X_377: 362.00
Y_377: 339.00
Z_377: 419.00

Scaled_X_377: -0.88 g
Scaled_Y_377: -1.01 g
Scaled_Z_377: -0.54 g

X_337: 362.00
Y_337: 339.00
Z_337: 419.00

Scaled_X_337: -0.88 g
Scaled_Y_337: -1.01 g
Scaled_Z_337: -0.54 g

--------------------------------------------------------------------


--------------------------------------------------------------------
X_377: 361.00
Y_377: 339.00
Z_377: 419.00

Scaled_X_377: -0.88 g
Scaled_Y_377: -1.01 g
Scaled_Z_377: -0.54 g

X_337: 361.00
Y_337: 339.00
Z_337: 419.00

Scaled_X_337: -0.88 g
Scaled_Y_337: -1.01 g
Scaled_Z_337: -0.54 g

--------------------------------------------------------------------

Here is the result in X UP, X Down, Y UP, Y Down, Z UP, Z Down

Code:
X UP

X_377: 362.00
Y_377: 339.00
Z_377: 421.00

Scaled_X_377: -0.88 g
Scaled_Y_377: -1.01 g
Scaled_Z_377: -0.53 g

X_337: 362.00
Y_337: 339.00
Z_337: 421.00

Scaled_X_337: -0.88 g
Scaled_Y_337: -1.01 g
Scaled_Z_337: -0.53 g


X down

X_377: 364.00
Y_377: 342.00
Z_377: 420.00

Scaled_X_377: -0.87 g
Scaled_Y_377: -0.99 g
Scaled_Z_377: -0.54 g

X_337: 364.00
Y_337: 342.00
Z_337: 420.00

Scaled_X_337: -0.87 g
Scaled_Y_337: -0.99 g
Scaled_Z_337: -0.54 g



Y up 

X_377: 364.00
Y_377: 343.00
Z_377: 420.00

Scaled_X_377: -0.87 g
Scaled_Y_377: -0.99 g
Scaled_Z_377: -0.54 g

X_337: 364.00
Y_337: 343.00
Z_337: 420.00

Scaled_X_337: -0.87 g
Scaled_Y_337: -0.99 g
Scaled_Z_337: -0.54 g



Y down 

X_377: 361.00
Y_377: 339.00
Z_377: 421.00

Scaled_X_377: -0.88 g
Scaled_Y_377: -1.01 g
Scaled_Z_377: -0.53 g

X_337: 361.00
Y_337: 339.00
Z_337: 421.00

Scaled_X_337: -0.88 g
Scaled_Y_337: -1.01 g
Scaled_Z_337: -0.53 g



Z up 


X_377: 361.00
Y_377: 338.00
Z_377: 421.00

Scaled_X_377: -0.88 g
Scaled_Y_377: -1.02 g
Scaled_Z_377: -0.53 g

X_337: 361.00
Y_337: 338.00
Z_337: 421.00

Scaled_X_337: -0.88 g
Scaled_Y_337: -1.02 g
Scaled_Z_337: -0.53 g



Z down 


X_377: 339.00
Y_377: 342.00
Z_377: 282.00

Scaled_X_377: -1.01 g
Scaled_Y_377: -0.99 g
Scaled_Z_377: -1.35 g

X_337: 339.00
Y_337: 342.00
Z_337: 282.00

Scaled_X_337: -1.01 g
Scaled_Y_337: -0.99 g
Scaled_Z_337: -1.35 g




I am not sure, if it is correct (?????????). I would expect the Acceleration in the Z direction to be nearly 1g. However it is showing in the Y direction net accelration is nearly 1g. If the sensors are damaged or should i manupulate the analog pins in the X,Y,Z directions??
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top