LLAMAFTW
LLAMAFTW

Reputation: 3

How to connect using different i2c pins of ESP32 and read data?

I'm using a ESP32 microcontroller, MAX30100 pulse sensor for my project and other sensors that need to use SCL and SDA. So I need to interface this sensor to ESP32's using different i2c pins not the default pins(21,22).

But I don't know how to read data from the MAX30100 if it connected to different pins (33, 32)

This is the code I used for default i2c pins to read data from MAX30100

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

#define I2C_SDA 33
#define I2C_SCL 32
#define REPORTING_PERIOD_MS     1000

PulseOximeter pox;
TwoWire I2CPOX = TwoWire(0);


// Time at which the last beat occurred
uint32_t tsLastReport = 0;


void setup() {
    Serial.begin(115200);
    Serial.print("Initializing pulse oximeter..");
    I2CPOX.begin(I2C_SDA, I2C_SCL, 100000);
    bool status;
    status = pox.begin(0x57, &I2CPOX);
    if (!status) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
        while (1);
        }
         Serial.println("-- Default Test --");
         delayTime = 1000;
         Serial.println();
}

// Callback routine is executed when a pulse is detected
void onBeatDetected() {
    Serial.println("♥ Beat!");
}

void loop() {
    // Read from the sensor
    pox.update();

    // Grab the updated heart rate and SpO2 levels
    if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
        Serial.print("Heart rate:");
        Serial.print(pox.getHeartRate());
        Serial.print("bpm / SpO2:");
        Serial.print(pox.getSpO2());
        Serial.println("%");

        tsLastReport = millis();
    }
} 

How do I interface MAX30100 to other pins? What should be the instructions? Do I need to change the library? How do I change the library if need to?

Upvotes: 0

Views: 1289

Answers (1)

GrooverFromHolland
GrooverFromHolland

Reputation: 1029

Don't put them on separate I2C ports. As long as the modules I2C addresses are different then they will both work from the same single I2C pins on your board.

If there really is a address conflict You can read these instructions https://dronebotworkshop.com/multiple-i2c-bus/

Upvotes: 1

Related Questions