using 4 of the same I2C/SPI sensors (BME280) on one board

i want to use four BME280 sensors on my ESP8266-12F board, but i think they only have two available addresses, so i can only use two? not four

should i use the softI2C library? which example do i use? they seem to be specific to things i have never heard of!

the breakout boards i got have SCL SDA VIN and GND - does this mean i can't use SPI - even though it is SPI capable device?

also i read in another post on here that I2C wiring can’t be very long - is there a limit? can i run a BME280 sensor on 10m of cable?

or is using a I2C multiplexer a better option??

Please give a link to your ESP8266 module.

This is the best option : TCA9548A I2C Multiplexer : ID 2717 : $6.95 : Adafruit Industries, Unique & fun DIY electronics and kits

For an Arduino Uno, there is also a SoftwareWire library (in the Library Manager). After creating the object, it is compatible with the Wire library. So you can take the library from Adafruit, copy it in your project, replace the Wire with myWire (or a define WIRE) and it should work. The SoftwareWire is not yet a finished mature project.

The total cable length (every piece of wire added together) is maximum 50cm. Some can do 2 meters, other say they can do 8 meters (ignore that).
The I2C bus was not designed to be used with a cable at all. There are special chips that convert the I2C into a signal for twisted wire cable.

Step one: The distance. Do you really need 10 meters distance ? Do you want to use special chips ? or a slow RS-232 or a fast RS-485 ? Perhaps wireless ? What about two ESP8266 modules ?

Step two: How to connect all the sensors, that depends on step one.

The BME280 has a LOT of addresses. Read the datasheet. However, when I tested one, I could not get it to work on all of those addresses like the datasheet says.

10m is definitely too long for I2C unless you use bus-extender chips.

MorganS, I didn't know that, so I read the datasheet. I can read that it can be two I2C addresses, no more.
According to the datasheet : "The 6 MSB bits are fixed. The last bit is changeable by
SDO value and can be changed during operation".

Koepel:
Please give a link to your ESP8266 module.

http://www.electrodragon.com/product/esp-12f-esp8266-wifi-board/

i also have ESP8266-01, ESP8266-12E or Arduino Mega

This is the best option : TCA9548A I2C Multiplexer : ID 2717 : $6.95 : Adafruit Industries, Unique & fun DIY electronics and kits

this is the one i have:

I2C but not SPI

For an Arduino Uno, there is also a SoftwareWire library (in the Library Manager). After creating the object, it is compatible with the Wire library. So you can take the library from Adafruit, copy it in your project, replace the Wire with myWire (or a define WIRE) and it should work. The SoftwareWire is not yet a finished mature project.

sounds good! but you say for only Uno?

The total cable length (every piece of wire added together) is maximum 50cm. Some can do 2 meters, other say they can do 8 meters (ignore that).
The I2C bus was not designed to be used with a cable at all. There are special chips that convert the I2C into a signal for twisted wire cable.

well, damn. :frowning:

that ruins the whole concept of my project! i may have to use DHT22's instead... (i am currently USING DHT22's but the accuracy advertised by the BME280 is much better and the DHTs need one GPIO each.)

Step one: The distance. Do you really need 10 meters distance ? Do you want to use special chips ? or a slow RS-232 or a fast RS-485 ? Perhaps wireless ? What about two ESP8266 modules ?

yeah, i COULD use four or five ESP8266's (i have this many already for other projectgs)

Step two: How to connect all the sensors, that depends on step one.

i guess wirelessly?

but since i am using www.blynk.cc to contol this, i have to inspect if Blynk can 100% accomodate that many ESP8266 nodes... (from what i understand, it should...)

MorganS:
The BME280 has a LOT of addresses. Read the datasheet. However, when I tested one, I could not get it to work on all of those addresses like the datasheet says.

nah.

it only has two.

#define BME280_I2C_ADDRESS1                  (0x76)
#define BME280_I2C_ADDRESS2                  (0x77)

maybe we are talking about different sensors?

10m is definitely too long for I2C unless you use bus-extender chips.

yeah, my DHT22’s are very happy on 10m and 15m Cat5 cables… i didn’t consider that BME280 needed to be right next to the processor to work… my bad :frowning:

You're right. I misremembered the BME280 because I tested it at the same time as another I2C chip that has a lot of addresses.

In BME280_MOD-1022.h
Comment:
//#define addrBME280 0x76
and add:
extern int addrBME280;

In your sketch use
int addrBME280=0x76; // or 0x77;
you can change it during execution

I guess, that differences in the calibration parameters are not significant.
If not, you could make recalibration at each addressing to particular sensor.

Also you can powerup each couple of BME280(one 0x76, another 0x77) via separate ESP8266 pin. So, you'll have several branches which can be switched alternatively.

Koepel:
Please give a link to your ESP8266 module.

This is the best option : TCA9548A I2C Multiplexer : ID 2717 : $6.95 : Adafruit Industries, Unique & fun DIY electronics and kits

