Giter Site home page Giter Site logo

arduino-mpu6050's Introduction

arduino-mpu6050's People

Contributors

dtan13 avatar jarzebski avatar mayankgour13 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino-mpu6050's Issues

Using MPU6050 on samd21 based boards

I have an arduino zero clone(samd21). and using this library to interface with mpu6050 imu.
Gyro yaw pitch roll example freezes as soon as it enters the loop.

It this a common issue?

GY-521

Is this code compatible with GY-521?
Its the same circuit right?

question about calibrateGyro() function

void MPU6050::calibrateGyro(uint8_t samples)
{
    // Set calibrate
    useCalibrate = true;

    // Reset values
    float sumX = 0;
    float sumY = 0;
    float sumZ = 0;
    float sigmaX = 0;
    float sigmaY = 0;
    float sigmaZ = 0;

    // Read n-samples
    for (uint8_t i = 0; i < samples; ++i)
    {
	readRawGyro();
	sumX += rg.XAxis;
	sumY += rg.YAxis;
	sumZ += rg.ZAxis;

	sigmaX += rg.XAxis * rg.XAxis;
	sigmaY += rg.YAxis * rg.YAxis;
	sigmaZ += rg.ZAxis * rg.ZAxis;

	delay(5);
    }

    // Calculate delta vectors
    dg.XAxis = sumX / samples;
    dg.YAxis = sumY / samples;
    dg.ZAxis = sumZ / samples;

    // Calculate threshold vectors
    th.XAxis = sqrt((sigmaX / 50) - (dg.XAxis * dg.XAxis));
    th.YAxis = sqrt((sigmaY / 50) - (dg.YAxis * dg.YAxis));
    th.ZAxis = sqrt((sigmaZ / 50) - (dg.ZAxis * dg.ZAxis));

    // If already set threshold, recalculate threshold vectors
    if (actualThreshold > 0)
    {
	setThreshold(actualThreshold);
    }
}

the number 50 should be samples number?

Question about normalized values.

Its not really an issue, more like a question, because I'm not sure if I understand.

Could someone explain what is the difference between raw reading and normalized values?
What are the basis for normalizing it and how does it work?

Mapping random number issue

I'm learning Arduino by working on simple projects. I have an issue with the MPU6050 program with Arduino. I wanted to sweep servo based on the pitch and roll reading from the sensor, however, as the sensor auto-calibrates, if the sensor is not parallel to ground level it calibrates the value it gets as normal reading (i.e) if the sensor is parallel to ground, it should show 0 as reading which is normal value and then changes to negative or positive based on the rotation, if the sensor is inclined to ground level when its calibrating, say 10, it reads that value as normal and then increases or decreases based on the angle the sensor rotates. To sweep the servo from 0 to 180 deg, I need the least negative value and most positive value to be mapped from 0 - 180.

I tried to check the reading to map, sometimes the values will be all negative for example ranging from -10 to -100 sometimes completely positive eg: 10 - 150 sometimes both and negative like -50 to 50. the calibration gives random numbers, is there a way to map them with least number and highest number?

Any leads much appreciated, thank you.

calibrateGyro uses fixed constant of 50

// Calculate threshold vectors
    th.XAxis = sqrt((sigmaX / 50) - (dg.XAxis * dg.XAxis));
    th.YAxis = sqrt((sigmaY / 50) - (dg.YAxis * dg.YAxis));
    th.ZAxis = sqrt((sigmaZ / 50) - (dg.ZAxis * dg.ZAxis));

I think the '50' should be replaced with the parameter 'samples' passed into calibrateGyro, otherwise if samples != 50, then these thresholds will be incorrect.

processing files

excellent library, just wondering where the code for the processing front-end is, looks great.

David

MPU6050_gyro_pitch_roll_yaw code wrong orientation

This code just maps acceleration because mpu6050 is only 6 axis accelerometer.

So this program just count with acceleration(deg/s) calculated from accelerometer data. So theoretically when I start rotating mpu 6050 with this code programm stop counting (writing motion for example in serial plotter), if I am rotating with static speed. In documentation of mpu6050 I found that this "gyroscope" Is actually measuring not rotation but rotting acceleration in XYZ axis. If I am correct this program or whole library needs function what will work with acceleration and calculate that to real rotation.
So am I correct?

the documentation

5.1 Gyroscope Features
The triple-axis MEMS gyroscope in the MPU-60X0 includes a wide range of features:

 Digital-output X-, Y-, and Z-Axis angular rate sensors (gyroscopes) with a user-programmable full-
