use multiple i2c sensors - bmp180, adafruit 9dof...running into errors

I’m using bmp180 barometric pressure sensor and the adafruit RTC . Everything works fine. then I try to use the 9d0f https://www.adafruit.com/products/1714 but all of a sudden as soon as i initiate 9dof sensor and Assign a unique ID to the sensors based on the sample code called “ahrs” , my code won’t even complete the setup loop.

I’ve run into this problem before where I think adding i2c sensors is interfering, but not sure if it’s their addresses interfering or what, or how to assign different addresses to each device if that is indeed what’s the problem

#include "RTClib.h"//real time clock
#include <SFE_BMP180.h> //barometer
//libraries for 9dof imu https://learn.adafruit.com/adafruit-9-dof-imu-breakout
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_9DOF.h>

//initiate 9dof , Assign a unique ID to the sensors 
Adafruit_9DOF                 dof   = Adafruit_9DOF();
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);
Adafruit_LSM303_Mag_Unified   mag   = Adafruit_LSM303_Mag_Unified(30302);

Is there something I have to do when using multiple I2C sensors with different ID’s to make sure their ID doesn’t interfere? I know I should be able to use multiple i2C sensors but I’ve had the exact same problem when using some i2c OLED screens and trying to integrate them to my system, where as soon as I initialize the OLED objects the code won’t even complete the setup loop, same thing I described here.

thanks

Begin at the beginning: Which Arduino board are you using ? Can you tell which RTC and which BMP180 module you are using ? Are are all the modules compatible with a 5V I2C bus ? Do you know the I2C address of every sensor ? Can you make a list of that ? Running the i2c_scanner can be helpful with that : http://playground.arduino.cc/Main/I2cScanner Can you tell for every module if there is a pullup resistor on that module ? What is the combined pullup for the SDA and SCL ?

I'm sorry for the many questions, but you should make a list and see if you can connect it all to the same I2C bus. My best guess is that you have 3.3V modules connected to a 5V I2C bus.

Thanks for this - Every component is working correctly. I'm using the adafruit RTC https://www.adafruit.com/products/264, the sparkfun bmp180 https://www.sparkfun.com/products/11824. All these are indeed compatible wtih the 5V i2c bus.

I'm also using the microsd data logging shield https://www.sparkfun.com/products/9802, a humidity sensor https://www.sparkfun.com/products/9569, but these i do not think have anything to do with my error.

ALL the sensors work flawlessly until I try to integrate the code for the Adafruit 9DOF with the rest of the code for all the other stuff. The code won't make it through setup as soon as i add these lines:

Adafruit_9DOF                 dof   = Adafruit_9DOF();
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);
Adafruit_LSM303_Mag_Unified   mag   = Adafruit_LSM303_Mag_Unified(30302);

The address scanner I will try - all of the sensors work correctly , and even when hooked up and running sample code for the 9DOF it works fine. But when I try to combine the code for the adafruit 9dof with the RTC and the BMP

Thanks i'll try the address scanner because that part is what i dont understand about. Like I said, it seems like as soon as i integrate the sample 9dof code (see above) it doesnt work so i think it's a i2c or software issue not a hardware issue.

Thanks for your answer, we have to make a long list what all the components are using…

Which Arduino board are you using ? It really matters for the I2C bus and for the available amount of memory.

If you have a problem when compiling it, can you show the error messages ? You can even make a screendump of it. The first error message is the most important.

That doesn’t mean that the hardware can be ignored. It should be right.
To be honest, I don’t care if every sensor works on its own. When a 3.3V sensor works, and you add a I2C 5V modules (with onboard pullup resistors), the I2C bus is pulled to 5V and the 3.3V sensor could get damaged.

This is a start, I hope you can fill in the rest. I have colored the dangerous parts:

  • Arduino board : Uno

  • Adafruit RTC
    http://www.adafruit.com/products/264
    The DS1307 is for a 5V I2C bus, and it used I2C address 0x68.
    Pullup resistors are 2k2, which is too low combined with others.
    Library: ?

  • Sparkfun BMP180
    http://www.sparkfun.com/products/11824
    It is a 3.3V module, not compatible with 5V I2C bus, with I2C address 0x77.
    There are 4k7 pullup resistors to 3.3V, they can be disabled by removing solder blob.
    Library: Sparkfun library causes runtime problems during setup, Adafruit library is okay.

  • Sparkfun SD shield
    http://www.sparkfun.com/products/9802
    This has been make compatible with 5V with a level shifter for the SPI bus.

  • Sparkfun humidity sensor HIH-4030
    http://www.sparkfun.com/products/9569
    Works at 5V and has an analog output.

  • Adafruit 9DOF
    http://www.adafruit.com/products/1714
    It has level shifters and can be used with 5V and 3.3V.
    It used two 10k pullup for SDA and two 10k for SCL. That is 5k pullup.
    L3DG20, I2C address : 0x6B (not sure)
    LSM303DLHC, I2C address : 0x19 and 0x1E (not sure)
    Library: Adafruit library.

