Go Down

Topic: ADXL377 Output Problem (Read 85 times) previous topic - next topic

msc

Hey. I bought a ADXL377 Adafruit Accelometer. I connected it as below schematic and used program that i share below. But i took unchanged values on the serial port screen. I moved the sensor but nothing changed...My sensor is off?? Can u help please. I tried it another Arduino Uno but nothing changed.

Code: [Select]
/******************************************************************************
ADXL377_example.ino
Simple example for using the ADXL377 accelerometer breakout.
Jordan McConnell @ SparkFun Electronics
3 July 2014
https://github.com/sparkfun/ADXL377_Breakout
This example collects raw accelerometer data from the ADXL377 sensor using
analog reads and then converts it into common units (g's) and prints the
result to the Serial Monitor.
Developed/Tested with:
Arduino Uno
Arduino IDE 1.0.5
This code is beerware.
Distributed as-is; no warranty is given.
******************************************************************************/

// Make sure these two variables are correct for your setup
int scale = 200; // 3 (±3g) for ADXL337, 200 (±200g) for ADXL377
boolean micro_is_5V = true; // 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);
}

// Read, scale, and print accelerometer data
void loop()
{
  // Get raw accelerometer data for each axis
  int rawX = analogRead(A0);
  int rawY = analogRead(A1);
  int rawZ = analogRead(A2);
 
  // Scale accelerometer ADC readings into common units
  // Scale map depends on if using a 5V or 3.3V microcontroller
  float scaledX, scaledY, scaledZ; // Scaled values for each axis
  if (micro_is_5V) // Microcontroller runs off 5V
  {
    scaledX = mapf(rawX, 0, 675, -scale, scale); // 3.3/5 * 1023 =~ 675
    scaledY = mapf(rawY, 0, 675, -scale, scale);
    scaledZ = mapf(rawZ, 0, 675, -scale, scale);
  }
  else // Microcontroller runs off 3.3V
  {
    scaledX = mapf(rawX, 0, 1023, -scale, scale);
    scaledY = mapf(rawY, 0, 1023, -scale, scale);
    scaledZ = mapf(rawZ, 0, 1023, -scale, scale);
  }
 
  // Print out raw X,Y,Z accelerometer readings
  Serial.print("X: "); Serial.println(rawX);
  Serial.print("Y: "); Serial.println(rawY);
  Serial.print("Z: "); Serial.println(rawZ);
  Serial.println();
 
  // Print out scaled X,Y,Z accelerometer readings
  Serial.print("X: "); Serial.print(scaledX); Serial.println(" g");
  Serial.print("Y: "); Serial.print(scaledY); Serial.println(" g");
  Serial.print("Z: "); Serial.print(scaledZ); Serial.println(" g");
  Serial.println();
 
  delay(2000); // 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;
}

jremington

The sensor is intended to measure up to 200 g, about what you get in a high speed automobile collision.

It may not even be possible to generate 10 g's by hand.

msc

So can't i use it for tilt measurement? I designed robot arm and i only want to measure the angle of the arm by the ground. Robot is moving so slow. So what do i need for this purpose?

jremington

#3
Apr 13, 2018, 05:12 pm Last Edit: Apr 13, 2018, 05:13 pm by jremington
For tilt measurements, you need an accelerometer that measures +/-2 g to +/-3 g full scale.

msc

Thank you so much. I will try it soon.

Go Up