So a couple days ago I tested imu sensor (MPU6050) code which I wrote that calculates roll, pitch and yaw values and it was working. Printing out values at least.
I tested it again today with another MPU6050 and for some reason it hangs or something, as if its in an infinite loop. Doesnt throw an error, it just hangs in the setup function. Some serial prints indicated to me that it hangs when it hits the .endTransmission() function as it only reaches and prints "Before end" and nothing after. Just an empty serial monitor.
Im really annoyed cuz this code, unchanged, worked before but I cant get my hands on the same components i used last time. Is there any way I can determine that the sensor I have now is faulty or is it a problem with my code (which I dont understand how). The sensor lights up when connected to power and ground, and two other wires for SDA and SCL. I dont know what an interrupt is, should I be using it? I wasnt it using it before. im not that great at the hardware.
Anyways, Im pissed.
void MPU::setupMPU(){
Wire.begin();
Wire.beginTransmission(MPU_address); // Beginning transmission on 0x68, the address of the MPU according to the datasheet
Wire.write(0x6B);
Wire.write(0); // Waking up the MPU by writing a 0 byte to the power management register at 0x6B
Serial.println("Before end");
Wire.endTransmission();
Serial.println("After");
currentTime = millis();
}
Well Im pretty sure theyre built in as I said I used this exact configuration before and it worked fine. Just with a different module (still MPU6050).
Frankly i didnt even know what pullup resistors were before this
Relax, and start thinking about better components for a newer version of your project. The MPU-6050 is no longer made and can no longer be bought. The cheap modules with a MPU-6050 might have a counterfeit chip and there are problems with the design of the cheap modules and wrong components on them.
If you want something that works, then buy things that have been tested by the seller and buy from sellers who are willing to help in case of problems. Good sellers are the Arduino store, Adafruit, Sparkfun, Pololu.
Adafruit has the best tutorials.
What is your Arduino board ?
The I2C bus can halt a sketch when there is a short circuit between SDA and SCL or between SDA and GND or between SCL and GND. But it can also be caused by long wires, missing pullup, missing power to the module, bad soldering, broken jumper wires, and so on.
If you can fix your I2C bus, then you can add a timeout: setWireTimeout() - Arduino Reference (the timeout should not be used to deal with a bad I2C bus, fix your I2C bus first).
Can you show a photo that shows the wiring from the Arduino to the MPU-6050 module ?