For an Arduino Uno, there is also a SoftwareWire library (in the Library Manager). After creating the object, it is compatible with the Wire library. So you can take the library from Adafruit, copy it in your project, replace the Wire with myWire (or a define WIRE) and it should work. The SoftwareWire is not yet a finished mature project.

The total cable length (every piece of wire added together) is maximum 50cm. Some can do 2 meters, other say they can do 8 meters (ignore that).
The I2C bus was not designed to be used with a cable at all. There are special chips that convert the I2C into a signal for twisted wire cable.

Step one: The distance. Do you really need 10 meters distance ? Do you want to use special chips ? or a slow RS-232 or a fast RS-485 ? Perhaps wireless ? What about two ESP8266 modules ?

Step two: How to connect all the sensors, that depends on step one.

long time no post, but i finally got around to needing two BME280's on one set of I2C pins and I have got it running with the Cactus library.

BUT i am running two BME280 on a 13 meter of CAT5e cable with on a Arduino Mega board.

seems fine!

why did you say it is 50cm max cable length?

year old post...
as with any digital signal, there is timing between pulses in the signal.
I have read of people going much further with slower timing.

if you needed say 35 meters, or even 75 meters, you would need to take some extraordinary steps.

but, once you get into those ranges, the cost of a simple wifi makes using wireless more attractive.

http://tronixstuff.com/2014/04/13/add-long-distance-connectivity-arduino-catkit-system/

I was mostly posting for people who search BME280 and find this thread and might need to know that what koepel said about I2C cable length doesn't seem to be entirely accurate...

and as i have done , experiment for your scenario and see what works...

Hi Wareemba,

I have the same sensors you have and trying to wire them both in I2C;

I tested one with cactus library and it works, but I don't know how can I manage to have two of them wired on the same I2C pins (Arduino UNO).

Since my goal is to get two sets of different inputs from the sensors (temperature,humidity and pressure from two different rooms), how do I manage to create two BME280 library objects in the code, with two different addresses?

Could you show me how did you solve it?

Many thanks.

hey mate,

these are my BME280 related lines of code:

#include "cactus_io_BME280_I2C.h"

BME280_I2C BME280Sensor01(0x77);
float BME280Sensor01Pres;
float BME280Sensor01Hum;
float BME280Sensor01Temp;
float BME280Sensor01DewPoint;

BME280_I2C BME280Sensor02(0x76);
float BME280Sensor02Pres;
float BME280Sensor02Hum;
float BME280Sensor02Temp;
float BME280Sensor02DewPoint;

void setup()
 {
 if (!BME280Sensor01.begin()) 
{
    Serial.println("Could not find a First BME280 sensor, check wiring!");
    while (1);
  }

  if (!BME280Sensor02.begin()) 
{
    Serial.println("Could not find a Second BME280 sensor, check wiring!");
    while (1);
  }
}

void runBMESensors()
{
  BME280Sensor01.readSensor();
  BME280Sensor01Pres = BME280Sensor01.getPressure_MB();
  BME280Sensor01Hum = BME280Sensor01.getHumidity();
  BME280Sensor01Temp = BME280Sensor01.getTemperature_C();
  BME280Sensor01DewPoint = dewPoint(BME280Sensor01Temp, BME280Sensor01Hum);

  Blynk.virtualWrite(V49, BME280Sensor01Pres);
  Blynk.virtualWrite(V33, BME280Sensor01Hum);
  Blynk.virtualWrite(V29, BME280Sensor01Temp);
  Blynk.virtualWrite(V47, BME280Sensor01DewPoint);

  if (debug) {
    Serial.print("BME 1\t");
    Serial.print(BME280Sensor01Pres); Serial.print("\t\t");    // Pressure in millibars
    Serial.print(BME280Sensor01Hum); Serial.print("\t\t");
    Serial.print(BME280Sensor01Temp); Serial.println(" *C\t");
    Serial.print(BME280Sensor01DewPoint); Serial.println(" *C\t");
  }

  BME280Sensor02.readSensor();
  BME280Sensor02Pres = BME280Sensor02.getPressure_MB();
  BME280Sensor02Hum = BME280Sensor02.getHumidity();
  BME280Sensor02Temp = BME280Sensor02.getTemperature_C();
  BME280Sensor02DewPoint = dewPoint(BME280Sensor02Temp, BME280Sensor02Hum);

  Blynk.virtualWrite(V72, BME280Sensor02Pres);
  Blynk.virtualWrite(V59, BME280Sensor02Hum);
  Blynk.virtualWrite(V53, BME280Sensor02Temp);
  Blynk.virtualWrite(V71, BME280Sensor02DewPoint);

  if (debug) {
    Serial.print("BME 2\t");
    Serial.print(BME280Sensor02Pres); Serial.print("\t\t");    // Pressure in millibars
    Serial.print(BME280Sensor02Hum); Serial.print("\t\t");
    Serial.print(BME280Sensor02Temp); Serial.println(" *C\t");
    Serial.print(BME280Sensor02DewPoint); Serial.println(" *C\t");
  }
}

hope that gives you enough ideas to sort it out :slight_smile: