I have a module MPU-9250/6500. Why it must be switched off from power for a few hours (and not just for a few minutes) before I switch it on again to get correct data?
Is there anything wrong with module or do I have to change something in my code?
Situation: My module works well at the beginning. I switch it off. After switch it on again (in a few minutes) I’m getting all incorrect data from it. If it is switched off for a few hours then it works properly.
My code is in the attachement. Thank you for responses!
Jremington, thanks for your quick answer, I think that this could not be the case, because my module is connected to via 3,3V and also level shifter is used on the module. I suppose that something is wrong in the attached code could you please check it.
Sometimes there is a processing unit inside that operates both the I2C bus and the sensor. When it gets pounded with I2C requests, then it might not have time to do other things.
Sometimes the sensor gets hot when there are too many requests for data. Temperature sensors are influenced by this "self-heating".
Can you give a link to where you bought the module ?
When it has level shifters and a voltage regulator, then it is better to apply 5V to VCC. If you apply 3.3V to VCC, then it has to go through a voltage regulator.
Which Arduino board do you use ?
Do you use the newest Arduino IDE ? Do you use an other IDE ? why ? Does it have old libraries ?
The loop() is slowed down by a delay of 200ms, that is good.
The calculate_IMU_error() does (200 + 3233) * 2 = 6866 I2C transactions with the sensor, without any delay in between.
How can any sensor keep up with that ?
Can you lower those numbers and add a delay of 10ms in each while-loop ?
What I write here is far-fetched, and I never heard of this problem before. But I have also never heard of someone doing 6866 I2C transaction without any delay with a sensor.
The variable 'c' is only used locally. You can move that into the function and make it a local variable. That function will work only once, because 'c' is not cleared when leaving that function and it is not cleared when entering that function. To do something a number of times, the for-loop is mostly used.