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.

Does gyroscope requires calibration? (MPU 6050)

Status
Not open for further replies.

ckkkkk

Junior Member level 2
Joined
Apr 19, 2019
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
204
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

This is the datasheet for the ADXL345 digital accelerometer [1]: https://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf

HTML:
import smbus
import time

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

# ADXL345 address, 0x53(83)
# Select bandwidth rate register, 0x2C(44)
#       0x0A(10)    Normal mode, Output data rate = 100 Hz
bus.write_byte_data(0x53, 0x2C, 0x0A)
# ADXL345 address, 0x53(83)
# Select power control register, 0x2D(45)
#       0x08(08)    Auto Sleep disable
bus.write_byte_data(0x53, 0x2D, 0x08)
# ADXL345 address, 0x53(83)
# 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)

# ADXL345 address, 0x53(83)
# Read data back from 0x32(50), 2 bytes
# X-Axis LSB, X-Axis MSB
data0 = bus.read_byte_data(0x53, 0x32)
data1 = bus.read_byte_data(0x53, 0x33)

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

# ADXL345 address, 0x53(83)
# Read data back from 0x34(52), 2 bytes
# Y-Axis LSB, Y-Axis MSB
data0 = bus.read_byte_data(0x53, 0x34)
data1 = bus.read_byte_data(0x53, 0x35)

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

# ADXL345 address, 0x53(83)
# Read data back from 0x36(54), 2 bytes
# Z-Axis LSB, Z-Axis MSB
data0 = bus.read_byte_data(0x53, 0x36)
data1 = bus.read_byte_data(0x53, 0x37)

# 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.
 

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).

multiply your axis reading with this constant to get g value.
 

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).

multiply your axis reading with this constant to get g value.

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?
 

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.
 

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.
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?
 

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:

CodeCogsEqn1.gif

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.
 

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
 

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

You cannot simply perform a scalar multiplication with only one axis, but vectorial along 3 axis, as below:

View attachment 152468

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.
 

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

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.
 

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

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?
 

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
 

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

HTML:
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:
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 thisforumwithaccelDirectionsa.PNG


"z_before = the previously written down values.
z_now = value of the actual measurement."
I am a little bit confused by this.
 

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
 

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

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?
 

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
 

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
Hi KlausST,
Got it, thanks.

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 said:
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?
 

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.
 

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
 

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

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.
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.
 
Last edited by a moderator:

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
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top