I2C protocol sensors

I am building a rig that will have two identical sensors wired in parallel to the SDA, SCL, 3.3v, and GND pins of the board. Each sensor includes a thermocouple and digital pressure transducer. Since I've never worked with sensors on arduino I don't know how to set up the code to make the controller and sensors talk to each other. Any advice would be much appreciated

Here is a link to the arduino library supplied by the manufacturer

https://github.com/bluerobotics/BlueRobotics_MS5837_Library

And here is the corresponding data sheet for the sensor

http://www.te.com/commerce/DocumentDelivery/DDEController?Action=srchrtrv&DocNm=MS5837-02BA01&DocType=Data+Sheet&DocLang=English&DocFormat=pdf&PartCntxt=CAT-BLPS0059

Those sensors only have one fixed I2C address, so you can't connect two of them to one bus.

An I2C multiplexer is a possible solution. Leo..

moonshineraider:
I am building a rig that will have two identical sensors wired in parallel to the SDA, SCL, 3.3v, and GND pins of the board. Each sensor includes a thermocouple and digital pressure transducer. Since I've never worked with sensors on arduino I don't know how to set up the code to make the controller and sensors talk to each other. Any advice would be much appreciated

You may proceed this way (untested)--
1. Connect the Arduino UNO, Adafruit TCA9548A 1-to-8 I2C Multiplexer Breakout (Allows Voltage-Level Translation Between 1.8-V,2.5-V, 3.3-V, and 5-V Buses: double check it; otherwise, things might be fired!), and 2xMS5837 Sensor Breakout( with internal 5/3.3V Regulator perhaps:double check it; otherwise, things might be fried!) as per following diagram. Please, report how it goes.
ptsensor.png
Figure-1: Connection diagram among UNO, I2C Multiplexer, and 2xMS5837 Sensor

2. Include this Library in your IDE.

3. Upload the following example (taken from IDE Example and modified: untested)

#include <Wire.h>
#include "MS5837.h"

MS5837 sensor;
byte busStatus;

void setup() {

  Serial.begin(9600);

  Serial.println("Starting");

  Wire.begin();
  while (!sensor.init())
  {
    Serial.println("Init failed!");
    Serial.println("Are SDA/SCL connected correctly?");
    Serial.println("Blue Robotics Bar30: White=SDA, Green=SCL");
    Serial.println("\n\n\n");
    delay(5000);
  }

  sensor.setModel(MS5837::MS5837_30BA);
  sensor.setFluidDensity(997); // kg/m^3 (freshwater, 1029 for seawater)

  Wire.beginTransmission(0x70); //address for I2C Expander; we can cascade 8 expanders
  Wire.write(0x06); //selecting bottom sensor of Fig-1; Sensor address 0x76 already keyed in Library
  busStatus = Wire.endTransmission();
  if(busStatus != 0x00)
  {
     Serial.println("I2C Expnader is not found....!");
     while(1); //wait for ever
  }
  Serial.println("I2C Expander is found....!");

}

void loop()
{

  // Update pressure and temperature readings
  sensor.read();

  Serial.print("Pressure: ");
  Serial.print(sensor.pressure());
  Serial.println(" mbar");

  Serial.print("Temperature: ");
  Serial.print(sensor.temperature());
  Serial.println(" deg C");

  Serial.print("Depth: ");
  Serial.print(sensor.depth());
  Serial.println(" m");

  Serial.print("Altitude: ");
  Serial.print(sensor.altitude());
  Serial.println(" m above mean sea level");

  delay(1000);
}

4. Bring the Serial Monitor at 9600 Bd.

5. Check that the Serial Monitor shows reasonable value for Temp, Press, and etc.

BTW: I don't have the sensor and I2C expanded to test your project.

ptsensor.png

BlueRobotics_MS5837_Library-master.zip (8.29 KB)

I wired the components according to the schematic you drew, as shown in the attached image. I tested using the 3.3v power supply pin from the control board.

After a sensor was connected to each of the boards wired to the buses, I ran the code you included in your reply and the serial monitor displayed a message that initialization failed. (screenshot included)

The same error message shows up whether the sensors are plugged into the red connector boards or not. Data and clock cables are verified to be connected properly, as each sensor will return meaningful data if it is connected independently without the multiplex.

FailedInit.PNG