EDIT: list updated

Thanks again -

Thanks again for help so thoroughly. it is very helpful.

The unfilled out parts: I am using Arduino UNO. and I am using Adafruit RTC lib: https://github.com/adafruit/RTClib

I am indeed using the BMP180 on the 3.3V Bus, but the RTC on a 5V bus and the 9DOF on a 5V bus.

With the Sparkfun library https://learn.sparkfun.com/tutorials/bmp180-barometric-pressure-sensor-hookup-/installing-the-arduino-library i am running into the error. I CAN compile and upload fine, but the program won't go through setup (i know this because i debug by printing at the end of setup "done with setup" . When I open the serial monitor , nothing prints (even though lots of things are supposed to) : either nothing but new lines being printed, OR just a few 1 and 0 and gibberish numbers. If I comment out those three lines to initialize the Adafruit 9DOF objects, the code runs fine.

When I am using adafruits bmp library it all works https://github.com/adafruit/Adafruit_BMP085_Unified INSTEAD of the sparkfun BMP180 library , my code does work ok , which I got from looking at the 10dof (which basically includes my 9dof board from adafruit + the bmp180) (adafruit 10dof : https://learn.adafruit.com/adafruit-10-dof-imu-breakout-lsm303-l3gd20-bmp180/software) .

But still i think I'm running into a weird error because i dont understand something related to I2C. i can upload my code if that would help but i'm using pretty much the sample code from each library / component to get the basic readings (barometric pressure, humidity, etc).

That 10DOF at Adafruit is like your 9DOF + BMP180. I already noticed that.

In my opinion, Adafruit maintains the code better than Sparkfun. So just use the Adafruit code for the BMP180 :P

I did check the Sparkfun code for the BMP180 and I can already see a mistake at the first glance. When reading data over I2C, they wait in a loop until something is available in the buffer, but the Wire library doesn't work that way. After the Wire.requestFrom() the I2C session has already ended, and waiting is wrong.

Your SDA and SCL signals are pulled to 5V when the I2C bus is idle, because of the many pullup resistors. So I call the I2C a "5V I2C bus". When you power the BMP180 with 3.3V, the SDA and SCL will still damage the BMP180, because they pulled elsewhere to 5V. This is important. I don't care if it works, the BMP180 will be damaged and possibly make the I2C bus work less good. Please do not connect the BMP180 to the 5V I2C bus anymore.

You need a level shifter for the BMP180. Or buy a BMP180 with level shifter included : http://www.adafruit.com/products/1603

You main issues are now: - Possibly running out of memory with so many sensors and libraries. - Too many pullup resistors for the I2C bus (a total of 1.1k). I think you are on the edge of a working and non-working I2C bus. - The BMP180 may not be connected to a 5V I2C bus.

ok thanks so much that was really helfpul. I switched out my sensor for the adafruit one, I had researched about that the i2c on a 5V data sda/scl line and thought it was ok without a level shifter... but from now on i will use a level shifter unless there is a built in one if i have dif. voltages in my data lines.

I still however am getting the issue. I'm wondering if it is a memory issue now. because it's the same thing. everything works, then when i add in one more line: Adafruit_LSM303_Mag_Unified mag = Adafruit_LSM303_Mag_Unified(30302); setup won't finish, and the arduino constantly resets itself. I'm thinking that this is a memory problem? And I'm running out of memory? my sketch is only 23K of the 32K allowed (Binary sketch size: 22,912 bytes (of a 32,256 byte maximum) ) but I guess maybe this might help explain: https://learn.adafruit.com/memories-of-an-arduino

i done know but I can try moving to a mega.

also you mentioned i might have a damaged i2c bus - would that be on my Arduino or on the sensor?

Thank you so much again.

The 5V would first damage the BMP180.

The sketch size is okay, but the variables in ram might be too much. The Arduino Uno has only 2k of sram. http://arduino.cc/en/Main/arduinoBoardUno

There are two things you can try: You can try to add this to your sketch : http://playground.arduino.cc/code/AvailableMemory Or try the new Arduino IDE 1.5.7 BETA. Just unzip it in a folder and set your projects folder in the settings. Let your project compile and it will give the ram usage (without allocated memory, without stack usage). When you use more than 75%, I start looking troublesome :~ The Arduino IDE 1.5.7 BETA is able to use extra compiler options, like this super-shrink-option : http://forum.arduino.cc/index.php?topic=262231.0

Perhaps someday you would like to add a nice OLED display, so moving towards an Arduino Mega 2560 is a good idea. Also buy a I2C level shifter to create 5V and 3.3V I2C busses.