scale range of ±250, ±500, ±1000, and ±2000°/sec

 External sync signal connected to the FSYNC pin supports image, video and GPS synchronization

 Integrated 16-bit ADCs enable simultaneous sampling of gyros

 Enhanced bias and sensitivity temperature stability reduces the need for user calibration

 Improved low-frequency noise performance

 Digitally-programmable low-pass filter

 Gyroscope operating current: 3.6mA

 Standby current: 5μA

 Factory calibrated sensitivity scale factor

 User self-test

manual link

I got an error for free falling

Arduino: 1.8.1 (Windows 7), Board: "Arduino/Genuino Uno"

C:\Users\Dell\Documents\Arduino\free_fal\free_fal.ino: In function 'void setup()':

free_fal:16: error: 'class MPU6050' has no member named 'begin'

while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_16G))

          ^

free_fal:16: error: 'MPU6050_SCALE_2000DPS' was not declared in this scope

while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_16G))

                ^

free_fal:16: error: 'MPU6050_RANGE_16G' was not declared in this scope

while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_16G))

                                       ^

free_fal:22: error: 'class MPU6050' has no member named 'setAccelPowerOnDelay'

mpu.setAccelPowerOnDelay(MPU6050_DELAY_3MS);

   ^

free_fal:22: error: 'MPU6050_DELAY_3MS' was not declared in this scope

mpu.setAccelPowerOnDelay(MPU6050_DELAY_3MS);

                        ^

free_fal:24: error: 'class MPU6050' has no member named 'setIntFreeFallEnabled'

mpu.setIntFreeFallEnabled(true);

   ^

free_fal:28: error: 'MPU6050_DHPF_5HZ' was not declared in this scope

mpu.setDHPFMode(MPU6050_DHPF_5HZ);

               ^

free_fal:30: error: 'class MPU6050' has no member named 'setFreeFallDetectionThreshold'

mpu.setFreeFallDetectionThreshold(17);

   ^

free_fal:31: error: 'class MPU6050' has no member named 'setFreeFallDetectionDuration'

mpu.setFreeFallDetectionDuration(2);

   ^

C:\Users\Dell\Documents\Arduino\free_fal\free_fal.ino: In function 'void checkSettings()':

free_fal:61: error: 'class MPU6050' has no member named 'getIntFreeFallEnabled'

Serial.println(mpu.getIntFreeFallEnabled() ? "Enabled" : "Disabled");

                  ^

free_fal:64: error: 'class MPU6050' has no member named 'getFreeFallDetectionThreshold'

Serial.println(mpu.getFreeFallDetectionThreshold());

                  ^

free_fal:67: error: 'class MPU6050' has no member named 'getFreeFallDetectionDuration'

Serial.println(mpu.getFreeFallDetectionDuration());

                  ^

free_fal:73: error: 'MPU6050_CLOCK_EXTERNAL_19MHZ' was not declared in this scope

 case MPU6050_CLOCK_EXTERNAL_19MHZ: Serial.println("PLL with external 19.2MHz reference"); break;

      ^

free_fal:74: error: 'MPU6050_CLOCK_EXTERNAL_32KHZ' was not declared in this scope

 case MPU6050_CLOCK_EXTERNAL_32KHZ: Serial.println("PLL with external 32.768kHz reference"); break;

      ^

free_fal:78: error: 'MPU6050_CLOCK_INTERNAL_8MHZ' was not declared in this scope

 case MPU6050_CLOCK_INTERNAL_8MHZ:  Serial.println("Internal 8MHz oscillator"); break;

      ^

free_fal:82: error: 'class MPU6050' has no member named 'getRange'

switch(mpu.getRange())

          ^

free_fal:84: error: 'MPU6050_RANGE_16G' was not declared in this scope

 case MPU6050_RANGE_16G:            Serial.println("+/- 16 g"); break;

      ^

free_fal:85: error: 'MPU6050_RANGE_8G' was not declared in this scope

 case MPU6050_RANGE_8G:             Serial.println("+/- 8 g"); break;

      ^

free_fal:86: error: 'MPU6050_RANGE_4G' was not declared in this scope

 case MPU6050_RANGE_4G:             Serial.println("+/- 4 g"); break;

      ^

free_fal:87: error: 'MPU6050_RANGE_2G' was not declared in this scope

 case MPU6050_RANGE_2G:             Serial.println("+/- 2 g"); break;

      ^

free_fal:91: error: 'class MPU6050' has no member named 'getAccelOffsetX'

Serial.print(mpu.getAccelOffsetX());

                ^

free_fal:93: error: 'class MPU6050' has no member named 'getAccelOffsetY'

Serial.print(mpu.getAccelOffsetY());

                ^

free_fal:95: error: 'class MPU6050' has no member named 'getAccelOffsetZ'

Serial.println(mpu.getAccelOffsetZ());

                  ^

free_fal:98: error: 'class MPU6050' has no member named 'getAccelPowerOnDelay'

