Code Monkey home page Code Monkey logo

adafruit_mpu6050's Introduction

Adafruit MPU6050 Build Status

This is the Adafruit MPU6050 6-DoF Accelerometer and Gyro Library for Arduino

Tested and works great with the Adafruit MPU6050 Breakout Board

This chip uses I2C to communicate, 2 pins are required to interface

Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!

Installation

To install, use the Arduino Library Manager and search for "Adafruit MPU6050" and install the library.

Dependencies

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

Documentation and doxygen

Documentation on Github pages

Documentation is produced by doxygen. Contributions should include documentation for any new code added.

Some examples of how to use doxygen can be found in these guide pages:

About Doxygen

Doxygen Tips

Formatting and clang-format

This library uses clang-format to standardize the formatting of .cpp and .h files. Contributions should be formatted using clang-format:

The -i flag will make the changes to the file.

clang-format -i *.cpp *.h

If you prefer to make the changes yourself, running clang-format without the -i flag will print out a formatted version of the file. You can save this to a file and diff it against the original to see the changes.

Note that the formatting output by clang-format is what the automated formatting checker will expect. Any diffs from this formatting will result in a failed build until they are addressed. Using the -i flag is highly recommended.

clang-format resources

About this Driver

Written by Bryan Siepert for Adafruit Industries. BSD license, check license.txt for more information All text above must be included in any redistribution

adafruit_mpu6050's People

Contributors

asaujim avatar caternuson avatar cimba007 avatar evaherrada avatar gabrielcsapo avatar kattni avatar ladyada avatar mahboud avatar matdombrock avatar siddacious avatar tyeth avatar yoavw 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

adafruit_mpu6050's Issues

Typo in README.md

The README.md file says "Adafruit MPU6050 6-DoF Accelerometer and Magnetometer". However, it should be "Adafruit MPU6050 6-DoF Accelerometer and Gyroscope“, as MPU6050 does not have a built-in magnetometer.

No .h headers in latest release - throws error

  • Arduino board: ESP32E

  • Arduino IDE version: 1.8.19
    LIST REPRO STEPS BELOW
    When i try to add the libary to the Arduio IDE, it throws an error that .h files are not found. The text in the picture is in dutch.

Schermafbeelding 2022-02-23 om 13 54 43

Then i downloaded the sirectory as a zip file, and installed it through the sketch. It told me all was ok , but after compilation igot this message: The first part in dutch tells me unvalid library found. And again, noheaders

Leaving...
Hard resetting via RTS pin...
Ongeldige bibliotheek gevonden in /Users/erikschott/Documents/Arduino/libraries/Adafruit_MPU6050: no headers files (.h) found in /Users/erikschott/Documents/Arduino/libraries/Adafruit_MPU6050

Too many dependencies?

These dependencies are only needed for one of the samples and not for using the actual sensor.
It has nothing to do with graphics or controlling some mono screen.