The codes of Post#2 are slightly modified based on the information of the following table of the Control Resister of the multiplexer. Please, upload the following codes and observe the result. I am not sure about the terminating logic of the RST (Reset) pin of the multiplexer; so, try connecting LH or LL at this pin.


Figure-1: Table showing the active states of the multiplexer channels

#include <Wire.h>
#include "MS5837.h"

MS5837 sensor;
byte busStatus;

void setup() {

  Serial.begin(9600);
  Wire.begin();

  Serial.println("Starting");

  Wire.beginTransmission(0x70); //address for I2C Expander; we can cascade 8 expanders
  Wire.write(0x40); //selecting bottom sensor of Fig-1 at SL6, SD6; sensor address 0x76 keyed in Library
  busStatus = Wire.endTransmission();
  if(busStatus != 0x00)
  {
     Serial.println("I2C Expnader is not found....!");
     while(1); //wait for ever
  }
  Serial.println("I2C Expander is found....!");
 
  while (!sensor.init())
  {
    Serial.println("Init failed!");
    Serial.println("Are SDA/SCL connected correctly?");
    Serial.println("Blue Robotics Bar30: White=SDA, Green=SCL");
    Serial.println("\n\n\n");
    delay(5000);
  }

  sensor.setModel(MS5837::MS5837_30BA);
  sensor.setFluidDensity(997); // kg/m^3 (freshwater, 1029 for seawater)

  
}

void loop()
{

  // Update pressure and temperature readings
  sensor.read();

  Serial.print("Pressure: ");
  Serial.print(sensor.pressure());
  Serial.println(" mbar");

  Serial.print("Temperature: ");
  Serial.print(sensor.temperature());
  Serial.println(" deg C");

  Serial.print("Depth: ");
  Serial.print(sensor.depth());
  Serial.println(" m");

  Serial.print("Altitude: ");
  Serial.print(sensor.altitude());
  Serial.println(" m above mean sea level");

  delay(1000);
}

I tried the revised code from post 4, and got a message that the multiplex board is found, but it still fails to initialize. Multiple attempts were made using different pin addresses since my sensors are connected to buses 3 and 7. Every instance displays the same result (see “MultiplexTest.PNG”).

I also used the code below pulled from Adafruit’s examples to see what would happen, and the serial monitor only displayed one line with empty characters (see “ScannerCodeOutput”).

/**
 * TCA9548 I2CScanner.pde -- I2C bus scanner for Arduino
 *
 * Based on code c. 2009, Tod E. Kurt, http://todbot.com/blog/
 *
 */

#include "Wire.h"
extern "C" { 
#include "utility/twi.h"  // from Wire library, so we can do bus scanning
}

#define TCAADDR 0x70

void tcaselect(uint8_t i) {
  if (i > 7) return;
 
  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission();  
}


// standard Arduino setup()
void setup()
{
    while (!Serial);
    delay(1000);

    Wire.begin();
    
    Serial.begin(115200);
    Serial.println("\nTCAScanner ready!");
    
    for (uint8_t t=0; t<8; t++) {
      tcaselect(t);
      Serial.print("TCA Port #"); Serial.println(t);

      for (uint8_t addr = 0; addr<=127; addr++) {
        if (addr == TCAADDR) continue;
      
        uint8_t data;
        if (! twi_writeTo(addr, &data, 0, 1, 1)) {
           Serial.print("Found I2C 0x");  Serial.println(addr,HEX);
        }
      }
    }
    Serial.println("\ndone");
}

void loop() 
{
}

Is there a chance that the multiplex requires passive resistors in the circuit? The schematic from Adafruit shows what looks like resistors in series with certain pins on the board, but I don’t know if those resistors are already on the board or not.

The scanner does output data, it’s just that your terminal baud rate is at 9600 and the program is at 115200. Fix it on either end.

The multiplexer has pull-down resistors on the address lines so you do not need to jump A0-2 to ground, they’re already pulled low.

The problem appears to be some really bad code. Give this sample a try. It is the basic demo program with the multiplexer initialization in the correct location reading from channel 3 on the multiplexer since I see you have the sensors on channels 3 and 7.

Let’s see if this works, if so, then test the other sensor by changing line 55 to “tcaSelect(7);” and give it a go. Once both sensors are working, we can adapt the program to read both. I want to make as small changes as possible since I cannot test, do not have the parts.

