Example for outputting two SPI sensors (Adafruit BME280)

Hello:

I got two Adafruit BME280 sensors and I want to compare if they are able to get similar/identical readings in the same environment.

Here is my SPI wiring on a Photon:

BME280 #1:
Vin -----> VIN
GND -----> GND
SCK -----> A3
SDO -----> A4
SDI -----> A5
CS -----> A2

BME280 #2:
Vin -----> VIN
GND -----> GND
SCK -----> D4
SDO -----> D3
SDI -----> D2
CS -----> D5

Am I doing this wiring correctly?
Can you please provide an example how to print out their readings?

Thanks a lot.

Actually you can have both sensors share the CLK, MISO, MOSI lines, only the CS lines need to be seperated and be active mutually exclusive.

Are you using the Adafruit or the SparkFun library?
Either way, there are demo applications with the libraries that should give you an idea how to use the libs.

Thanks. I will take a look on Adafruit library.

The code is a little complicated. I can define two specific CS pins, but I do not know which sensor is generating the output.

It’s not that difficult

You’ll have two seperate objects

Adafruit_BME280 bme1(BME1_CS); // hardware SPI
Adafruit_BME280 bme2(BME2_CS); // hardware SPI

void loop()
{
    Serial.print("Sensor 1: Temperature = ");
    Serial.print(bme1.readTemperature());
    Serial.println(" *C");

    Serial.print("Sensor 2: Temperature = ");
    Serial.print(bme2.readTemperature());
    Serial.println(" *C");
}

Thanks a lot. I learned. One more question: I see It has different SPI library for Photon. Can these Adafruit code work for Photon?

If a library is hosted on Particle Build (Web IDE) then it should be running on the Particle devices - that’s the whole point of having a dedicated library repository.

You might need to look into the docs
https://docs.particle.io/guide/getting-started/build/photon/
Particularly
https://docs.particle.io/guide/getting-started/build/photon/#using-libraries

Sometimes libraries need porting, sometimes you might just need to alter the pins used in the demos.