What is the meaning of "volatile bool mpuInterrupt = false; " in Arduino Program interfacing MPU6050?

closed as unclear what you're asking by per1234, sempaiscuba, MatsK, VE7JRO, gre_gor Jan 10 at 12:07

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    what program? I would guess it is a flag set in interrupt triggered by the MPU6050 indicating to the reset of the sketch that the interrupt was triggered – Juraj Jan 8 at 9:25

The i2cdevlib has that declared in this file: https://github.com/jrowberg/i2cdevlib/blob/master/Arduino/MPU6050/examples/MPU6050_DMP6/MPU6050_DMP6.ino

That is the "dmp" example.
Inside the MPU-6050 sensor is a "dmp" and a FIFO buffer. The "dmp" is a processing unit that collects the sensor data, does some calculations and puts the data in the FIFO buffer. After that the Arduino is signalled with a interrupt.

In the Arduino, in the interrupt routine, the flag 'mpuInterrupt' is set. In the loop() that flag is checked and the amount of data in the FIFO buffer is read. When there is enough data, that data is read and used in the sketch.

Since the variable 'mpuInterrupt' is used in a interrupt routine and in the loop(), it is made 'volatile'. That tells the compiler that the variable can change at any moment, so the compiler can keep that in mind when creating binary code for the loop().

  • Thanks for answering! I got it. From where did u get all this knowledge... any book you can prefer? – Soham Prajapati Jan 8 at 10:15
  • @SohamPrajapati I know the mpu-6050 and the i2cdevlib a little. Setting a volatile bool variable in a interrupt routine to 'true' and dealing with that in the loop() is something common for arduino. – Jot Jan 8 at 13:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.