/* Blue Robotics MS5837 Library Example
-----------------------------------------------------
 
Title: Blue Robotics MS5837 Library Example
Description: This example demonstrates the MS5837 Library with a connected
sensor. The example reads the sensor and prints the resulting values
to the serial terminal.
The code is designed for the Arduino Uno board and can be compiled and 
uploaded via the Arduino 1.0+ software.
-------------------------------
The MIT License (MIT)
Copyright (c) 2015 Blue Robotics Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-------------------------------*/

#include <Wire.h>
#include "MS5837.h"

#define TCAADDR 0x70
 
void tcaSelect(uint8_t i) {
  if (i > 7) return;
 
  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission();  
}

MS5837 sensor;

void setup() {
  
  Serial.begin(9600);
  Serial.println("Starting");
  Wire.begin();

  // Initialize pressure sensor
  // Returns true if initialization was successful
  // We can't continue with the rest of the program unless we can initialize the sensor

  tcaSelect(3); // using sensor in channel 3 of TCA9548
  
  while (!sensor.init()) {
    Serial.println("Init failed!");
    Serial.println("Are SDA/SCL connected correctly?");
    Serial.println("Blue Robotics Bar30: White=SDA, Green=SCL");
    Serial.println("\n\n\n");
    delay(5000);
  }
  
  sensor.setModel(MS5837::MS5837_30BA);
  sensor.setFluidDensity(997); // kg/m^3 (freshwater, 1029 for seawater)
}

void loop() {
  // Update pressure and temperature readings
  sensor.read();

  Serial.print("Pressure: "); 
  Serial.print(sensor.pressure()); 
  Serial.println(" mbar");
  
  Serial.print("Temperature: "); 
  Serial.print(sensor.temperature()); 
  Serial.println(" deg C");
  
  Serial.print("Depth: "); 
  Serial.print(sensor.depth()); 
  Serial.println(" m");
  
  Serial.print("Altitude: "); 
  Serial.print(sensor.altitude()); 
  Serial.println(" m above mean sea level");

  delay(1000);
}

The code in post #4 reliably returns data for all 8 buses on the multiplex. For the addition of the second sensor, I assume I have to name the second sensor (like in line 16) and define what bus it is on? Will it be as straightforward as copying the block that initializes the single sensor or is there more to it?

moonshineraider: The code in post #4 reliably returns data for all 8 buses on the multiplex. For the addition of the second sensor, I assume I have to name the second sensor (like in line 16) and define what bus it is on? Will it be as straightforward as copying the block that initializes the single sensor or is there more to it?

Straight forward the similar codes except that the channel of the second sensor has to be changed to (SD7, SC6) using these codes as per Fig-1 of Post#4.

Wire.beginTransmission(0x70); //address for I2C Expander; we can cascade 8 expanders
  Wire.write(0x80); //selecting Top sensor of Fig-1 of Post#2 at SD7, SC6; sensor address 0x76 keyed in Library
  busStatus = Wire.endTransmission();

BTW: What logic level (5V or 0V or nothing) have you connected with RST-pin of the I2C multiplexer?

Since the code provided earlier was able to run a single sensor properly on whatever bus I selected (using command tcaselect() with argument 0-7 to specify the bus) I opted to re-arrange the wiring as shown in Fig. 1. If the camera angle doesn't clearly show, the green wires are connected to SDA and SCL, and the RST through A2 pins are all open (0V). The red breakout boards are connected to buses 1 and 2, and each has been verified with a single sensor to output consistent data. Figure 2 shows the code I used for a single sensor (commands for lcd screen can be ignored, that device is working properly and I'm quite familiar with it.)

Note on nomenclature: This setup intends to place one (waterproofed) sensor at the bottom of a volume of liquid and on at the surface, hence the names sensorTop and sensorBottom.


Figure 1.

#include <Wire.h>  // Built in Arduino library for I2C protocol devices
#include "MS5837.h" // Library from Blue Robotics for the specific sensor being used
#include <LiquidCrystal.h> // Library for LCD display

#define TCAADDR 0x70 // defines the fixed address of multiplex board
LiquidCrystal lcd(8, 9, 10, 11, 12, 13); // Assign pins for LCD

void tcaSelect(uint8_t i) {
  if (i > 7) return;
 
  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission();  
}

// Name the connected sensors (only sensorBottom is called in this code)
MS5837 sensorBottom;
MS5837 sensorTop;

