Connect MPU6050 and BMP180

Luca

Active member
Hi, i need to conect both mpu6050 and bmp180 to an teensy 4.0 via I2C bus, but i do not know how to connect multiple i2c devices to the same board. How can i interface to the multiple I2C ports of the teensy?
Luca.
 
In theory you should be able to hook them up the same way. That is they both use the same pins for SCL/SDA.
And they should hopefully play nice and only respond to their own ID's.
That is if you look at a sketch like, the example master:
Code:
#include "Wire.h"

#define I2C_DEV_ADDR 0x55

uint32_t i = 0;

void setup() {
  Serial.begin(115200);
  Serial.setDebugOutput(true);
  Wire.begin();
}

void loop() {
  delay(5000);

  //Write message to the slave
  Wire.beginTransmission(I2C_DEV_ADDR);
  Wire.printf("Hello World! %u", i++);
  uint8_t error = Wire.endTransmission(true);
  Serial.printf("endTransmission: %u\n", error);
  
  //Read 16 bytes from the slave
  uint8_t bytesReceived = Wire.requestFrom(I2C_DEV_ADDR, 16);
  Serial.printf("requestFrom: %u\n", bytesReceived);
  if((bool)bytesReceived){ //If received more than zero bytes
    uint8_t temp[bytesReceived];
    Wire.readBytes(temp, bytesReceived);
    log_print_buf(temp, bytesReceived);
  }
}
When you wish to talk to a device you do things like: Wire.beginTransmission(I2C_DEV_ADDR);
This starts up a transmission to a specific device that has an address: 0x55

Each device should have different addresses. Sometimes if you are trying to do multiple of the same device, they will have some way to select different addresses. Some do this
by jumpers (either wires or solder), some may allow you to do so with their firmware.
 
You can actually have them on the same bus since their I2C Addressesses are different:
MPU6050 - 0x68
BMP180 - 0x77

As @KurtE showed they can be communicated by just changing I2C_DEV_ADDR to the appropriate device address.
 
Ok, but maiby i was not clear. I have understood that both sensors can run on the same bus but my question was because they can do that, what should i use the other I2C buses for?
 
Ok, but maiby i was not clear. I have understood that both sensors can run on the same bus but my question was because they can do that, what should i use the other I2C buses for?

For whatever reason you might have... Or not.

You might put some things on one buss and other things on another, a few possible reasons:
a) You have a device that does not play well with others...
b) You want to put on multiple devices that have the same I2C address. Example two like displays.
c) Maybe you have a device and software that supports DMA transfers and you wish to do other things while that is going on.
 
Back
Top