jefmenegazzo / mpu-i2c-drivers-python

I2C Drivers for MPU-9250, MPU-9255, MPU-9150, MPU-6500, MPU-6555, and MPU-6050
https://jefmenegazzo.github.io/mpu-i2c-drivers-python/
Other
72 stars 23 forks source link

Cannot calibrate slave #9

Closed jessicatrac closed 3 years ago

jessicatrac commented 4 years ago

Hello! Thanks so much for your work - greatly appreciated. I'm working with two MPU9250s for a simulator project and am having trouble getting data from the slave consistently. When I start up my Pi for the first time and run the master-slave-mode.py example without the calibration, I get reliable readings for the master and slave. For example, accelerometer readings of [0,0,1] on flat ground and [0,0,-1] when flipped upside down. Gyroscope readings are close to [0,0,0] while stationary for the most part.

When I run mpu.calibrate() after, I run into this error:

Calibrating 0x68 - AK8963 Traceback (most recent call last): File "/home/pi/MPU9250/examples/basic-usage/master-slave-mode.py", line 36, in mpu.calibrate() # Calibrate sensors File "/home/pi/MPU9250/mpu9250_jmdev/mpu_9250.py", line 592, in calibrate self.calibrateAK8963() File "/home/pi/MPU9250/mpu9250_jmdev/mpu_9250.py", line 887, in calibrateAK8963 avg_rad / mag_scale[0], ZeroDivisionError: float division by zero

Since I am most concerned with getting accel & gyro readings for my project, I switch to mpu.calibrate6500(), but run into this error next:

Could not connect to slave to calibrate |.....MPU9250 in 0x68 Biases.....| Accelerometer Master [0.12724958147321427, 0.08103143601190477, -0.13961937313988093] Accelerometer Slave [0, 0, 0] Gyroscope Master [-2.0375932965959818, -0.30699230375744047, -0.20599365234375] Gyroscope Slave [0, 0, 0] Magnetometer SID [1, 1, 1] Magnetometer HID [0, 0, 0]

At first I thought it might be a wiring problem with the slave IMU. However, since the initial readings look fine I am not sure if that is the case. I've reproduced this pattern (data collection works until I attempt calibration) 3 times consecutively. Any guidance would be appreciated!

jefmenegazzo commented 4 years ago

@jessicatrac Could you give the following information?

The first error ZeroDivisionError: float division by zero occurs due to a problem when calibrating the magnetometer. However, division by zero here only occurs if the magnetometer reading is in trouble, always returning 0. There may be a hardware problem.

In the case of using direct calibration with calibrateMPU6500, it again appears to be possibly a hardware error.


In my experience, signal loss may be occurring. In these cases the connection with MPU sometimes works, sometimes it doesn't. One of the times that the signal loss occurred to me was because I was using a long cable (more than 2.5m). Note that in this case, both the length and the diameter of the cable you use can cause signal loss. One thing you can try to do is leave the MPU and your SBC connected / powered, and next disconnect the VCC and GROUND cables from the SBC GPIO and reconnect, running the code afterwards.


Another alternative is the following: if you are using only two MPUs, you can connect them on the same SBC and use address 0x68 for one and 0x69 for the other. If you have only one I2C GPIO in your SBC, you can build a cable as shown in the Figure below:

RedeSensores1

I will appreciate it if you can share your solution.

jessicatrac commented 4 years ago

@jefmenegazzo sure! Thanks for the help.

oct21_mpu9250_jmdev_test.txt -> here's some logs from a test I did. 2 successful data collections prior to any calibration. 2 successful calibrations next (although the 2nd doesn't seem as valid). Then 3 unsuccessful calibrations.

IMG_6393

I am only using two MPU9250s and have them wired up as your diagram is showing for MPU0x68 Master and Slave. I don't suspect it's a wiring issue since the solder points are fine and length is as well. I may try the 0x69 route for one but I recall having some trouble with it before. I also think it might be signal loss due to a hardware error but cannot confirm. My breakout board for the MPU9250 is also different from the one you linked on pypi, which is likely not a factor. I'm using Sparkfun. I think I'll attempt the 0x69 route again and then order some new sensors in case it's a true hardware issue.

I will give you another update once I try a couple of the above. Please let me know if any of my answers above give you any further insight into my problem!

jessicatrac commented 3 years ago

@jefmenegazzo thanks for your help. In the end I had set the MPU addresses to 0x68 and 0x69 and create two separate objects. I was not able to get the data collection working by assigning the addresses as the master and slave. Not sure why, as they work separately and hardware seems fine!