void setup() {
  // Set up LCD display (16 chars long and 2 high)
  lcd.begin(16, 2);
  lcd.clear();
  // Set up serial monitor
  Serial.begin(9600);
  Serial.println("Starting");
  // I2C command to start data transfer to devices
  Wire.begin();

  // Initialize pressure sensor
  // Returns true if initialization was successful
  // We can't continue with the rest of the program unless we can initialize the sensor
  tcaSelect(2); // Selecting which bus of TCA9548 board to use
  
  while (!sensorBottom.init()) {
    Serial.println("Init failed!");
    Serial.println("Are SDA/SCL connected correctly?");
    Serial.println("Blue Robotics Bar02: White=SDA, Green=SCL");
    Serial.println("\n\n\n");
    delay(5000);
  }
  
  sensorBottom.setModel(MS5837::MS5837_02BA); // from Blue Robotics library, tells which model the board is talking to
  sensorBottom.setFluidDensity(997); // kg/m^3 (freshwater, 1029 for seawater)
}
// Request various data using commands from Blue Robotics library and print in monitor
void loop() {
 
  sensorBottom.read();  // Update pressure and temperature readings with I2C command
  
  // Display depth on LCD
  lcd.setCursor(0,0);
  lcd.print("Water Height:");
  lcd.setCursor(0,1);
  lcd.print(sensorBottom.depth());
  lcd.setCursor(10,1);
  lcd.print("meters");
  
  Serial.print("Pressure: "); 
  Serial.print(sensorBottom.pressure()); 
  Serial.println(" mbar");
  
  Serial.print("Temperature: "); 
  Serial.print(sensorBottom.temperature()); 
  Serial.println(" deg C");
  
  Serial.print("Depth: "); 
  Serial.print(sensorBottom.depth()); 
  Serial.println(" m");
  
  Serial.print("Altitude: "); 
  Serial.print(sensorBottom.altitude()); 
  Serial.println(" m above mean sea level");
  Serial.println();

  delay(1000); // Display new set of data every second
}

Figure 2. Code for a single sensor (bus 2)

I gave it a try assigning a second sensor (sensorTop) to a separate bus, the code for which is in figure 3. Here I should state that if I swap the two sensors on the same plug, same bus, their pressure readings are slightly different, but within and acceptable error range. Figures 4 and 5 show each sensor's output.

#include <Wire.h>  // Built in Arduino library for I2C protocol devices
#include "MS5837.h" // Library from Blue Robotics for the specific sensor being used
#include <LiquidCrystal.h> // Library for LCD display

#define TCAADDR 0x70 // defines the fixed address of multiplex board
LiquidCrystal lcd(8, 9, 10, 11, 12, 13); // Assign pins for LCD

 // I think this block is detecting the multiplex board and making sure it talks back
void tcaSelect(uint8_t i) {
  if (i > 7) return;
 
  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission();  
}

// Name the connected sensor
MS5837 sensorBottom;
MS5837 sensorTop;

