I2C Scan Sanity Check
To verify the I2C addresses, an I2C scan can be used. See the guide linked below for more information on I2C scanning. The guide also has a Arduino I2C scan code example that can be used.
Here is the resulting output seen in the Arduino Serial Monitor:
The BME280 found at address 0x77
is the one directly attached. The 0x37
address is the BME280 located downstream of the LTC4316. These are the two addresses we need for modifying the code. The 0x37
address can be thought of as an alternate address for the BME280. In that manner, the code usage is the same as the Two Devices using Alternate Address approach shown previously. The only difference is the actual address.
// SPDX-FileCopyrightText: 2024 Carter Nelson for Adafruit Industries // // SPDX-License-Identifier: MIT #include <Adafruit_BME280.h> // For each device, create a separate instance. Adafruit_BME280 bme1; // BME280 #1 @ 0x77 Adafruit_BME280 bme2; // BME280 #2 @ 0x37 void setup() { Serial.begin(9600); while(!Serial); Serial.println(F("Two BME280 Example")); // NOTE: There's no need to manually call Wire.begin(). // The BME280 library does that in its begin() method. // In the call to begin, pass in the I2C address. // If left out, the default address is used. // But also OK to just be explicit and specify. bme1.begin(0x77); // address = 0x77 (default) bme2.begin(0x37); // address = 0x37 (behind LTC4316) } void loop() { float pressure1, pressure2; // Read each device separately pressure1 = bme1.readPressure(); pressure2 = bme2.readPressure(); Serial.println("------------------------------------"); Serial.print("BME280 #1 Pressure = "); Serial.println(pressure1); Serial.print("BME280 #2 Pressure = "); Serial.println(pressure2); delay(1000); }
Here's the output:
Note how for each device, there is a separate instance created:
Adafruit_BME280 bme1; // BME280 #1 @ 0x77 Adafruit_BME280 bme2; // BME280 #2 @ 0x37
And then for each, the begin()
function is called and the address is specified:
bme1.begin(0x77); // address = 0x77 (default) bme2.begin(0x37); // address = 0x37 (behind TCA4316)
Here we intentionally specify the default 0x77
address just to be explicit. And 0x37
is the address for the BME280 behind the TCA4316.
Once that is taken care of, the two instances can be used to directly read the sensor values:
pressure1 = bme1.readPressure(); pressure2 = bme2.readPressure();
Page last edited January 22, 2025
Text editor powered by tinymce.