# Does gyroscope requires calibration? (MPU 6050)

1. ## How to convert accelerometer data into G with the ADXL345 digital accelerometer

Am totally new to electronics and the datasheet is very confusing to me, so can anyone please guide me through the specification of the accelerometer? So that i can have a better understanding on the accelerometer and to be able to convert the accelerometer data into G.

X-axis Y-axis Z-axis -28 -26 218 These are the readings i get from the accelerometer with a +-2g range

HTML Code:
```import smbus
import time

# Get I2C bus
bus = smbus.SMBus(1)

# Select bandwidth rate register, 0x2C(44)
#       0x0A(10)    Normal mode, Output data rate = 100 Hz
bus.write_byte_data(0x53, 0x2C, 0x0A)
# Select power control register, 0x2D(45)
#       0x08(08)    Auto Sleep disable
bus.write_byte_data(0x53, 0x2D, 0x08)
# Select data format register, 0x31(49)
#       0x08(08)    Self test disabled, 4-wire interface
#                   Full resolution, Range = +/-2g
bus.write_byte_data(0x53, 0x31, 0x08)

time.sleep(0.5)

# Read data back from 0x32(50), 2 bytes
# X-Axis LSB, X-Axis MSB

# Convert the data to 10-bits
xAccl = ((data1 & 0x03) * 256) + data0
if xAccl > 511 :
xAccl -= 1024

# Read data back from 0x34(52), 2 bytes
# Y-Axis LSB, Y-Axis MSB

# Convert the data to 10-bits
yAccl = ((data1 & 0x03) * 256) + data0
if yAccl > 511 :
yAccl -= 1024

# Read data back from 0x36(54), 2 bytes
# Z-Axis LSB, Z-Axis MSB

# Convert the data to 10-bits
zAccl = ((data1 & 0x03) * 256) + data0
if zAccl > 511 :
zAccl -= 1024

# Output data to screen
print ("Acceleration in X-Axis : %d" %xAccl)
print ("Acceleration in Y-Axis : %d" %yAccl)
print ("Acceleration in Z-Axis : %d" %zAccl)```
These are the code. 2. ## Re: How to convert accelerometer data into G with the ADXL345 digital accelerometer

in the +/- 2g range , the resolution is 10bits.
The value per bit is 3.9mg.(3.90625mg exactly). 3. ## Re: How to convert accelerometer data into G with the ADXL345 digital accelerometer Originally Posted by srizbf in the +/- 2g range , the resolution is 10bits.
The value per bit is 3.9mg.(3.90625mg exactly).

Hi, srizbf,
According to the method you provide here, so i just simply use 218 * 0.0039g which = 0.8502g. But i thought when the accelerometer is stationary the z-axis should be 1g? Am i doing something wrong here? 4. ## Re: How to convert accelerometer data into G with the ADXL345 digital accelerometer

Nothing wrong.
it indicates that the accelerometer may be stationary but is not perfectly vertical. •

5. ## Re: How to convert accelerometer data into G with the ADXL345 digital accelerometer Originally Posted by srizbf Nothing wrong.
it indicates that the accelerometer may be stationary but is not perfectly vertical.
I did some research and some said to acquire 1g offset needs to be either subtract or add to the data is this the case when i need to find the offset too? 6. ## Re: How to convert accelerometer data into G with the ADXL345 digital accelerometer

so i just simply use 218 * 0.0039g which = 0.8502g
You cannot simply perform a scalar multiplication with only one axis, but vectorial along 3 axis, as below: Anyway, something seems to be wrong, whether in the conversion factor or in the need to calibrate the measured value. or even the need to subtract the base line value due to gravity acceleration. 7. ## Re: How to convert accelerometer data into G with the ADXL345 digital accelerometer

Hi,

