NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Project Help and Ideas » Accelerometer - ADXL345 ... Please help
March 26, 2012 by ashag |
Hi, I am trying to make a device to detect falls and I am using the ADXL345 accelerometer for this. The datasheet for the accelerometer is - http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf Here's the problem that I'm having - When I initialize the accelerometer using the following line
the values it displays on the terminal are 0,0,1 in the X,Y,Z axis when lying on a table but when I shake the accelerometer, the values don't change. When I initialize the accelerometer using -
the values it displays in the X,Y and Z axes when lying flat are 0,0,9. The values however change when I shake the device. The only difference between the two lines I have posted is that the justify bit is turned on in the 2nd line. The description of Justify bit in the datasheet is -
A setting of 1 in the justify bit selects left-justified (MSB) mode, and a setting of 0 selects right-justified mode with sign extension. I do not understand what it means though. The code to initialize the accelerometer is -
The code to read the X,Y and Z-axes
The code to calculate the average value of G in each direction. The formula I'm currently using to calculate g is - (Raw data) * (G-range) / (2^13). I'm using +/- 16g so I believe the G range should be 32.
I will really appreciate if someone is able to help me out. Thanks Ashish |
---|---|
March 26, 2012 by pcbolt |
Hi Ashish - I would try to print out the raw values (both high and low bytes separately) you get when you execute "Accel_ReadZ()". Then go back and try setting/clearing the justify bit to see how your results change. Maybe the conversion to a 10-bit number needs tweaking depending on how the device outputs its values. |
March 27, 2012 by pcbolt |
Ashish - I'm not sure this line is right:
Since you declared Z as a short (int16_t), it shouldn't need to be converted, since it is already twos-complemented. If it does need to be converted, for 16-bit numbers the range is 0 to 65,536 (unsigned) and -32,768 to +32,767 (signed) so I don't think 4095 and 8192 will work. |
Please log in to post a reply.
Did you know that any circuit of voltage sources and resistors can be simplified to a "Thevenin" equivalent circuit? Learn more...
|