I have arduino nano + MPU6050 (GY-521) - works fine with other libraries for this sensor. But I would like to find why I get this error with this library.
Initialize MPU6050
Could not find a valid MPU6050 sensor, check wiring!
I followed this tutorial.
I tried to swap SCL and SDA wires - not helped, connected back how described in tutorial.
I searched information related to wires/pins in MPU6050.h and MPU6050.cpp - nothing found.
The initialisation of mpu object fails. How can I get more details in console to identify the root of the problem?
I don't have any resistors on SDA, SCL lines, as this is not required in the tutorial.
I opened MPU6050.cpp and I see for the communication is used the same Wire.h that works in basic hello world test example (but another library).
If wire.h is OK and arduino nano can talk to mpu6050, then the problem is only in this library mentioned above. I tried to look in MPU6050.h the registers addresses and compared them to the rigister addresses from mpu6050 datasheet and they are correct.
MPU address is correct - 0x68 because I don't use AD0 pin.
I MPU6050.cpp, begin function contains 3 parameters, mpu6050_dps_t scale, mpu6050_range_t range, int mpua, but in the arduino sketch, I see only 2 parameters in begin: mpu6050_dps_t scale, mpu6050_range_t range.
Should I add the address in the sketch begin too?
cpp
bool MPU6050::begin(mpu6050_dps_t scale, mpu6050_range_t range, int mpua)
0x68 is a correct address for a MPU6050 (The device has two valid addresses, 0x68 or 0x69, depending on the status of the AD0 pin) so that's good news - it seems to be visible
(on a Nano SDA -> A4; SCL -> A5 should be the correct wiring)
J-M-L:
0x68 is a correct address for a MPU6050 (The device has two valid addresses, 0x68 or 0x69, depending on the status of the AD0 pin) so that's good news - it seems to be visible
(on a Nano SDA -> A4; SCL -> A5 should be the correct wiring)
This is not a case for crappy build because the sensor is detected by I2Cscanner and other libraryes work fine with this sensor. It's not a hardware problem, I think, but a software problem. I need bigger debug level in console to see more details, because this code reports only "check wiring". I checked - wiring is OK.
what do you mean ? Do you have a library working fine with your device? why don't you use it?
Because this library can be used for a very good motion detector. Read my first post.
Other libraries works, but I need to add a lot of C++ code to adjust for a good motion detector. I'm new in C++ and it's difficult for me to start from zero.
While debugging this code I'm learning.
I just modified the function "Check MPU6050 Who Am I Register" to return always true, and the code runs. Now I'm checking why it can't read who am I register.
What is 152 ?? Decimal 152 is 0x98 in hex. Wrong value. Or I'm interpreting something wrong here.
Can someone give an idea? I am reading correctly the values?
OK. 6 bytes not bits. You can ignore my typo in the comment. This does not affect the result. I've requested even 1 byte and I get the same result 152 (0x98), but the right result should be 104 or 0x68
uint8_t value;
Wire.beginTransmission(0x68);
Wire.write(0x75);
Wire.endTransmission();
Wire.beginTransmission(0x68);
Wire.requestFrom(0x68, 1);
value = Wire.read();
Wire.endTransmission();
// now print it
Serial.print(value, BIN);
Then the spec states WHO_AM_I[6:1] that means you need to only take bits 1 to 6 of that register read to form the address and describes it this way
This register is used to verify the identity of the device. The contents of WHO_AM_I are the upper 6 bits of the MPU-60X0’s 7-bit I2C address. The least significant bit of the MPU-60X0’s I2C address is determined by the value of the AD0 pin. The value of the AD0 pin is not reflected in this register .
The I2C bus specification specifies that in standard-mode I2C, the slave address is 7-bits long followed by the read/write bit.