void setup() {
  // Set up LCD display (16 chars long and 2 high)
  lcd.begin(16, 2);
  lcd.clear();
  // Set up serial monitor
  Serial.begin(9600);
  Serial.println("Starting");
  // I2C command to start data transfer to devices
  Wire.begin();

  // Initialize pressure sensor
  // Returns true if initialization was successful
  // We can't continue with the rest of the program unless we can initialize the sensor

  tcaSelect(1); // using sensor on bus 1 of TCA9548
  
  while (!sensorBottom.init()) {
    Serial.println("Init failed!");
    Serial.println("Are SDA/SCL connected correctly?");
    Serial.println("Blue Robotics Bar02: White=SDA, Green=SCL");
    Serial.println("\n\n\n");
    delay(5000);
  }

  tcaSelect(2); // using sensor on bus 2 of TCA9548
  
  while (!sensorTop.init()) {
    Serial.println("Init failed!");
    Serial.println("Are SDA/SCL connected correctly?");
    Serial.println("Blue Robotics Bar02: White=SDA, Green=SCL");
    Serial.println("\n\n\n");
    delay(5000);
  }
  
  sensorBottom.setModel(MS5837::MS5837_02BA); // from Blue Robotics library, tells which model the board is talking to
  sensorBottom.setFluidDensity(997); // kg/m^3 (freshwater, 1029 for seawater)
  sensorTop.setModel(MS5837::MS5837_02BA); // from Blue Robotics library, tells which model the board is talking to
  sensorTop.setFluidDensity(997); // kg/m^3 (freshwater, 1029 for seawater)
}
// Request various data using commands from Blue Robotics library and print in monitor
void loop() {
 
  sensorBottom.read();  // Update pressure and temperature readings with I2C command
  sensorTop.read();
  
  // Display depth on LCD
  lcd.setCursor(0,0);
  lcd.print("Water Height:");
  lcd.setCursor(0,1);
  lcd.print(sensorBottom.depth());
  lcd.setCursor(10,1);
  lcd.print("meters");
  
  // Display data for bottom sensor
  Serial.print("Bottom Pressure: "); 
  Serial.print(sensorBottom.pressure()); 
  Serial.println(" mbar");
  
  Serial.print("Bottom Temperature: "); 
  Serial.print(sensorBottom.temperature()); 
  Serial.println(" deg C");
  // Display data for top sensor
  Serial.print("Top Pressure: "); 
  Serial.print(sensorTop.pressure()); 
  Serial.println(" mbar");
  
  Serial.print("Top Temperature: "); 
  Serial.print(sensorTop.temperature()); 
  Serial.println(" deg C");
  Serial.println();
  
//  Serial.print("Depth: "); 
//  Serial.print(sensorBottom.depth()); 
//  Serial.println(" m");
//  
//  Serial.print("Altitude: "); 
//  Serial.print(sensorBottom.altitude()); 
//  Serial.println(" m above mean sea level");

  delay(5000); // Display new set of data every second
}

Figure 3. Code for 2 sensor setup

Bottom sensor output.PNG
Figure 4. Bottom sensor only output (bus 1)

Top sensor output.PNG
Figure 5. Top sensor only output (bus 1)

The issue comes when I run both sensors. The output for one sensor will be consistent with the output for the single setup, and the other with have a large deviation from what it outputs independently. Figure 6 shows the output when the bottom sensor is on bus 1 and the top sensor is on bus 2. The top sensor is showing the correct pressure, but the bottom sensor is off by a large margin. (They are both sitting next to each other on the workbench in open air) If I leave the sensors plugged into the same ports, but switch the tcaselect() arguments 1 and 2 on lines 35 and 45, the bottom sensor's error changes as shown in figure 7.

Two sensor output.PNG
Figure 6. Bottom sensor on bus 1, and top sensor on bus 2

Two sensor output switched.PNG
Figure 7. Sensors plugged into same buses but with tcaselect() arguments switched

At this point, I'm fairly certain that I'm missing something in the code to properly differentiate the signals from the sensors. Not sure how to properly implement though.

Screenshots attached since images are not showing up in body of post. Wiring setup image failed security protocols when attempting to attach

Bottom sensor output.PNG

Top sensor output.PNG

Two sensor output.PNG

Two sensor output switched.PNG

You can place the images on line by following these tips:

1. After attaching the image file, save the post.

2. Right Click on the attached file name and copy the link address.

3. Open the post in modify mode.

4. Place the cursor where you want to place the image.

5. Click on the Insert an image icon of the Tools bar. A window will appear and place the cursor in the input box. Press button cntrl+V on the keyboard. The link will appear in the input box. Click on OK button of the window. Save the post. Check that the image has appeared online.

Thanks for the tips, post has been modified

You got 99% of it, karma given for good work. You just missed the initializers before each object use. I added channel declares for better readability and please note that I can only say this compiles, I cannot test. But, based on your comments, it should work and if not, I expect by now you’ll be able to sort it out yourself.

If the mux initialization calls gets messy, you could either create some wrapper functions that call the standard library with a channel number or modify the library to add the multiplexer and invoke the objects with the channel number. Personally, I’d go with the wrapper option for several reasons in addition to it being the easiest to implement in the land of Arduino libraries.

#include <Wire.h>  // Built in Arduino library for I2C protocol devices
#include "MS5837.h" // Library from Blue Robotics for the specific sensor being used
#include <LiquidCrystal.h> // Library for LCD display

#define TCAADDR 0x70 // defines the fixed address of multiplex board

#define adrBottom 1
#define adrTop 2

LiquidCrystal lcd(8, 9, 10, 11, 12, 13); // Assign pins for LCD

 // I think this block is detecting the multiplex board and making sure it talks back