Do some"calibration tests":
Put the sensor on the table and fix it with a tape.
(Maybe mark it's position and direction on the table with a pen)
* do the measurement an write down the values (best if you do a couple of measurements to get a clue about fluctuation and noise. You may also cancel out some noise by taking the average)
* the move the sensor upside down and fix it with identical direction on the table.
(Z should be negative now)
Now calculate:
Z_offset = (z_before + z_now)/2
Z_sensitivity = (z_before - z_now)/2
Z_multiplier = 1G / z_sensitivity

For all further Z calculations use: Z = (z_measured - z_offset) * z_multiplier

Do the same with the other two axis.

Klaus 8. ## Re: How to convert accelerometer data into G with the ADXL345 digital accelerometer Originally Posted by andre_teprom You cannot simply perform a scalar multiplication with only one axis, but vectorial along 3 axis, as below: Anyway, something seems to be wrong, whether in the conversion factor or in the need to calibrate the measured value. or even the need to subtract the base line value due to gravity acceleration.
Hi andre_teprom,
Thanks for providing the correct method on perfoming a scalar multiplication. 9. ## Re: How to convert accelerometer data into G with the ADXL345 digital accelerometer Originally Posted by KlausST Hi,

Do some"calibration tests":
Put the sensor on the table and fix it with a tape.
(Maybe mark it's position and direction on the table with a pen)
* do the measurement an write down the values (best if you do a couple of measurements to get a clue about fluctuation and noise. You may also cancel out some noise by taking the average)
* the move the sensor upside down and fix it with identical direction on the table.
(Z should be negative now)
Now calculate:
Z_offset = (z_before + z_now)/2
Z_sensitivity = (z_before - z_now)/2
Z_multiplier = 1G / z_sensitivity

For all further Z calculations use: Z = (z_measured - z_offset) * z_multiplier

Do the same with the other two axis.

Klaus
Hi KlausST,
Thanks for providing the "calibration test" method. Unfortunately, i do not have access to the accelerometer at this moment, but as soon as i get access back on the accelerometer i'll definitely try out this method you suggested. •

10. ## Re: How to convert accelerometer data into G with the ADXL345 digital accelerometer Originally Posted by KlausST Hi,

Do some"calibration tests":
Put the sensor on the table and fix it with a tape.
(Maybe mark it's position and direction on the table with a pen)
* do the measurement an write down the values (best if you do a couple of measurements to get a clue about fluctuation and noise. You may also cancel out some noise by taking the average)
* the move the sensor upside down and fix it with identical direction on the table.
(Z should be negative now)
Now calculate:
Z_offset = (z_before + z_now)/2
Z_sensitivity = (z_before - z_now)/2
Z_multiplier = 1G / z_sensitivity

For all further Z calculations use: Z = (z_measured - z_offset) * z_multiplier

Do the same with the other two axis.

Klaus
Hi Klaus,

I now have gain access back to the accelerometer and i have took 10 measurement readings from it while it's laying flat on the table. It seems that the z - axis readings are all from 216,217 and 220 so which 1 do i use to determine the offset value? Also what's the z_before and z_now? Can you clarify that for me? •

11. ## Re: How to convert accelerometer data into G with the ADXL345 digital accelerometer

Hi,

z_before = the previously written down values.
z_now = value of the actual measurement.

If the sensor is corretly oriented, then z should be positive in normal position and negative in upside down position.

--> please show us all your measurement values with the information of sensor direction.

Klaus 12. ## Re: How to convert accelerometer data into G with the ADXL345 digital accelerometer Originally Posted by KlausST Hi,

z_before = the previously written down values.
z_now = value of the actual measurement.

If the sensor is corretly oriented, then z should be positive in normal position and negative in upside down position.

--> please show us all your measurement values with the information of sensor direction.

Klaus
HTML Code:
```Acceleration in X-Axis : -6
Acceleration in Y-Axis : 5
Acceleration in Z-Axis : 222
Acceleration in X-Axis : -6
Acceleration in Y-Axis : 5
Acceleration in Z-Axis : 222
Acceleration in X-Axis : -9
Acceleration in Y-Axis : 3
Acceleration in Z-Axis : 219
Acceleration in X-Axis : -9
Acceleration in Y-Axis : 3
Acceleration in Z-Axis : 219
Acceleration in X-Axis : -10
Acceleration in Y-Axis : 4
Acceleration in Z-Axis : 221
Acceleration in X-Axis : -10
Acceleration in Y-Axis : 4
Acceleration in Z-Axis : 218
Acceleration in X-Axis : -10
Acceleration in Y-Axis : 4
Acceleration in Z-Axis : 220
Acceleration in X-Axis : -8
Acceleration in Y-Axis : 6
Acceleration in Z-Axis : 220
Acceleration in X-Axis : -8
Acceleration in Y-Axis : 3
Acceleration in Z-Axis : 217
Acceleration in X-Axis : -6
Acceleration in Y-Axis : 6
Acceleration in Z-Axis : 221```
HTML Code:
```Acceleration in X-Axis : -6
Acceleration in Y-Axis : 5
Acceleration in Z-Axis : 222
Acceleration in X-Axis : -6
Acceleration in Y-Axis : 5
Acceleration in Z-Axis : 222
Acceleration in X-Axis : -9
Acceleration in Y-Axis : 3
Acceleration in Z-Axis : 219
Acceleration in X-Axis : -9
Acceleration in Y-Axis : 3
Acceleration in Z-Axis : 219
Acceleration in X-Axis : -10
Acceleration in Y-Axis : 4
Acceleration in Z-Axis : 221
Acceleration in X-Axis : -10
Acceleration in Y-Axis : 4
Acceleration in Z-Axis : 218
Acceleration in X-Axis : -10
Acceleration in Y-Axis : 4
Acceleration in Z-Axis : 220
Acceleration in X-Axis : -8
Acceleration in Y-Axis : 6
Acceleration in Z-Axis : 220
Acceleration in X-Axis : -8
Acceleration in Y-Axis : 3
Acceleration in Z-Axis : 217
Acceleration in X-Axis : -6
Acceleration in Y-Axis : 6
Acceleration in Z-Axis : 221```
(When the accelerometer is upside down)

These are the data i get from the accelerometer with a loop of 10 times.

In direction like this "z_before = the previously written down values.
z_now = value of the actual measurement."
I am a little bit confused by this. 13. ## Re: How to convert accelerometer data into G with the ADXL345 digital accelerometer

Hi,

* normal position measurement
* Z values are around 220. (I asked you to write these values down)
* then I asked you to turn the sensor upside down
* Z values now are around -264
* so z before was about 220 and now it is about -264
Where is the difficulty?

Klaus 14. ## Re: How to convert accelerometer data into G with the ADXL345 digital accelerometer Originally Posted by KlausST Hi,

* normal position measurement
* Z values are around 220. (I asked you to write these values down)
* then I asked you to turn the sensor upside down
* Z values now are around -264
* so z before was about 220 and now it is about -264
Where is the difficulty?

Klaus
Hi KlausST,
Omg i felt so dumb and thanks for clearing that up for me. Also all the data was acquired with a loop that goes through 10 times, do i need to average them to get the z_before and z_now? 15. ## Re: How to convert accelerometer data into G with the ADXL345 digital accelerometer

Hi,

You have 10 readings (each). The values vary 218...222 (-262 ... -265) because of noise.
If you take a random single value frome the 10 values...you also get a noisy result. With high uncertainty.
If you take the average of the 10 values then you reduce the noise and thus reduce uncertainty.

Klaus 16. ## Re: How to convert accelerometer data into G with the ADXL345 digital accelerometer Originally Posted by KlausST Hi,

You have 10 readings (each). The values vary 218...222 (-262 ... -265) because of noise.
If you take a random single value frome the 10 values...you also get a noisy result. With high uncertainty.
If you take the average of the 10 values then you reduce the noise and thus reduce uncertainty.

Klaus
Hi KlausST,
Got it, thanks.

[QUOTE=KlausST;1647863
Z_offset = (z_before + z_now)/2
Z_sensitivity = (z_before - z_now)/2
Z_multiplier = 1G / z_sensitivityKlaus
For all further Z calculations use: Z = (z_measured - z_offset) * z_multiplier[/QUOTE]

Which means
Z_offset = (219 + (-263.8)) / 2 = -22.4
Z_sensitivity = (219 - (-263.8)) / 2 = 241.4
Z_Multiplier = 256 / 241.4 = 1.061 Am i correct on these calculations?

Also next time when i needed to get Z-axis in G i have to do all the calculations above right? 17. ## Re: How to convert accelerometer data into G with the ADXL345 digital accelerometer

Hi KlausST,
Also i have noticed that based on the method you provided, it takes both +- z-axis data in order to calculate the offset and to convert the value in G. Is there any other way that i can get the offset that would be usable for both the +ve and -ve of z-axis? Because what i am doing is a fall detection system using raspberry pi and it will be strap on the wrist and the accelerometer will likely be on the same direction for most of the time so it might be impossible to calculate the offset value and convert it into G all the time. 18. ## Re: How to convert accelerometer data into G with the ADXL345 digital accelerometer

Hi,

Also next time when i needed to get Z-axis in G i have to do all the calculations above right?
No, this why I explicitely wrote:
For all further Z calculations use: Z = (z_measured - z_offset) * z_multiplier
All other calculations are - as written - for the calibration only ... and thus only need to be calculated when you want to run a calibration cycle.

****
Also i have noticed that based on the method you provided, it takes both +- z-axis data in order to calculate the offset and to convert the value in G. Is there any other way that i can get the offset that would be usable for both the +ve and -ve of z-axis?
Is the given method too simple?

But yes there are other methods. Like: Bring your sensor to the ISS where is zero-G and then you don´t need positive and negative data.

Klaus 19. ## Re: How to convert accelerometer data into G with the ADXL345 digital accelerometer Originally Posted by KlausST Hi,

No, this why I explicitely wrote:

All other calculations are - as written - for the calibration only ... and thus only need to be calculated when you want to run a calibration cycle.

****

Is the given method too simple?

But yes there are other methods. Like: Bring your sensor to the ISS where is zero-G and then you don´t need positive and negative data.

Klaus
No, what i mean is the above method will only works with both the positive and the upside down accelerometer data which is the negative data. But i am doing fall detection system and the accelerometer will be attached on the same direction for most of the times which means it might not even get negative data for the z-axis. So in this case i will not be able to perform all this also. Originally Posted by KlausST Z_offset = (z_before + z_now)/2
Z_sensitivity = (z_before - z_now)/2
Z_multiplier = 1G / z_sensitivityKlaus
For all further Z calculations use: Z = (z_measured - z_offset) * z_multiplier
As all this will only works with the z_before and z_now which are the positive data and the negative data. 20. ## Re: How to convert accelerometer data into G with the ADXL345 digital accelerometer

Hi,

No, what i mean is the above method will only works with both the positive and the upside down accelerometer data which is the negative data. But i am doing fall detection system and the accelerometer will be attached on the same direction for most of the times which means it might not even get negative data for the z-axis. So in this case i will not be able to perform all this also.
Makes no sense to me...

Klaus •

--[[ ]]--