Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.0 kB
3
Indexable
Never
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085.h>
#include <TCA9548A.h>

TCA9548A mux;
Adafruit_BMP085 bmp[5];

void setup() {
  Wire.begin();
  Serial.begin(9600);

  // Initialize the I2C multiplexer
  mux.begin();
  
  // Connect each BMP180 sensor to the multiplexer channels
  for (int i = 1; i < 2; i++) {
    mux.openChannel(i); // Enable the channel
    if (!bmp[i].begin()) {
      Serial.println(i);
      Serial.println("Could not find a valid BMP180 sensor, check wiring!");
      while (1);
    }
  }
}

void loop() {
  for (int i = 1; i < 2; i++) {
    mux.openChannel(i); // Switch to the desired channel
    Serial.print("Sensor ");
    Serial.print(i + 1);
    Serial.print(": ");
    Serial.print("Temperature = ");
    Serial.print(bmp[i].readTemperature());
    Serial.print(" *C, Pressure = ");
    Serial.print(bmp[i].readPressure() / 100.0F);
    Serial.println(" hPa");
    delay(1000); // Delay between sensor readings
  }
}
Leave a Comment