I2C Multiplexing and apology

Active 3 months ago
Viewed 372 times

I have a Raspberry Pi 3B+ and I bought two BME280 sensors (specifically these) and I would like to connect them via I2C. I read that you can do software multiplexing but all the information I am finding is incomplete, makes assumptions, or people are commenting that it doesn’t work. Can anyone please let me know what I need to do? For the record, I’ve already hooked up one of them and am getting the readings correctly, but I need both of them connected.

  • Quick comment. Rpi4B has 4 I2C channels. Does it help? There is another I2C switcher which can handle more than one I2C device with same address. – tlfong01 Sep 25 ’19 at 13:13
  • @tlfong01, I have the 3B+, and have no background on electronics. I would love to be told what to connect to which GPIOs and what commands to run to get it working, if at all possible, unless I’m asking for too much… – Mark Cilia Vincenti Sep 25 ’19 at 13:19
  • Hi @Mark Cilia Vincenti, but only Rpi4B have more than one I2C bus. Perhaps you can try Lady Ada’s goody: Adafruit TCA9548A 1-to-8 I2C Multiplexer Breakout learn.adafruit.com/…. AdaFruit’s tutorial is usually newbie friendly. – tlfong01 Sep 25 ’19 at 13:28  
  • 1
    Yes, AdaFruit’s hardware is almost always open source. Actually I never buy anything from her. But I am grateful to her (and SparkFun) , so I always recommend AdaFruit. AliExpress is usually OK, though I always buy from TaoBao which is even cheaper than AliExpress but also OK. – tlfong01 Sep 25 ’19 at 13:39


In general, every I2C device has its own address, and one can connect many devices to the same port e.g. of the PI. Individual communication is possible via those addresses. (This is something you set in your program code)

Now, it should be clear that this only works if each device has its own, unique address on the port. If you buy a hand full of those sensors, each has the same address, and hence, you can not connect them to the same I2C port on the PI.

As written in the comments, you can

  • use two I2C ports – if you have two ports
  • use an I2C multiplexer, which is kind of a relay allowing to switch between devices.

But there is a build-in solution. The address of I2C devices is often hard coded, sometimes completely configurable, and sometimes, the last one or two bits can be configured.

If you read the datasheet of the BME280 sensor, the pin SDO defines lowest bit of the Adress. By default, it is connected to GND, resulting in address 76. When connected to 3.3V, the address is 77. This allows to connect two BME280 sensors to the same I2C port of the PI at the same time, and to communicate with each via its unique address.

The link you provide shows the schematic of the PCB, which contains a switch S1 for exactly this:

enter image description here

There is no physical switch on the PCB, instead, there is a solder jumper consisting of the three pads in a row next to the sensor:

enter image description here

The center pad is connected to the SDO pin of the sensor, the upper left to GND, and the lower right to 3.3V.

By default, the center pad should be connected to the upper left pad, but you need it to be connected to the lower right one instead! (But only for ONE of your two sensors). This simply needs a soldering iron and a little solder.

Now, there should be a blob of solder connecting the center and upper left pad, similar as on the left side on this picture:

enter image description here

I do not see this blob on the picture of your PCB, may be, your real PCBs have them, maybe, not.

If not, the two pads are for sure connected by a thin copper track, as on the right side in the image from me above. If this is the case, this thin copper track must be removed with a sharp knife. I don’t see such track on the photo of your PCB. It might be covered with the violet paint, so you should carefully check it.

(FYI: The reason for the small copper track is that the blob needs lots of solder, while industrial soldering processes use very little solder. So, such blobs need to be placed by hand. To avoid this, that small copper tracks are used, so the few people which ever want to modify something here, would need to cut that track, first.)

As you uploaded a high resolution image of the PCB:

enter image description here

It is exactly what I wrote. There is a track between the central and the left pad, covered with violet solder mask.

  1. Remove the track between the pads with a sharp knife.
  2. Connect central pad with right pad with some solder.
  3. Attach the sensor to the PI, and run sudo i2cdetect -y 1.
    This will scan for I2C devices and display the addresses of the found ones in a table.
  4. Do the same for the unmodified sensor. Its address should differ by one from the other address.
  5. Attach both sensors. That is: Pin 1 of both together to the correct pin of the PI, pin 2 of both together to the correct pin, and so on…
  6. Run the command again. It should now find both devices!