- [Adafruit GFX Library](https://github.com/adafruit/Adafruit-GFX-Library)
- [Adafruit SSD1306](https://github.com/adafruit/Adafruit_SSD1306)

Example for motion detection interrupt

Hi! Is there any complete example for getting motion detection interrupt using this library? I noticed that someone has already implemented on the pull request but the same guy didn't give us a complete valid example, just a small snippet. I tried to use this snippet but I haven't got success on achieving this detection.

Failed to find MPU6050 chip

the new version MPU6050 has the different DEVICE_ID

Change the Macro in “Adafruit_MPU6050.h” File:
#define MPU6050_DEVICE_ID 0x68 -> #define MPU6050_DEVICE_ID 0x98
can solve the problem .

I don't think this is the best solution to solve it. so I just put it in Issues.

I try the solution (add code to main.ino):

#ifdefine MPU6050_DEVICE_ID 
#undefine MPU6050_DEVICE_ID 
#define MPU6050_DEVICE_ID 0x98
#endif

but it did not work.

setMotionInterrupt is enabling the wrong bit

  • Arduino board: ESP32
  • Arduino IDE version: 1.8.19
  • Library version: 2.2.4

I am trying to use the interrupt pin to trigger reads on the MCU when new data is ready, but I was not having any luck. I took a close look at how the library was enabling the pin interrupt and it did not make much sense when comparing to the datasheet.

This library has been around for a while and no issues have addressed this, so maybe I am misunderstanding something.

The interrupt is enabled by setMotionInterrupt():

void Adafruit_MPU6050::setMotionInterrupt(bool active) {
  Adafruit_BusIO_Register int_enable =
      Adafruit_BusIO_Register(i2c_dev, MPU6050_INT_ENABLE, 1);
  Adafruit_BusIO_RegisterBits int_motion =
      Adafruit_BusIO_RegisterBits(&int_enable, 1, 6);
  int_motion.write(active);
}

However, the datasheet shows that the relevant registry bits are the following:
Screenshot 2023-08-04 at 10 51 32

As you can see, the bit 6 does not have any function.

I was interested in having the MPU6050 interrupt (INT) pin latched when new data was available. I changed the function to enable the bit 0 instead of 6 and indeed data started flowing as expected:

void Adafruit_MPU6050::setMotionInterrupt(bool active) {
  Adafruit_BusIO_Register int_enable =
      Adafruit_BusIO_Register(i2c_dev, MPU6050_INT_ENABLE, 1);
  Adafruit_BusIO_RegisterBits int_motion =
      Adafruit_BusIO_RegisterBits(&int_enable, 1, 0);
  int_motion.write(active);
}

I noticed the same issue with the Adafruit_MPU6050::getMotionInterruptStatus() method, which also reads the bit 6, which does not have any function in the datasheet.
Screenshot 2023-08-04 at 10 35 51

This brings me to the motion_detection.ino example: I have no idea how it actually works, as the bit 6 is being evaluated via the getMotionInterruptStatus() method and according to the datasheet nothing should happen. I can only guess this bit might also be toggled, but is not documented as such.

Could someone double check this?

Relevant to this topic: the other thing I want to do is to enable INT_RD_CLEAR bit, in the INT_PIN_CFG register, so any read would clear the latch, set by the available setInterruptPinLatch() method, but this is not exposed by this library. Currently, only reading the INT_STATUS register will clear the latch, which is not needed when you already know new data is available via the INT pin. Indeed, when I enabled this bit, executing getMotionInterruptStatus() became unnecessary.

Calling .begin() multiple times has a memory leak

Multiple calls to begin and subsequently to _init will lead to the code below having a memory leak.

  delay(100);
  
  temp_sensor = new Adafruit_MPU6050_Temp(this);
  accel_sensor = new Adafruit_MPU6050_Accelerometer(this);
  gyro_sensor = new Adafruit_MPU6050_Gyro(this);

fix:

  delay(100);
  delete temp_sensor;
  delete accel_sensor;
  delete gyro_sensor;
  
  temp_sensor = new Adafruit_MPU6050_Temp(this);
  accel_sensor = new Adafruit_MPU6050_Accelerometer(this);
  gyro_sensor = new Adafruit_MPU6050_Gyro(this);

Proof: First Number is heap available and other numbers are acceleration X,Y,Z

00:56:51.542 -> 1199,0.29,0.23,8.37
00:56:53.938 -> 1172,0.26,0.24,8.25
00:56:56.334 -> 1145,0.21,0.27,8.25
00:56:58.760 -> 1118,0.17,0.31,8.18
00:57:01.150 -> 1091,0.26,0.25,8.26
00:57:03.540 -> 1064,0.26,0.33,8.41
00:57:05.946 -> 1037,0.22,0.21,8.01
00:57:08.381 -> 1010,0.28,0.31,8.30
00:57:10.780 -> 983,0.25,0.25,8.31
00:57:13.173 -> 956,0.26,0.29,8.26

Result .. on low memory ECU hangs or resets.

Usecase: Power the MPU6050 by an Arduino pin. This requires reinitialisation (by mpu.begin() after sleep-periode + power-up of MPU6050).

Incorrect comment in header file re default address. No useful documentation...

This is written in the header file, and is WRONG:-

#define MPU6050_I2CADDR_DEFAULT 0x68 ///< MPU6050 default i2c address w/ AD0 high

The I2C address is 0x68 when AD0 is LOW
The I2C address is 0x69 when AD0 is HIGH.

This is important, because many people have to change the address to 0x69 (wire AD0 to VCC) in order for the MPU6050 to co-exist with most RTC clock modules, which also use 0x68 I2c (and cannot be changed).

It appears that we can pass the I2C address into the begin() function? This needs to be documented.

You've got a README.md (yay!) except it doesn't tell you anything about how to use the lib (boo!!): Please include basic library usage functions into the README, so we know how to use this from page 1....

Multiple MPUs in the same code?

We try to use two MPU650 in parallel @uno in the same code.
Generally I2C scanner shows both of them with their addresses.

This does not seem to work:

Adafruit_MPU6050 accelgyroIC1(0x68);
Adafruit_MPU6050 accelgyroIC2(0x69);

Any idea what we did wrong?
Thanks

Alternative to resetting clearing MPU on init and begin calls.

  • Arduino board: MPU6050

  • Arduino IDE version (found in Arduino -> About Arduino menu): NA - 2.0 or 1.8

  • List the steps to reproduce the problem below (if possible attach a sketch or
    copy the sketch code in too):

When you use the ESP32 in Deep Sleep mode, and are using a MPU6050 that is configured to wake the ESP32, the interrupt status bits that are required to be read, will get demolished by the init() call (calling reset()), and the begin() call changes other settings that might not be desirable.

This is due to the fact that the ESP32's return from deep sleep, is very similar to a reset of the chip and many configurations, such as i2c connections, are reset and need to be reconfigured. It is important to be able to read the i2c, without disturbing important data.

An alternative could be to have init() not do anything but to make sure Wire and i2c are setup for the board so that communication can happen between the esp32 and the MPU6050. Then most people would use begin() to continue normal setup. Those who care to preserve the settings they already have, will not call begin(). They would read what they need, and change any settings as needed, without having a call that blanket resets things.

I don't think this is a big change, and I plan to try out those changes myself, to see if it accomplishes my goal. I'm curious what your thoughts are about this.

Examples do not build - code bug? - trying to return VOIDs

Building for ESP32 D1 I observe the following:-

C```
:\Users\cnd\Documents\Arduino\libraries\Adafruit_MPU6050\Adafruit_MPU6050.cpp: In member function 'bool Adafruit_MPU6050::enableSleep(bool)':
C:\Users\cnd\Documents\Arduino\libraries\Adafruit_MPU6050\Adafruit_MPU6050.cpp:497:28: error: void value not ignored as it ought to be
return sleep.write(enable);
^
C:\Users\cnd\Documents\Arduino\libraries\Adafruit_MPU6050\Adafruit_MPU6050.cpp: In member function 'bool Adafruit_MPU6050::enableCycle(bool)':
C:\Users\cnd\Documents\Arduino\libraries\Adafruit_MPU6050\Adafruit_MPU6050.cpp:519:28: error: void value not ignored as it ought to be
return cycle.write(enable);
^
C:\Users\cnd\Documents\Arduino\libraries\Adafruit_MPU6050\Adafruit_MPU6050.cpp: In member function 'bool Adafruit_MPU6050::setGyroStandby(bool, bool, bool)':
C:\Users\cnd\Documents\Arduino\libraries\Adafruit_MPU6050\Adafruit_MPU6050.cpp:576:79: error: void value not ignored as it ought to be
return gyro_stdby.write(xAxisStandby << 2 | yAxisStandby << 1 | zAxisStandby);
^
C:\Users\cnd\Documents\Arduino\libraries\Adafruit_MPU6050\Adafruit_MPU6050.cpp: In member function 'bool Adafruit_MPU6050::setAccelerometerStandby(bool, bool, bool)':
C:\Users\cnd\Documents\Arduino\libraries\Adafruit_MPU6050\Adafruit_MPU6050.cpp:603:40: error: void value not ignored as it ought to be
zAxisStandby);
^
C:\Users\cnd\Documents\Arduino\libraries\Adafruit_MPU6050\Adafruit_MPU6050.cpp: In member function 'bool Adafruit_MPU6050::setTemperatureStandby(bool)':
C:\Users\cnd\Documents\Arduino\libraries\Adafruit_MPU6050\Adafruit_MPU6050.cpp:622:28: error: void value not ignored as it ought to be
return temp_stdby.write(1);
^
exit status 1
Error compiling for board ESP32 Dev Module.

Bias cancellation procedure is missing

MPU6050 suffers from small gyro biases that make it difficult to compute the orientation in the absence of a compass reference.

This application note shows a possible procedure to the problem.

I also found a complete implementation here.

I think a proper integration of these procedures in this library is necessary to make it fully usable.

WDT trigger on ESP32C3

I'm using a ESP32C3 board, and the program will stop for about 30min, and WDT got trigger.

The same program works fine on ESP8266.

Wrong description in file Adafruit_MPU6050.h

Lines 203/204:

 *    @brief  Class that stores state and functions for interacting with
 *            the MPU6050 I2C Digital Potentiometer

Obviously, the MPU-6050 is not a Digital Potentiometer!

The method setTemperatureStandby() always disables the sensor.

setTemperatureStandby always disables the temperature sensor regardless of the argument's value. The last line of its code (622) always writes a 1 instead of using the argument. So using setTemperatureStandby(false) still disables the sensor.

/**************************************************************************/
/*!
* @brief Sets disable mode for thermometer sensor.
* @param enable
* If `true` the temperature sensor will stop taking measurements.
* Setting `false` returns the temperature sensor to the normal
* measurement mode.
* @return True if setting was successful, otherwise false.
*/
/**************************************************************************/
bool Adafruit_MPU6050::setTemperatureStandby(bool enable) {
Adafruit_BusIO_Register pwr_mgmt =
Adafruit_BusIO_Register(i2c_dev, MPU6050_PWR_MGMT_1, 1);
Adafruit_BusIO_RegisterBits temp_stdby =
Adafruit_BusIO_RegisterBits(&pwr_mgmt, 1, 3);
return temp_stdby.write(1);
}

It might just be a small typo. It seems to be solved by swapping the call in the line 622 for return temp_stdby.write(enable);

Where are the docs?

In the readme I see that it mentions that the docs are generated with Doxygen and I see the links to learn about Doxygen but where are the actual docs for this project located?

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.