Using multiple MicroPressure sensors with a multiplexer

I am trying to use 4 SparkFun Micropressure sensors with an Adafruit TCA9548A but am having problems with both errors and not knowing how to hook them up correctly. (I'm using the library for Adafruit's equivalent MPRLS sensor.)

Here is my code:

void TCA9548A(uint8_t bus) {    //Setup for Adafruit Multiplexer
  Wire.beginTransmission(0x70);
  Wire.write(1<< bus);
  Wire.endTransmission;
}


void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Wire.begin();

  TCA9548(1);
  boolean Adafruit_MPRLS1::begin;

Here is the error I'm getting:

Arduino: 1.8.15 (Windows 10), TD: 1.54, Board: "Teensy 4.1, Serial, 600 MHz, Faster, US English"


Final_I2C: In function 'void TCA9548A(uint8_t)':

Final_I2C:14: error: statement cannot resolve address of overloaded function

   Wire.endTransmission;

                       ^

Final_I2C: In function 'void setup()':

Final_I2C:23: error: 'TCA9548' was not declared in this scope

   TCA9548(1);

            ^

Final_I2C:24: error: 'Adafruit_MPRLS1' has not been declared

   boolean Adafruit_MPRLS1::begin;

           ^

Final_I2C:24: error: qualified-id in declaration before ';' token

   boolean Adafruit_MPRLS1::begin;

                                 ^

statement cannot resolve address of overloaded function



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

How about
Wire.endTransmission();

How about

boolean Adafruit_MPRLS1::begin();

Need to see the rest of the code to help with that.

You mean "here is a tiny snippet of my code". See here.
Post all the code. Use the IDE auto format tool before posting code.

Sorry for not sending all the code, here is the entire thing:

#define SysValve 1
#define DistValve 2
#define MidValve 3
#define ProxValve 4

#define Address 0x70 //Setup to connect to the Sparkfun MicroPressure sensors
#include <Wire.h>
#include <Adafruit_MPRLS.h>
Adafruit_MPRLS mpr = Adafruit_MPRLS(-1, -1);

void TCA9548A(uint8_t bus) {    //Setup for Adafruit Multiplexer
  Wire.beginTransmission(0x70);
  Wire.write(1 << bus);
  Wire.endTransmission();
}


void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Wire.begin();

  TCA9548(1);
  boolean Adafruit_MPRLS1::begin();

  pinMode(SysValve, OUTPUT);  //Setting the output pins to the valves:
  pinMode(DistValve, OUTPUT);
  pinMode(MidValve, OUTPUT);
  pinMode(ProxValve, OUTPUT);

  pinMode(A0, INPUT); //Setting which pin to read from
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  pinMode(A3, INPUT);

}

void loop() {
  float SysPSI = analogRead(A1); //Input from sensors:

  float DistPSI = analogRead(A1);

  float MidPSI = analogRead(A1);

  float ProxPSI = analogRead(A1);

  Serial.print("System Pressure: ");    //Show pressure of each chamber:
  Serial.println(SysPSI);
  Serial.print("Distal Chamber Pressure: ");
  Serial.println(DistPSI);
  Serial.print("Middle Chamber Pressure: ");
  Serial.println(MidPSI);
  Serial.print("Proximal Chamber Pressure: ");
  Serial.println(ProxPSI);

  if (SysPSI == 14.7) { //Open secondary valves if system is at atmospheric pressure:
    while (DistPSI == 14.7 && MidPSI == 14.7 && ProxPSI == 14.7) {
      digitalWrite(DistValve, HIGH);
      digitalWrite(MidValve, HIGH);
      digitalWrite(ProxValve, HIGH);
    }
  }
  if (SysPSI < 44.7 && SysPSI > 14.7) {
    if ( (DistPSI == 14.7 && MidPSI == 14.7 && ProxPSI == 14.7) || (DistPSI < SysPSI && MidPSI < SysPSI && ProxPSI < SysPSI)) {
      while (DistPSI != SysPSI && MidPSI != SysPSI && ProxPSI != SysPSI) {
        digitalWrite(SysValve, HIGH);   //If system pressure is between the max PSI and atmospheric pressure while the secondary pressure is < system pressure open the 1st valve:
      }
    }
  };
  if (DistPSI > SysPSI) {   // :
    while (DistPSI != SysPSI) {
      digitalWrite(DistValve, HIGH);
    }
    while (MidPSI != SysPSI) {
      digitalWrite(MidValve, HIGH);
    }
    while (ProxPSI != SysPSI) {
      digitalWrite(ProxValve, HIGH);
    }
  }
  digitalWrite(SysValve, LOW);
  digitalWrite(DistValve, LOW);
  digitalWrite(MidValve, LOW);
  digitalWrite(ProxValve, LOW);
}

I'm still getting some errors from the code:

Arduino: 1.8.15 (Windows 10), TD: 1.54, Board: "Teensy 4.1, Serial, 600 MHz, Faster, US English"


Final_I2C: In function 'void setup()':

Final_I2C:23: error: 'TCA9548' was not declared in this scope

   TCA9548(1);

            ^

Final_I2C:24: error: 'Adafruit_MPRLS1' has not been declared

   boolean Adafruit_MPRLS1::begin();

           ^

Final_I2C:24: error: qualified-id in declaration before '(' token

   boolean Adafruit_MPRLS1::begin();

                                 ^

'TCA9548' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Thank you your help, sorry again for not sending the entire thing, this is the first time I've asked for help with code/errors.

