Hello everyone, I am attempting to use a MAX30102 heartbeat and SO2 sensor along with a MLX90614 temperature sensor on a raspberry pi pico. Using the sensors individually, I have no issues, but when I attempt to use both at the same time, I can only get the MAX30102 sensor to work. Doing some research, I think it's due to how MLX90614 sensor uses the wire protocol. I know that I can use Wire and Wire1, which I think would allow me to use both sensors, but I am not sure how to enable this on the pi pico. Any ideas on how I can get both to work?
Here is the code I am using:
#include <Wire.h>
#include "MAX30105.h"
#include <SparkFunMLX90614.h> //Click here to get the library: http://librarymanager/All#Qwiic_IR_Thermometer by SparkFun
#include "heartRate.h"
extern TwoWire Wire1;
MAX30105 particleSensor;
IRTherm therm; // Create an IRTherm object to interact with throughout
const byte RATE_SIZE = 8; //Increase this for more averaging. 4 is good.
byte rates[RATE_SIZE]; //Array of heart rates
byte rateSpot = 0;
long lastBeat = 0; //Time at which the last beat occurred
unsigned long previousMillis = 0;
long interval = 550;
#define numReadings 10
float readings[numReadings];
uint8_t readIndex = 0;
bool fullArray = false;
float readings1[numReadings];
uint8_t readIndex1 = 0;
bool fullArray1 = false;
float beatsPerMinute;
int beatAvg;
void setup()
{
Serial.begin(115200);
Wire.begin();
therm.begin();
therm.setUnit(TEMP_F);
// Initialize Heartrate sensor
particleSensor.begin(Wire, I2C_SPEED_FAST);
particleSensor.setup(); //Configure sensor with default settings
particleSensor.setPulseAmplitudeRed(0x0A); //Turn Red LED to low to indicate sensor is running
particleSensor.setPulseAmplitudeGreen(0); //Turn off Green LED
}
void temp()
{
if (therm.read()) // On success, read() will return 1, on fail 0.
{
if (readIndex == numReadings) {
fullArray = true;
readIndex = 0;
}
readings[readIndex] = therm.object();
readIndex++;
uint8_t total;
if (fullArray) total = numReadings;
else total = readIndex;
float average = 0;
for (uint8_t i = 0; i < total; i++){
average += readings[i];
}
average = average / total;
if (readIndex1 == numReadings) {
fullArray1 = true;
readIndex1 = 0;
}
readings1[readIndex1] = therm.ambient();
readIndex1++;
uint8_t total1;
if (fullArray1) total1 = numReadings;
else total1 = readIndex1;
float average1 = 0;
for (uint8_t i = 0; i < total1; i++){
average1 += readings1[i];
}
average1 = average1 / total1;
Serial.print(average);
Serial.print(",");
Serial.println(average1);
}
}
void loop(){
long irValue = particleSensor.getIR();
if (checkForBeat(irValue) == true)
{
//We sensed a beat!
long delta = millis() - lastBeat;
lastBeat = millis();
beatsPerMinute = 60 / (delta / 1000.0);
if (beatsPerMinute < 255 && beatsPerMinute > 20)
{
rates[rateSpot++] = (byte)beatsPerMinute; //Store this reading in the array
rateSpot %= RATE_SIZE; //Wrap variable
//Take average of readings
beatAvg = 0;
for (byte x = 0 ; x < RATE_SIZE ; x++)
beatAvg += rates[x];
beatAvg /= RATE_SIZE;
}
}
Serial.print("IR=");
Serial.print(irValue);
Serial.print(", BPM=");
Serial.print(beatsPerMinute);
Serial.print(", Avg BPM=");
Serial.print(beatAvg);
delay(1000);
if (irValue < 50000)
Serial.print(" No finger?");
Serial.println();
}
temp();
}