如何将MAX30100脉冲传感器连接到ESP32的不同i2c引脚并读取数据?



我的项目使用ESP32 30引脚板,MAX30100脉冲传感器。我可以将此传感器连接到ESP32的不同i2c引脚,即不是默认引脚(21,22)。

但是我不知道如何从MAX30100读取数据,如果它连接到不同的引脚-(假设32,33)

这是我用于默认i2c引脚从MAX30100读取数据的程序

#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#define BLYNK_PRINT Serial
#include <Blynk.h>
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#define REPORTING_PERIOD_MS 1000
char auth[] = "*******************";             // You should get Auth Token in the Blynk App.
// Connections : SCL PIN - D1 , SDA PIN - D2 , INT PIN - D0
PulseOximeter pox;
float BPM, SpO2;
uint32_t tsLastReport = 0;

void onBeatDetected()
{
Serial.println("Beat Detected!");
}
void setup()
{
Serial.begin(115200);
pinMode(19, OUTPUT);
Blynk.begin(auth,"************", "**********");
Serial.print("Initializing Pulse Oximeter..");
if (!pox.begin()) {
Serial.println("FAILED");
for(;;);
}     
else
{
Serial.println("SUCCESS");
pox.setOnBeatDetectedCallback(onBeatDetected);
}
// The default current for the IR LED is 50mA and it could be changed by uncommenting the following line.
pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
}
void loop()
{
pox.update();
Blynk.run();
BPM = pox.getHeartRate();
SpO2 = pox.getSpO2();
if (millis() - tsLastReport > REPORTING_PERIOD_MS)
{
Serial.print("Heart rate:");
Serial.print(BPM);
Serial.print(" bpm / SpO2:");
Serial.print(SpO2);
Serial.println(" %");
Blynk.virtualWrite(V3, BPM);
Blynk.virtualWrite(V4, SpO2);
tsLastReport = millis();
}
}

如何将MAX30100连接到其他引脚?说明应该是什么?

PulseOximeter pox;

这个指令是什么意思?

你应该在库中改变方向:

链接到github中的库文件

第29行:修改

Wire.begin(SDA_PIN, SCL_PIN);

其中SDA_PIN和SCL_PIN是你自己的路由定义。

注意:如果你改变了库,你将需要在所有的开发中始终使用该引脚,所以如果你在本地导入该库可能会更好,或者如果你改变了库,如果你不传递任何引脚at参数,它默认是I2C引脚,但是,如果定义了,使用定义的引脚。