The compiler knows a function with "TCA9548A", but not "TCA9548" (the A is missing).

Adafruit library for the HoneyWell MicroPressure MPR sensors: https://github.com/adafruit/Adafruit_MPRLS.
If you look at the example, then it uses: mpr.begin()
I suggest to use that example.

It is not possible to compare a floating point number with 14.7 or 44.7
If the floating point number would be 14.7000001, then it is not 14.7

What type of number would I need to use to be able to compare the number with 14.7?

You can not compare it with 14.7, because it might be a little more or a little less.

You could do this:

if( SysPSI > 12.0 && SysPSI < 17.4)
{
  ...
}

The analogRead() function does not return a floating point number with the psi. You have to calculate the psi if that sensor has a analog output. But the Sparfun MicroPressure Sensors do not have a analog output.
See the example how to get the pressure with: "mpr.readPressure();"

I've updated the code with what you've said:

#define SysValve 1
#define DistValve 2
#define MidValve 3
#define ProxValve 4

#define Address 0x70 //Setup to connect to the Sparkfun MicroPressure sensors
#include <Wire.h>
#include <Adafruit_MPRLS.h>
Adafruit_MPRLS mpr = Adafruit_MPRLS(-1, -1);

void TCA9548A(uint8_t bus) {    //Setup for Adafruit Multiplexer
  Wire.beginTransmission(0x70);
  Wire.write(1 << bus);
  Wire.endTransmission();
}


void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Wire.begin();
  mpr.begin();

  TCA9548A(1);
  boolean Adafruit_MPRLS1::begin();

  pinMode(SysValve, OUTPUT);  //Setting the output pins to the valves:
  pinMode(DistValve, OUTPUT);
  pinMode(MidValve, OUTPUT);
  pinMode(ProxValve, OUTPUT);

  pinMode(A0, INPUT); //Setting which pin to read from
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  pinMode(A3, INPUT);

}

void loop() {
  float SysPSI = mpr.readPressure(); //Input from sensors:

  float DistPSI = mpr.readPressure();

  float MidPSI = mpr.readPressure();

  float ProxPSI = mpr.readPressure();

  Serial.print("System Pressure: ");    //Show pressure of each chamber:
  Serial.println(SysPSI);
  Serial.print("Distal Chamber Pressure: ");
  Serial.println(DistPSI);
  Serial.print("Middle Chamber Pressure: ");
  Serial.println(MidPSI);
  Serial.print("Proximal Chamber Pressure: ");
  Serial.println(ProxPSI);

  if (SysPSI == 14.7) { //Open secondary valves if system is at atmospheric pressure:
    while (DistPSI == 14.7 && MidPSI == 14.7 && ProxPSI == 14.7) {
      digitalWrite(DistValve, HIGH);
      digitalWrite(MidValve, HIGH);
      digitalWrite(ProxValve, HIGH);
    }
  }
  if ((SysPSI < 48 && SysPSI > 40) && (SysPSI > 12.0 && SysPSI < 17.4)) {
    if ( (DistPSI == 14.7 && MidPSI == 14.7 && ProxPSI == 14.7) || (DistPSI < SysPSI && MidPSI < SysPSI && ProxPSI < SysPSI)) {
      while (DistPSI != SysPSI && MidPSI != SysPSI && ProxPSI != SysPSI) {
        digitalWrite(SysValve, HIGH);   //If system pressure is between the max PSI and atmospheric pressure while the secondary pressure is < system pressure open the 1st valve:
      }
    }
  };
  if (DistPSI > SysPSI) {   // :
    while (DistPSI != SysPSI) {
      digitalWrite(DistValve, HIGH);
    }
    while (MidPSI != SysPSI) {
      digitalWrite(MidValve, HIGH);
    }
    while (ProxPSI != SysPSI) {
      digitalWrite(ProxValve, HIGH);
    }
  }
  digitalWrite(SysValve, LOW);
  digitalWrite(DistValve, LOW);
  digitalWrite(MidValve, LOW);
  digitalWrite(ProxValve, LOW);
}

I'm still getting a few errors though:

Arduino: 1.8.15 (Windows 10), TD: 1.54, Board: "Teensy 4.1, Serial, 600 MHz, Faster, US English"


Final_I2C: In function 'void setup()':

Final_I2C:25: error: 'Adafruit_MPRLS1' has not been declared

   boolean Adafruit_MPRLS1::begin();

           ^

Final_I2C:25: error: qualified-id in declaration before '(' token

   boolean Adafruit_MPRLS1::begin();

                                 ^

'Adafruit_MPRLS1' has not been declared



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Have you seen the example ?
Did you see this in the example :

boolean Adafruit_MPRLS1::begin();

I don't. I also don't know where it is coming from or why that is in the sketch.

The compiler can tell what a problem is, but you have to understand what the compiler is trying to tell. That line gives two compiler error that something is not declared. The compiler is saying: "Huh, what is this".

1 Like

I was trying to set up the multiplexer before and during the setup, I fixed it, now it compiles without any errors, I need to test it though.

The compiler can detect only certain types of errors. You have more errors to fix.

For example:

  float SysPSI = mpr.readPressure(); //Input from sensors:

  float DistPSI = mpr.readPressure();

  float MidPSI = mpr.readPressure();

  float ProxPSI = mpr.readPressure();

This code will read the same sensor 4 times and get 4 readings which are the same or almost the same. It will assign those 4 similar readings to 4 variables which were meant to hold readings from 4 different sensors.

I need to add the function to change the bus on the multiplexer before each of the readings. Thank you for the reminder.