Multiple I2C sensors questions

Hello
My project needs to combine both an MPU6050 gyo/accelerometer package using the "i2cdev.h" "wire.h" and "mpu6050.h" libraries and it also needs to use a bmp085 pressure sensor using the "wire.h" and "Adafruit_BMP085.h" libraries.

I'm fine with just one sensor on I2C but I've never used multiple sensors before so I just want to get a few questions cleared before I start assembling things.

First pull up resistors, a few places have said you can connect multiple sensors to the same ports on an arduino (a4, a5, gnd etc) but that pull up resistors are a good idea to use, is this true and if so is there a guide as to which values of resistor to use and which pins must they be connected to besides +v?

And second do I need to do some sort of addressing to differentiate between the two sensors in the code; wire apparently automatically sets the Arduino as the master but I'm not sure whether the above libraries handle addressing and any other issues around multiple i2c devices. Basically to begin with can I just combine the sample code from the two libraries and with a little editing get the raw data out of both the gyro/accelerometer and the barometer?

thanks in advance.

i'm a newbie myself, but i can answer a bit.

multiple sensors should be fine, you can have plenty of them !
check out the I2C reference page via the links in the Learning >> Playgound page of this site.

there are pull-up resistors already available on the Arduino, i've managed to run an LCDisplay via I2C without those, but i'm not sure what power issues would come up if one had more devices on the I2C bus - i'll leave that to someone more knowledgable.

the devices usually have their addresses pre-defined but you can search for it with this nifty helper
http://playground.arduino.cc//Main/I2cScanner

The i2cdevlib has a section for BMP085: BMP085 pressure sensor | I2C Device Library
Everything in the i2cdevlib is know to work together. However using the Adafruit libraries for BMP085 should work I think.

The Arduino Wire library (for I2C) can handle the I2C protocol just fine. You can address all devices on the I2C bus without problem. Each I2C device has its own I2C address. The Wire library sets an address on the bus and only the device that recognizes its address responds to that.

No device on the I2C can pull the SDA and SCL line high. That depends fully on the pull-up resistors. A resistor of 4k7 from SDA to 3.3V or 5V and a resistor of 4k7 from SCL to 3.3V or 5V is best.
When the I2C bus has no wires and is very short, the pull-up resistors can be 50k or more.
When you need a 400kHz I2C bus, over 2 meters, you might perhaps need pull-up resistors of 1k.
If you have too many pull-up resistors, one of the devices might have trouble making the SDA or SCL low.

You have to be careful with pull-up resistors, because of the voltage.
The BMP085 and the MPU-6050 are a 3.3V devices. So you need a 3.3V I2C bus. You can achieve this by using pull-up resistors to the 3.3V. So if none of the I2C devices pulls the bus low, the voltage climbs to 3.3V because of the pull-up resistors.
The BMP085 and MPU-6050 sensor boards probably have already pull-up resistors to 3.3V. Sometimes they have also voltage regulator onboard.
When you have about 5 sensors boards, each with pull-up resistors, there might be too much pull-up. It may sound silly, but I sometimes remove the pull-up resistors from the modules, and keep just one set of pull-up resistors.
Can you tell which modules you use ?

A better way is to use a level shifter. If you use that, you have a 5V and a 3.3V I2C bus and you can add devices to either of the I2C busses. When your Arduino board is the Arduino Uno, Nano, Pro, Mini, Leonardo, or Micro, you don't need that. You must use a level shifter if you use a Arduino Mega 2560.
Which Arduino board are you using ?

When you use different voltage levels it is good practice to use a Level shifter. The one below for Adafruit should work fine:

This already includes 10k pull-up resistors.

It is really very simple to calculate pullup resistor values but requires a little bit of I2C bus spec. knowledge.
The I2C pins for normal mode (100KHz) and fast mode (400KHz) can only sink 3mA, which is also the reason why the overall bus capacitance should not exceed 400pF. Assuming a 5V I2C bus and A 1.8k resistor, according to ohm law 2.8 mA of current flow through the resistor. So in essence a 1k resistor is too low and the likelihood that the pins still are able to pull the I2C lines below the logic zero level is small.

Caltoa:
...
...
No device on the I2C can pull the SDA and SCL line high. That depends fully on the pull-up resistors. A resistor of 4k7 from SDA to 3.3V or 5V and a resistor of 4k7 from SCL to 3.3V or 5V is best.
When the I2C bus has no wires and is very short, the pull-up resistors can be 50k or more.
When you need a 400kHz I2C bus, over 2 meters, you might perhaps need pull-up resistors of 1k.
If you have too many pull-up resistors, one of the devices might have trouble making the SDA or SCL low.

...
...

i was of the understanding that you only need ONE set of pull-up resistors ?

You only need one set of pull-up resistors for the whole I2C bus

from http://www.robot-electronics.co.uk/acatalog/I2C_Tutorial.html

Yes, just ONE set of pull-up resistors.

But many modules have pull-up resistors on the sensor board, and sometimes level shifters have also pull-up resistors included. With a lot of modules added to the I2C it might be too much pull-up.

If you give a link to your sensor modules, I can point out where the smd pull-up resistors are on that board.

Caltoa:
Yes, just ONE set of pull-up resistors.

But many modules have pull-up resistors on the sensor board, and sometimes level shifters have also pull-up resistors included. With a lot of modules added to the I2C it might be too much pull-up.

If you give a link to your sensor modules, I can point out where the smd pull-up resistors are on that board.

ohh, so when the LCDisplay with the 'I2C backpack' worked without any pull-up resistors added, it's possible the I2C bus wasn't relying on the Arduino ones, but resistors already on the I2C backpack ?

something to consider then, haven't gotten any I2C modules as yet.

Yes, and the Arduino enables it's internal pull-up resistors in the Wire library. So even if they are not on the display backpack, the I2C might still work with the internal 50k pull-up resistors.

Note: The Arduino Mega 2560 board has extra 10k pull-up resistors on the I2C bus to 5V. Therefor you can not connect 3.3V sensors to that I2C bus, and you have to use a level shifter.

Caltoa:
Yes, and the Arduino enables it's internal pull-up resistors in the Wire library. So even if they are not on the display backpack, the I2C might still work with the internal 50k pull-up resistors.

Note: The Arduino Mega 2560 board has extra 10k pull-up resistors on the I2C bus to 5V. Therefor you can not connect 3.3V sensors to that I2C bus, and you have to use a level shifter.

okay, thanks - will have to be careful in looking at I2C modules then, kind of figured that the pull-up resistors would be external since we only need one, why would everything (potentially connected) on the I2C bus then be given their own ?!

@ Caltoa, or whomever can provide help,

I am wanting to connect four I2C sensors to an Arduino and would like to disable the pull-up resistors on the BH1750 (Model: GY-30) breakout board. A URL is listed providing both a pic and a circuit diagram for this particular board. My question is: "Is it possible to disable the pull-up resistors on the particular circuit?" and if so, would you please offer your suggestions.

Kind regards,
Jack

http://www.ebay.com/itm/Arduino-I2C-Digital-Light-sunlight-intensity-lux-Sensor-Module-BH1750-BH1750FVI-/121039391267