MPU 6050 is jamming the main thread when failed

Hello,

I am trying to get MPU6050 to work and it does. However, on few occasions I noticed that The read function jams the main loop like while(true) function.

I am using this example sketch which is a part of ElectronicsCats library.

In my tests, I plug the sensor out and the main thread just jams. To be exact, I am removing vcc gnd sca sda wires but not the interrupt wire. BTW I use pin 2 as interrupt.

What I want is that I should do things in my main loop function even if the sensor connection is completely disconnected.

I have tried to determine exact line that the thread jams but I have realized that it is kind of random. Since random doesn't make any sense in the world of software, I think this has to do with the interrupts, I know MPU6050 library does use them.

What would you guys do to make this sketch failure proof??

The person who does what you are suggesting would immediately get the hand whacked many times with a very big stick.

Paul

main loop function even if the sensor connection is completely disconnected

You need timeouts and comprehensive error checking in every function call that addresses the sensors. The standard libraries don't provide that.

random doesn't make any sense in the world of software

The behavior is not random. It just seems that way to you because you have no idea what is going wrong.

Keep in mind that a good way to destroy processors and sensor modules is to change the wiring while the circuit is powered up.