Issue with ADXL377 accelerometer analog readings, with Adruino UNO

Hi everyone,
My very first Adruino project ever, am trying to setup an ADXL377 accelerometer and read in G force readings from the 3 axis.
I am using code found online, and am not receiving any errors upon compiling:

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;  
}

I am connected at 5V, per a diagram I also found online(see attached), pretty basic really, +5V, GND and A0, A1 and A2 for the 3 axis.
Readings are as follows, few examples:
X: 511
Y: 512
Z: 512

X: 102.81 g
Y: 103.41 g
Z: 103.41 g

X: 513
Y: 513
Z: 513

X: 104.00 g
Y: 104.00 g
Z: 104.00 g

I'm a bit concerned with the 100g reading at rest?
Has anyone ever seen this type of problem before? Should I get near 0 readings on at least 2 axis?
Also, moving the board around while looking at the serial monitor doesn't seem to have any effect on readings, should it? I tried sampling at 20ms, still no apparent change to readings.
All comments welcome.
Thanks in advance
AC

512 is certainly not the right zero reading for half a 3.3v analog input. It is the right zero reading for half of a 5v analog input. Unless... AREF is tied to 3.3v. If you did that you could choose the 3.3v micro option instead of the 5v option. If you did not do that then send a picture of your wiring and maybe something will be obvious. Do those raw readings actually change with g-force?

Hi wzaggle,
First, thank you so much for your reply. I have it connected as 5V, and I did not connect the AREF yet, as I am not quite sure on what pin it needed to go on the accelerometer. I only have Vs, GND, X, Y, Z and ST on the chip's board, unless it is meant to be split with Vs?
And to answer your question, the values don't seem to change with movement of the accelerometer board, which I find odd...
I'll upload a pic of the 2 boards, although probably not clear, so don't hesitate to ask any question whatsoever.
Thanks
AC

I have it connected as 5V

The ADXL377 is a 3.3V device, and will eventually be destroyed if connected to 5V, unless your module has a voltage regulator.

Post a link to the module you have.

Hi jremington,
Thanks for your post. I had read that the ADXL377 could support 5V, but I just tested again, switching to 3.3V input, adjusted the source code accordingly, and I'm seeing the same issue or concern. At 3.3V I get a consistent 334-335 out of all 3 analog outputs, and none seem to be affected by any movement of the chip at all.
That mapf function gives out a -69g, so obviously that will need some adjustments too, but for now my concern is really the consistency in analog readings.
Any thoughts? Could the chip be defective?
Thanks
AC

I had read that the ADXL377 could support 5V

Do you believe everything you read?

According to the datasheet, a reliable reference, the absolute maximum voltage for the ADXL377 is 3.6V. After exposing the chip to 5V, you can't trust it.

In order to test the chip and verify correct operation, you need to expose it to a known acceleration well within the measurement range (for example +/- 100 g). That is rather difficult for most experimenters.

Jremington, would the chip laying flat upside up, and then upside down not show a difference +/- on one axis?

Possibly, but maybe not. In any case, your sensor is probably damaged.

Check the noise statistics in the data sheet. +/- 1 g is only 0.5% of the full scale reading, 200 g.

What do you really want to measure?

Jremington, after some more reading, I think you're right and I made my first mistake on my first project. Lol I think the chip is probably still returning the equivalent to 0g values, at rest, but has no reflex for reporting movement due to the 5V I assume. I'll order another one and see what it says.
To answer your last question, the goal will eventually be to measure the force of an impact, say 2 objects colliding at speed.

Thanks for the replies, and here is where I assumed it was 5V capable, from what I thought was a reliable source:

The sensor is soldered onto a PCB with four mounting holes (in case you don't remember, this is accelerating at up to 200g's!) and a 3.3V regulator so you can use it with 5v logic such as an Arduino. Taken from: ADXL377 - High-G Triple-Axis Accelerometer (+-200g Analog Out) : ID 1413 : $24.95 : Adafruit Industries, Unique & fun DIY electronics and kits

I don't understand your post.

Do you have the Adafruit breakout board with the voltage regulator? That would be safe to use with 5V, as I suggested in reply #3.

If you do not have the Adafruit board, post a link to a web page or data sheet for the exact product that you do have.

I'm sorry for the confusion, my mistake was to look at the adafruit data while having purchsed this board: http://www.analog.com/en/design-center/evaluation-hardware-and-software/evaluation-boards-kits/eval-adxl377.html#eb-overview

That module is for 3.0 to 3.3V only.

Figure 1 of the user guide on the linked web page shows the board powered by 3V.

Hi jremington,
As an update, I tested with a new sensor and can now see variable readings with movement of the board. It confirms the voltage issue you suspected.
As far as raw data readings, at rest, all 3 axis send 334 or 335 consistently, which should in theory be the 0 gravity reading, or perhaps 1 g rather? Now the code I kisted above doesn't seem to convert the raw data reading to g force like it should, or the results of the mapf function call are off. The equivalent to a normal 334 for example returns -69 g's. If I reverse the logic for the if condition per 5V, I get a conversion of -1 to -0.75 or something.
Per the sensor specs, the output voltage per axis at rest should be 1.5v, so I understand. Would you know the correlation between the 1.5v and a raw reading of 334 from the program? I'm trying to figure out how to convert the raw output to g force is what I need.
Any help or guidance would be greatly appreciated.
Thanks
AC

The sensor is ratiometric, which means it should return Vcc/2 for zero g. What is the value of the sensor Vcc that you are using?

In any case, you need to calibrate the sensor, and that is to measure the output of each individual axis at zero g. If the Z axis is up or down, X and Y are at zero g. Use those values in your code.

I would not use the map() function. Instead, scale the values using a simple equation similar to the following, where you first subtract the zero g value, convert to volts, and divide by the sensitivity factor from the sensor data sheet.

float accx = (rawX - zero_g_X)*5.0/1024./0.0065;  //sensitivity factor from data sheet = 6.5 mV/g

For better accuracy, substitute the "5.0" with the measured value of Vcc on your Arduino.

Hello jremington,
I truly appreciate your feedback, it's not easy being a newbie!
Just so I am sure I understand correctly, you are saying that I should measure the output of each axis and use those values in your proposed equation. I should measure each axis for voltage output, against GND, is that what you mean?
Thanks
AC

Voltages are always referred to GND, as GND defines 0 V.