switch(mpu.getAccelPowerOnDelay())

          ^

free_fal:100: error: 'MPU6050_DELAY_3MS' was not declared in this scope

 case MPU6050_DELAY_3MS:            Serial.println("3ms"); break;

      ^

free_fal:101: error: 'MPU6050_DELAY_2MS' was not declared in this scope

 case MPU6050_DELAY_2MS:            Serial.println("2ms"); break;

      ^

free_fal:102: error: 'MPU6050_DELAY_1MS' was not declared in this scope

 case MPU6050_DELAY_1MS:            Serial.println("1ms"); break;

      ^

free_fal:103: error: 'MPU6050_NO_DELAY' was not declared in this scope

 case MPU6050_NO_DELAY:             Serial.println("0ms"); break;

      ^

C:\Users\Dell\Documents\Arduino\free_fal\free_fal.ino: In function 'void loop()':

free_fal:111: error: 'Vector' was not declared in this scope

Vector rawAccel = mpu.readRawAccel();

^

free_fal:112: error: 'Activites' was not declared in this scope

Activites act = mpu.readActivites();

^

free_fal:114: error: 'act' was not declared in this scope

Serial.print(act.isFreeFall);

            ^

exit status 1
'class MPU6050' has no member named 'begin'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Euler Angles

Hi Jarzebski,

I have been trying to use your library to convert the axis to Euler angles but I could not figure out. Could you post an example, please?

thank in advance.
best regards.

Arduino ide for esp8266 use MPU6050

I use arduino-MPU6050-master library , No matter how I flip it my serial output is positive and I can't get negative numbers。

like this:

Xnorm = 0.08 Ynorm = 38.57 Znorm = 7.81
Xraw = 84.00 Yraw = 64588.00 Zraw = 13068.00
Xnorm = 0.14 Ynorm = 38.64 Znorm = 7.82
Xraw = 232.00 Yraw = 64724.00 Zraw = 12860.00
Xnorm = 0.18 Ynorm = 38.74 Znorm = 7.77
Xraw = 36.00 Yraw = 64540.00 Zraw = 13124.00
Xnorm = 0.03 Ynorm = 38.63 Znorm = 7.85
Xraw = 64744.00 Yraw = 65072.00 Zraw = 10928.00
Xnorm = 38.79 Ynorm = 38.95 Znorm = 6.97
Xraw = 65244.00 Yraw = 65080.00 Zraw = 13208.00
Xnorm = 39.00 Ynorm = 38.86 Znorm = 7.78
Xraw = 65284.00 Yraw = 64800.00 Zraw = 13284.00
Xnorm = 38.98 Ynorm = 38.78 Znorm = 7.91
Xraw = 65116.00 Yraw = 1248.00 Zraw = 12456.00
Xnorm = 39.03 Ynorm = 0.20 Znorm = 7.50
Xraw = 64716.00 Yraw = 64716.00 Zraw = 13124.00
Xnorm = 38.69 Ynorm = 38.82 Znorm = 7.83

The Wire.requestFrom does not need a Wire.beginTransmission, no Wire.endTransmission and no waiting.

In the file MPU6050.cpp the use of Wire.requestFrom can be improved.

The Wire.beginTransmission and Wire.endTransmission are only needed when writing data. They should not be used with Wire.requestFrom and can be removed. In two places there is Wire.beginTransmission, and in three places both the Wire.beginTransmission and Wire.endTransmission with the Wire.requestFrom. They can all be removed.

The Wire.requestFrom is a complete I2C transaction on its own. It stores the received data in a buffer in the Wire library and returns when the I2C transaction completely has finished. It is therefor not needed to wait for something. In four places there is a while-loop after Wire.requestFrom. Those while-loops can be removed.

Dynamic acceleration from MPU6050

Would it be possible to subtract Earth gravity from the static acceleration reported by MPU6050 to obtain a dynamic acceleration (of course I don't mean simply subtracting 9,81 from Z axis)? For sure, you need to know the device orientation towards the gravity (mass) center of Earth. MPU6050 has gyro, but no magnetometer, but maybe by combining it with an accelerometer data, and using a Kalman filter, we could calculate it precise enough?

Wiring failure

Hi, im having issue on the result shown on serial monitor, my connection is as below:
VCC-----3.3V ( tried connected to 5V but getting same result)
GND-----GND
SCL-------A5
SDA------A4
AD0------GND ( tried to disconnect this but getting same result)

This is what i get on serial monitor:
image
My aim is to get pitch, roll and yaw angle( focusing more to get accurate yaw). Any help for this problem is much appreciated:)

calculating threshold vectors

Hi Korneliusz,

in MPU6050.cpp, lines 571-574 we have the following code:

