I'm working with two MPRLS pressure sensors and a TCA9548A multiplexer, to allow me to read both sensors on the arduino. I found that for one sensor to increase the sample rate, all I had to do was set the EOC_PIN to a GPIO pin and wire it up and cancel the delay in the Adafruit_MPRLS.cpp file. But now I have two sensors and two EOC pins, (one for each sensor). How do I watch both pins in the same loop, and set the TCA9548A to the correct channel any time one of the pins goes high, which I have been told shall, increase the sample rate for both?
This is the attempt I have made at the moment, that doesn't work.
#include <Wire.h>
#include "Adafruit_MPRLS.h"
#define TCAADDR 0x70
#define RESET_PIN -1 // set to any GPIO pin # to hard-reset on begin()
#ifdef EOC_PIN
#define EOC_PIN A3
#else
#define EOC_PIN A4
#endif
Adafruit_MPRLS mpr = Adafruit_MPRLS(RESET_PIN, EOC_PIN);
/* Assign a unique ID to this sensor at the same time */
Adafruit_MPRLS mpr1 = Adafruit_MPRLS(1);
Adafruit_MPRLS mpr2 = Adafruit_MPRLS(2);
unsigned long time;
void tcaselect(uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
void setup()
{
Serial.begin(115200);
/* Initialise the 1st sensor */
tcaselect(2);
if (! mpr1.begin())
{
Serial.println("Failed to communicate with MPRLS sensor 1, check wiring?");
}
/* Initialise the 2nd sensor */
tcaselect(7);
if (! mpr2.begin())
{
Serial.println("Failed to communicate with MPRLS sensor 2, check wiring?");
}
Serial.println("Time (ms) \t Sensor 1 (hPa) \t Sensor 2 (hPa) ");
}
void loop()
{
time = millis();
Serial.print(time);
tcaselect(2);
float pressure_hPa_1 = mpr1.readPressure();
Serial.print("\t");
Serial.print("\t");
Serial.print(pressure_hPa_1);
tcaselect(7);
float pressure_hPa_2 = mpr2.readPressure();
Serial.print("\t");
Serial.print("\t");
Serial.println(pressure_hPa_2);
}