Go Down

Topic: I2C with 3 Sensors (Read 3287 times) previous topic - next topic



I have a problem with 3 sensors on the I2C bus with the Arduino Due.

I have the following sensors together on SCL and SDA (PIN 20 and 21)
* COMPASS (Addr 0x1E // 7-bit HMC5883)
* BMP180 (Addr 0x77).
everything works io.

Now I stick to the
* gyro (Addr 0x07 // L3GD20H)
and everything goes wrong.

Individually it works well.

Does anyone have an idea?


it may be because the function of Gyro 16bit and two others on 7bit. If so, how can I solve this problem?


How long are the cables you are adding and what pullup resistors do you have?
"The problem is in the code you didn't post."


I send you three suggestions: Note the addressing problem documented in the Reference/Wire page.
Divide problem into smaller parts. Separately make each device work correctly with a specific test program for each device. Ensure that each item is wired correctly and works. The Due has SCA and SCA1. two separate ports. The pull-up resistor comment  for SCA1 and SDA1 is apparently voluntary. I am using SCA1 and SDA1 without any pull up resistor .

So after you have all three devices working one-at-a-time then I suggest you go read the detailed description of how SCA SDA works. The four wire ICSP bus is designed with a "slave enable" wire. You can have multiple slave devices provided you enable only one at a time. The problem for SCA SDA is understanding how to select between two devices when two devices are attached to the same pins. The Due has gobs and gobs of speed and a lot of plain old digital pins too. Speaking from personal experience, it doesn't tell you much about what is wrong. Cheers!

Note that if your device has an 8 bit address, you have to adjust the value the Due looks for.

" There are both 7- and 8-bit versions of I2C addresses. 7 bits identify the device, and the eighth bit determines if it's being written to or read from. The Wire library uses 7 bit addresses throughout. If you have a datasheet or sample code that uses 8 bit address, you'll want to drop the low bit (i.e. shift the value one bit to the right), yielding an address between 0 and 127. "

The information that the "Wire" does not explain is how does SCA/SDA work?


Apr 01, 2015, 09:47 am Last Edit: Apr 01, 2015, 09:55 am by wassmann69
thanks for the replies. I do not use "pullup resistors". The cable length is 5 cm max. The problem is, it's enough if I put only one cable to the bus (SDA or SLC) then everything collapses. I'm not for analysis or set. All sensors are working individually and together with the HMC5883 BMP180. I once made a drawing.
The Model is: http://www.exp-tech.de/adafruit-l3gd20-l3g4200-upgrade-triple-axis-gyro-breakout-board
Is in the description: This board/chip uses I2C 7-bit address 0x6B.

The code for the L3GD20H is:
Code: [Select]

#include <Wire.h>
#include <L3G.h>

L3G gyro;

void setup() {

  if (!gyro.init())
    Serial.println("Failed to autodetect gyro type!");
    while (1);


void loop() {

  Serial.print("G ");
  Serial.print("X: ");
  Serial.print(" Y: ");
  Serial.print(" Z: ");


But what really matter, since I do not even get around to it ...


Apr 01, 2015, 10:11 am Last Edit: Apr 01, 2015, 10:16 am by wassmann69
Oh, and I also tested whether the L3GD20 interfere only in combination with one of the other sensors. I get the L3GD20 to run individually.

I have a question: How big should / should pullup resistors for the be? 10K?
All Sensor working with 5V


Where to find some really good description of I2C signal basics.

I found this description about how I2C fits in relation to other communication methods:


And here is an even more specific link to Arduino I2C


Note in above link there is a pointer to "interfacing to multiple devices"

Best wishes that further information will help you get that third device working.


Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


If the 3 sensors are identical and all have the same I2C address, then a I2C mux can be used to  select which device is being accessed:
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


Hi CrossRoads

sorry, but how do they know that all 3 sensors have the same address? I do not believe. Or did I miss something?


The diagram looks correct. Using pins 20 and 21 on a Due will give you pullup resistors.

The address of 0x07 for the gyro looks unusual. The addresses 0 to 7 are reserved by the I2C standard for other purposes. There isn't supposed to be a device at that address. The address range 0b00001xx [includes 4, 5, 6, 7] is  reserved for "high speed mode" and if one of the devices on the bus is capable of high speed mode, it will take over the bus when it sees 0x07 as an address.

Does the bus work if you have the gyro connected, but never call it?
"The problem is in the code you didn't post."


so, I have the problem resolved now. I have the L3GD20H now in spi mode and it works. With the address I understood. So not funktionirt way. I have again an understanding question: I now get values for the 3 axes left up to 20 deg / sec and right around 560. Matters involving this? LG



The data bus only works when the gyro is connected alone. As soon as an additional sensor (no matter which) comes to everything collapses.


hi wassmann69,

I'm trying to get values from HMC5883l with Due, but unable to get correct outcome yet, could you please share your code?


Go Up