// Calculate threshold vectors
th.XAxis = sqrt((sigmaX / 50) - (dg.XAxis * dg.XAxis));
th.YAxis = sqrt((sigmaY / 50) - (dg.YAxis * dg.YAxis));
th.ZAxis = sqrt((sigmaZ / 50) - (dg.ZAxis * dg.ZAxis));

should the numbers 50 be replaced by the variable "samples"?

Good day,

Lior

yaw values

I try this but values of yaw is increasing continuously

error

it says that 'class MPU6050' has no member named 'begin'.... what do i do?

Units per deg/sec?

I am making a balancing robot and I need to figure out how many units per deg/sec the
mpu.readNormalizeGyro();
function outputs. I have the gyro configured using
mpu.begin(MPU6050_SCALE_500DPS, MPU6050_RANGE_2G)
Could anyone tell me the range?
Thank you!

readRawAccel() conversion error

There is a bug which reveals itself on 16 or 32 bit MPUs. RAW acceleration is returned via 2 8-bit registers, but is signed, and 2's complement encoded. Registers are mapped as uint8_t (unsigned 8-bit), which is fine, but they are bitshifted and ORed together and assigned to float variable.
xha << 8 | xla creates xa, but it's type is uint16_t, while it should be int16_t... both can be assigned to float variable, but only second one is valid.

Is:

ra.XAxis = xha << 8 | xla;
ra.YAxis = yha << 8 | yla;
ra.ZAxis = zha << 8 | zla;

Should be:

ra.XAxis = (int16_t)(xha << 8 | xla);
ra.YAxis = (int16_t)(yha << 8 | yla);
ra.ZAxis = (int16_t)(zha << 8 | zla);

It just says "Initialize MPU6050"

That's it. It just says "Initialize MPU6050".
i am using a sensor with 10 pins and instead of VCC it uses VDD. It says "CJMCU"
i don't know if i need to drop any additional info

VDD = 3.3v
GND = GND
SCL = A5
SDA = A4

Multiple Sensors

Can you add a method for adding multiple sensors to the Arduino's? I'm not sure how to connect one to 0x68 and 0x69 and call both in a program. Thanks

Gyro Example Simple-Nothing happen

After including all the stuff and adding the files, for some reason when I upload it, nothing happens. It says "Initialize MPU6050" Then nothing.

Does anyone have a solution for this?

Units

What are the units of acceleration and gyroscope for both raw and normalize?

Something wrong about the threshold vectors

// Read n-samples
    for (uint8_t i = 0; i < samples; ++i)
    {
	readRawGyro();
	sumX += rg.XAxis;
	sumY += rg.YAxis;
	sumZ += rg.ZAxis;

	sigmaX += rg.XAxis * rg.XAxis;
	sigmaY += rg.YAxis * rg.YAxis;
	sigmaZ += rg.ZAxis * rg.ZAxis;

	delay(5);
    }

    // Calculate delta vectors
    dg.XAxis = sumX / samples;
    dg.YAxis = sumY / samples;
    dg.ZAxis = sumZ / samples;

    // Calculate threshold vectors
    th.XAxis = sqrt((sigmaX / 50) - (dg.XAxis * dg.XAxis));
    th.YAxis = sqrt((sigmaY / 50) - (dg.YAxis * dg.YAxis));
    th.ZAxis = sqrt((sigmaZ / 50) - (dg.ZAxis * dg.ZAxis));

as we can see, the threshold vectors are calculated from raw data, but in function readNormalizeGyro()

Vector MPU6050::readNormalizeGyro(void)
{
    readRawGyro();

    if (useCalibrate)
    {
	ng.XAxis = (rg.XAxis - dg.XAxis) * dpsPerDigit;
	ng.YAxis = (rg.YAxis - dg.YAxis) * dpsPerDigit;
	ng.ZAxis = (rg.ZAxis - dg.ZAxis) * dpsPerDigit;
    } else
    {
	ng.XAxis = rg.XAxis * dpsPerDigit;
	ng.YAxis = rg.YAxis * dpsPerDigit;
	ng.ZAxis = rg.ZAxis * dpsPerDigit;
    }

    if (actualThreshold)
    {
	if (abs(ng.XAxis) < tg.XAxis) ng.XAxis = 0;
	if (abs(ng.YAxis) < tg.YAxis) ng.YAxis = 0;
	if (abs(ng.ZAxis) < tg.ZAxis) ng.ZAxis = 0;
    }

    return ng;
}

the threshold vectors are compared to normalize data, these few lines should be modified to?

if (actualThreshold)
    {
	if (abs(rg.XAxis) < tg.XAxis) ng.XAxis = 0;
	if (abs(rg.YAxis) < tg.YAxis) ng.YAxis = 0;
	if (abs(rg.ZAxis) < tg.ZAxis) ng.ZAxis = 0;
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.