0

This was touched on in this question, but I was unable to get the solution to work: (Not all devices that are connection via I2C are showing)

I have a GY-87 multi-sensor module and can get the IMU (MPU6050) and Baro to work without issue. Those are i2c addresses 0x68 and 0x77. Supposedly the Compass (HMC5883L) is being blocked by the MPU6050. In the C i2cdev library, there's a call to 'enable bypass' for the compass, which allows it to be accessed. The above question seemingly describes the python equivalent (where you're manually sending the appropriate values to the appropriate registries to enable bypass), but after I run the below code, I don't see the compass appear on i2c detect.

What am I doing wrong?

import smbus
import time

#initialize so we can get the hmc
bus = smbus.SMBus(1) # or 0, depends on the revision of the board
address = 0x68
PWR_MGMT_1 = 0x6B
bus.write_byte_data(address, PWR_MGMT_1, 0x80)
time.sleep(2)

bus.write_byte_data(address, 0x37, 0x02)
bus.write_byte_data(address, 0x6A, 0x00)

Link to module: https://www.amazon.com/Accelerometer-Compass-Barometric-HMC5883L-MPU6050/dp/B017LADTEK

  • Are you saying all these sensors are on the single GY87 module? Please provide a link to the module specs. – joan Sep 8 '18 at 16:12
  • @joan I've provided a link to the module – Speedy Sep 8 '18 at 22:00
  • This guy github.com/jarzebski has Arduino libraries that cover MPU6050 and HMC5883, that might help. From the looks of it the two writes you are doing look correct (setMasterMode = false and setBypassMode = true) the HMC5883 should then be visible on address 1E – KennetRunner Sep 11 '18 at 20:57
  • I testing sending those 3 sets of bytes via C and it worked as expected (i2cdetect showed a device on 1E). Also tested just resetting the device (writing 0x80 to register 0x6B) and then setting 'bypass mode' (writing 0x02 to register 0x37) and then running i2cdetect, and it worked as expected. – KennetRunner Sep 11 '18 at 22:11
0

I haven't done very thorough science on this method, but the secret sauce seems to be:

  1. Initialize the IMU
  2. write 0x02 to 0x37
  3. write 0x00 to 0x6a
  4. write 0x00 to 0x6b
  5. THEN initialize the HMC (the file I use to do that writes 0x70 to 0x00, the appropriate scale factor to 0x01, and then 0x00 to 0x02. These are all per the HMC manual to initialize the device to 15hz output averaging 8 measurements per output in continuous measurement mode with the appropriate scaling).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.