void tcaSelect(uint8_t i) {
  if (i > 7) return;
 
  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission();  
}

// Name the connected sensor
MS5837 sensorBottom;
MS5837 sensorTop;

void setup() {
  // Set up LCD display (16 chars long and 2 high)
  lcd.begin(16, 2);
  lcd.clear();
  // Set up serial monitor
  Serial.begin(9600);
  Serial.println("Starting");
  // I2C command to start data transfer to devices
  Wire.begin();

  // Initialize pressure sensor
  // Returns true if initialization was successful
  // We can't continue with the rest of the program unless we can initialize the sensor

  tcaSelect(adrBottom); // using sensor on bus 1 of TCA9548
  
  while (!sensorBottom.init()) {
    Serial.println("Init failed!");
    Serial.println("Are SDA/SCL connected correctly?");
    Serial.println("Blue Robotics Bar02: White=SDA, Green=SCL");
    Serial.println("\n\n\n");
    delay(5000);
  }

  tcaSelect(adrTop); // using sensor on bus 2 of TCA9548
  
  while (!sensorTop.init()) {
    Serial.println("Init failed!");
    Serial.println("Are SDA/SCL connected correctly?");
    Serial.println("Blue Robotics Bar02: White=SDA, Green=SCL");
    Serial.println("\n\n\n");
    delay(5000);
  }
  
  sensorBottom.setModel(MS5837::MS5837_02BA); // from Blue Robotics library, tells which model the board is talking to
  sensorBottom.setFluidDensity(997); // kg/m^3 (freshwater, 1029 for seawater)

  sensorTop.setModel(MS5837::MS5837_02BA); // from Blue Robotics library, tells which model the board is talking to
  sensorTop.setFluidDensity(997); // kg/m^3 (freshwater, 1029 for seawater)
}

// Request various data using commands from Blue Robotics library and print in monitor
void loop() {
 
  tcaSelect(adrBottom); // using sensor on bus 1 of TCA9548
  sensorBottom.read();  // Update pressure and temperature readings with I2C command

  tcaSelect(adrTop); // using sensor on bus 2 of TCA9548
  sensorTop.read();
  
  // Display depth on LCD
  lcd.setCursor(0,0);
  lcd.print("Water Height:");
  lcd.setCursor(0,1);
  lcd.print(sensorBottom.depth());
  lcd.setCursor(10,1);
  lcd.print("meters");
  
  // Display data for bottom sensor
  Serial.print("Bottom Pressure: "); 
  Serial.print(sensorBottom.pressure()); 
  Serial.println(" mbar");
  
  Serial.print("Bottom Temperature: "); 
  Serial.print(sensorBottom.temperature()); 
  Serial.println(" deg C");
  // Display data for top sensor
  Serial.print("Top Pressure: "); 
  Serial.print(sensorTop.pressure()); 
  Serial.println(" mbar");
  
  Serial.print("Top Temperature: "); 
  Serial.print(sensorTop.temperature()); 
  Serial.println(" deg C");
  Serial.println();
  
//  Serial.print("Depth: "); 
//  Serial.print(sensorBottom.depth()); 
//  Serial.println(" m");
//  
//  Serial.print("Altitude: "); 
//  Serial.print(sensorBottom.altitude()); 
//  Serial.println(" m above mean sea level");

  delay(5000); // Display new set of data every second
}

The code in post #12 worked well the first time I ran it, but I didn't take a screenshot and I can't reproduce it exactly. I tried to run the rig on battery and the display gave an incorrect value, so I put it back on USB to check the serial monitor and found that the top sensor is sending the correct pressure value, but the bottom sensor only sends the correct pressure value on the first iteration of the loop output, but not for any subsequent iterations (Fig. 1). Curiously both sensors are sending correct temperature data.

Is this behavior indicative of a messy initialization call that you were talking about?

Two sensor oddity.PNG
Figure 1. Correct pressure in first line, but not for any following loops. Temperature data is correct for all loops.

Both sensors have been verified to output consistent data with single sensor setup.

Two sensor oddity.PNG

Hi

I have the same problem.
With the TCA9548
the 1st MS5837 does not work. The 2nd is OK
If I reverse the 2 MS5837 , it’s always the first one that does not work. The 2nd always still.
I tried to put delay but … nothing to change

Has anyone found a solution?