Using 2 I2C compass chips simultaneously


Active member
Hi there. I'm trying to use two I2C sensors (HW-246 GY-271) simultaneously. From what I've read it should be possible to have the two sensors connected to the same pins on the Arduino. I also have a Teensy, which has multiple I2C pins. But the libraries (QMC5883L) I'm using don't have any method for assigning pins. Can any one guide me a bit into the ins and outs of this? I'm quite lost in between assigning I2C pins in the libraries used and identifying multiple I2C devices and can't really find info on either topic...
You are going to probably have to use 2 separate Wire buses since both share the same I2C address unless your specific module has a way to change its address.

As for a library you are going to have to point to the exact library you are using for help on that one. More than likely the library will have to be modified to make it generic so different buses can be used. Assuming you are using a Teensy 4.1 - you didtn't specify.
There are I2C multiplexers. You hook each device up to separate logical I2C busses. When you want to talk to a particular device, you send an I2C message to the multiplexer for which bus to connect to. You do have to be careful if the library communicates with the device in the background and pause such communication while you are talking to the other device.
Followed instructions in topic underneath and now have two compass sensors running simultaneously on two I2C busses on a Teensy 4.1