I am trying to get a SparkFun BMP581 sensor to work with an Adafruit TCA9548a multiplexer. The BMP581 works when it is not connected to the TCA. The inverse happens when the they are connected.
Code w/o TCA9548:
#include "SparkFun_BMP581_Arduino_Library.h"
#include <Wire.h>
BMP581 pressureSensor; // Create a new sensor object
uint8_t i2cAddress = BMP581_I2C_ADDRESS_DEFAULT;
void setup() { Wire.begin(); // Start I2C bus delay(500); // wait Serial.begin(115200); // Start Serial connection
Serial.println("BMP581 Begin!");
/* Initialize the sensor */ while(pressureSensor.beginI2C(i2cAddress) != BMP5_OK) { // Not connected --> inform user Serial.println("Error: BMP581 not connected - check wiring and I2C address!");
// Wait
delay(1000);
} Serial.println("BMP581 Connected!"); }
void loop() { // Get measurements from the sensor bmp5_sensor_data data = {0}; int8_t err = pressureSensor.getSensorData(&data);
// Check whether data was acquired successfully if(err == BMP5_OK) { Serial.print("Temperature (C): "); Serial.print(data.temperature);
Serial.print("\nPressure (Pa): ");
Serial.println(data.pressure);
} else{ Serial.print("Error getting data from sensor! Error Code: "); Serial.println(err); } delay(1000); }
Code w/ TCA9548:
#include <Wire.h>
#include "SparkFun_BMP581_Arduino_Library.h"
BMP581 BMP;
#define TCA_Addr 0x70 uint8_t BMP_Addr = BMP581_I2C_ADDRESS_DEFAULT;
void tcaselect(uint8_t i) { if (i > 7) return;
Wire.beginTransmission(TCA_Addr); Wire.write(1 << i); Wire.endTransmission(); }
void setup() { while (!Serial); delay(1000); Wire.begin(); Serial.begin(115200);
tcaselect(5); init_bmp(); }
void loop() { bmp581(); }
void init_bmp() { tcaselect(5); while (BMP.beginI2C(TCA_Addr) != BMP5_OK) { Serial.println("Error: BMP581 not connected - check wiring and I2C address!"); delay(1000); } Serial.println("BMP581 Connected!"); }
void bmp581() { tcaselect(5); bmp5_sensor_data data = {0}; int8_t err = BMP.getSensorData(&data);
if (err == BMP5_OK) { Serial.print("Temperature (C): "); Serial.println(data.temperature);
Serial.print("\nPressure (Pa): ");
Serial.println(data.pressure);
} else { Serial.print("Error getting data from sensor! Error Code: "); Serial.println(err); } delay(1000); }
I don't have Fritzing so please bare with me and my circuit diagram I drew in paint.
Thank you