That’s all from the hardware side. Your software will still talk to the unmodified sensor. Alter the address by 1 in the software to communicate with the other.


  • Thanks for your lengthy answer. Unfortunately, I don’t understand the majority of what you said and I need to do some research to understand what you mean. I’ll do that later. Yesterday, I already ordered the TCA9548A, but if I can do without it it means I can finish the project earlier. Unfortunately, I still cannot understand what I need to connect to what. – Mark Cilia Vincenti Sep 26 ’19 at 9:47
  • 2
    @MarkCiliaVincenti: I have added some pictures and simplifed the answer. – sweber Sep 26 ’19 at 10:43
  • @MarkCiliaVincenti Great! See the last section of my answer! – sweber Sep 26 ’19 at 12:11
  • This is a brilliant answer, @sweber. I’ll test it out and if it works you deserve some bounty as well. – Mark Cilia Vincenti Sep 26 ’19 at 12:16
  • I did steps 1 and 2 for now. Could you kindly rephrase step 5? Do you mean I strip off the ribbon cable and connect the ribbon cable of the other sensor in parallel, such that both sensors share the same GPIO pins? – Mark Cilia Vincenti Sep 27 ’19 at 15:29
  • 1
    Yes, the pins of the two sensors share the same pins of the Pi! That’s exactly what this all is about. You don’t address different devices by different electrical connections, you do it by software and the data over the lines. – sweber Sep 27 ’19 at 16:52
  • IT WORKS!!!! Thanks so much! – Mark Cilia Vincenti Sep 27 ’19 at 17:58
  • I will be able to award you with a bounty in 24 hours time. – Mark Cilia Vincenti Sep 27 ’19 at 17:59
  • 1
    @Mark Cilia Vincenti, I am glad that sweber gives you the correct answer. The two answers of using two I2C channels and TCA9548A are careless, and wasting your money. My apologies. sweber’s suggestion of using the one hardware address bits is very common among I2C devices. I have been using it many many times. I am ashamed that I made such a silly mistake of forgetting it and not recommended it to you. If there is a punishment scheme, I should be deducted at least 50 reputation points. Or another way of thanking sweber perhaps is to search his other good answers and upvote them. 🙂 – tlfong01 Sep 29 ’19 at 5:20
  • 1
    Maybe you want to buy a TCA9548A, @tlfong01? 😛 No worries mate 🙂 – Mark Cilia Vincenti Sep 30 ’19 at 9:28
  • @Mark Cilia Vincenti, Ha, thank you. Actually I have more than 10 TCAs in my junk box. BTW, I may tell you why I feel guilty. When I was studying engineering, I was told that one day if I become an engineer, I cannot OVERSELL any product or service by taking advantage of my knowledge that other don’t know. Later I taught in a community college with many poor students who could not afford expensive toys. I used to send newsletters to over 500 students of a course, telling them what components they should buy to save money, /to continue, … – tlfong01 Sep 30 ’19 at 9:41
  • 1
    @tlfong01 mate it was just 4 euros including shipping 🙂 and had it arrived already I would still have preferred to use that option because I had to ask someone else to modify the sensor because my soldering skills are probably bested by my pet dog. – Mark Cilia Vincenti Sep 30 ’19 at 9:46
  • Now If I told them to buy the stupid TCA but in fact they can just use a hobby knife to make a cut, :(. You see, is it not just about saving money, it is about careless misconduct. And you may find my profile saying I am a hobbyist programmer, instead of telling them that I was once an “professional” engineer, misleading them to trust me more than they should, … In short, my careless mistake is not just damaging my own reputation or credit, but also the engineering society I registered, and my employer, … – tlfong01 Sep 30 ’19 at 9:48
  • 1
    Well, one more thing, before I answered you question, I read that you mentioned “multiplexing” and they don’t work, so I wrongly thought that you must be ninja level, and did research before asking. But now I know you are just another friendly newbie: 🙂 – tlfong01 Sep 30 ’19 at 9:52

Categories: Uncategorized

%d bloggers like this: