I2C and addresses

Hi, With my Arduino Uno, I want to use three I2C devices: A BMP180 Digital Barometric Pressure Sensor Board, an RTC DS1307, and a I2C Adapter Serial Interface Board Module mounted on a 1602 LCD 16x2.

My questions are: 1. Do I locate the address number of each device on its data sheet ( or with the I2C scanner at: https://github.com/todbot/arduino-i2c-scanner)? 2. How can I determine the voltages of each I2C device? 3. And, if the addresses are different, then do I not need to use an I2C multiplexer 4. Can I connect the SPL's from each device to the SPL on the Uno. The same question for the SDA's. 5. And how can I determine if I need to use resistors and which amounts.

Thank you, Steve

selster: Hi, With my Arduino Uno, I want to use three I2C devices: A BMP180 Digital Barometric Pressure Sensor Board, an RTC DS1307, and a I2C Adapter Serial Interface Board Module mounted on a 1602 LCD 16x2.

My questions are: 1. Do I locate the address number of each device on its data sheet ( or with the I2C scanner at: https://github.com/todbot/arduino-i2c-scanner)?

Use datasheet if you have one or just run the scanner with ONLY one device physically connected.

  1. How can I determine the voltages of each I2C device?

You do not need to as long as they are ALL +5V or +3.3V , but recheck that Uno runs the TWI on +5V to make sure.

  1. And, if the addresses are different, then do I not need to use an I2C multiplexer

Correct, that is the purpose of the TWI - common "bus" interface.

  1. Can I connect the SPL's from each device to the SPL on the Uno. The same question for the SDA's.

ABSOLUTELY See above

  1. And how can I determine if I need to use resistors and which amounts.

NONE check if the TWI has internal pull-ups on Uno and with all those device on the bus you do not need one anyway. The only possible issue may be when checking for response (ACK )

Thank you, Steve

Good luck, I am just going thru TWI for LCM1602 on Due. Fun.

You need to check if these devices have pull up resistors built in. The I2C RTC module we sell does have. You only want one set, and for preference to the working voltage of your Arduino.

If they have different addresses (they should) they will all work OK on the same bus. Each call to an I2C device should specify an address that it is trying to communicate to. (Our RTC module has a DS1307 and an I2C EEPROM on different addresses so it is two i2C devices accessed separately).

To find out each I2C address you use and I2C scanner. It may well be best to do one at a time to make sure you get them all.

From my immediate experience using scanner on Due - it is a big gamble!
I just got my LCM1602 working and the scanner did not find the address, but found 27 devices which do not exist!
I think using this

Wire1.beginTransmission(address);
error = Wire1.endTransmission();

without knowing what the TWI clock is and checking for immediate response may be a problem.
I may play with it later.

Is your LMC1602 20 x 4 characters? You get an interesting pattern when you send more than 20 characters to it. Line 0 an 2 are a pair ( acting as single line ) and 1 and 3 same.
Kind of interleaved. Even and odd perhaps.
Can’t wait to try some “high tech” graphics on it!

boolean CLCM1602::I2C_Scanner(void)
{
#ifdef DEBUG
  TRACE("boolean CLCM1602::I2C_Scanner(void)", 1);
#endif

  byte error, address;
  int nDevices;
do
{
  Serial.println("\nScanning...");

  nDevices = 0;
  for (address = 1; address < 127; address++ )
  {
    Serial.printf("\nScan address %x ", address);
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire1.beginTransmission(address);
    error = Wire1.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.print(address, HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error == 4)
    {
      Serial.print("Unknow error at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.println(address, HEX);
    }
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(100);           // wait 5 seconds for next scan
}while(1);

  return true;

}

Vaclav: From my immediate experience using scanner on Due - it is a big gamble!

I've done an I2C scan on an Uno and Pro mini and that seems to work well.

"You need to check if these devices have pull up resistors built in. The I2C RTC module we sell does have. You only want one set,"

What happens if more than one device has built in pull up resistors? Would I need to take them out of two devices, so that only one has the pull ups? Thanks

Well, it depends on what pull up resistors they have.

http://www.gammon.com.au/i2c

Many thanks Nick. So a rule of thumb would mean that as long as the effective resistance is over 1K for powered or more than 2K2 for battery, it should be OK?

As I recall, the recommended value is 4.7k so I would be aiming for that, although as you can see from the scope images, it isn't really critical. I estimate a constant current of 1.06 mA if you use 4.7k at 5v, I suppose it depends if you can wear that continuously. You could always turn the pull-ups on and off, if you are only using them occasionally.

http://www.gammon.com.au/power

Some devices come with them built in for convenience but I am not sure that is an advantage. But I suppose to answer the OP’s query about I2C pullups, if all three have them, and they were all 4k7, he could certainly leave them as is for testing, and if he needs to save battery life when running for real, he should remove some.

I’d say, as a matter of course, you should at least have a quick glance through the datasheet of any device you’re going to add to your project. While you’re there you might just as well take note of it’s I2C address. IF the device fails to respond to the address given, THEN use the scanner to see if it can locate the device on a different address.

Than you very much! I have the following:

  1. I2C interface for LCD: no pull up resistors. Address is 0x20 or 0x38. Voltage = 5 volts.
  2. I2C Barometer BMP180 board: SCL and SDA each have a 3.7K resistor. Voltage = 3.3 volts. Not sure of address. 3.a. I2C RTC: SCL and SDA each have 3.3K resistors. Volts. I think 2.7 - 5.5. Maxim DS1307. Not sure how to find address. 3.b. I2C RTC EEPROM: Atmel At 24C32/64. not sure how to find address.

I need to figure out the addresses or get them via the I2C scanner. In any event, both the barometer and the RTC have pull up resistors. Do I need to remove them, one or both? Thank you, Steve

The addresses of the RTC is if I remember correctly 0x68 and EEPROM is 0x50. (Both in hex).

It's possibly the pressure meter may not like being connected to 5v via the I2c resistors in the RTC. You could remove them. (Once you are sure they work on their own.)

Actually the pull resistors for the I2C LCD interface are 10K for both SCL and SDA.

I am not sure why we are getting into this “pull-ups” , the sole purpose of pull- up / pull-down resistor is to keep the (processor) input at known state when there is no device connected to it.
AKA open / unconnected input on dual gate AND needs pull-up so it does not float at random level.
If you do NOT read it the input state in processor it is irrelevant.
I2C is a serial , connected, not open bus (similar function as USB) - under processor control and should not be allowed to float , hence it needs SOME pull-up. So if one device has pull-up ( perhaps the processor) it is all what is needed. ( Physical length of the bus is also a factor) If there is more, as long as it does not drain your power source, it is OK.

Now the scanner code is a different story - there are TOO many wire.h/ cpp codes floating ( no pun intended) around using different way to check the I2C bus on AVR and on SAM (Due) .
As I posted before - the beginTransmission / endTransmisson returned random results.
The other one using callback reports ALL addresses , not just active devices, only addresses. Not very useful.
I run both scanners on Due TWI1.
The I2C suppose to return ACK when slave devices successfully connects / receive data and neither one of these scanner codes does that. I am going to look into that callback function in more details soon, it seems to have considerable delay responding, so I assume it does something more than just bounces back.

Cheers Vaclav

Vaclav:
I am not sure why we are getting into this “pull-ups” , the sole purpose of pull- up / pull-down resistor is to keep the (processor) input at known state when there is no device connected to it.

Err, no.
Err, very much no.

An open-collector (drain) output is connected, but it can only pull down, so it has to have a pull-up.

(similar function as USB)

Again, no, because, somewhat perversely, USB is not a bus (certainly not in the electrical sense that I2C is a bus); it a series of point-to-point connections.

Vaclav:
I am not sure why we are getting into this “pull-ups” , the sole purpose of pull- up / pull-down resistor is to keep the (processor) input at known state when there is no device connected to it.

No, that is not the purpose of the pull-up.

Try using I2C with devices connected but no pull-up. It won’t work.

Certainly pull-up/pull-down resistors help keep a pin at a known state, however with I2C they are an integral part of the design. The processor does not drive the pin high, the pull-up does that. All the processor does is drive it low.

selster: Actually the pull resistors for the I2C LCD interface are 10K for both SCL and SDA.

Start getting each device working on its own, when you have that, it is worth considering whether any pull ups need to be removed.