![](/img/trans.png)
[英]How to connect MAX30100 pulse sensor to a different i2c pins of ESP32 and read data?
[英]How to connect using different i2c pins of ESP32 and read data?
我正在为我的项目使用 ESP32 微控制器、MAX30100 脉冲传感器以及其他需要使用 SCL 和 SDA 的传感器。 所以我需要使用不同的 i2c 引脚而不是默认引脚(21,22)将此传感器连接到 ESP32。
但我不知道如何从 MAX30100 读取数据,如果它连接到不同的引脚 (33, 32)
这是我用于默认 i2c 引脚以从 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();
}
}
如何将 MAX30100 连接到其他引脚? 指令应该是什么? 我需要更换图书馆吗? 如果需要,如何更改库?
不要将它们放在单独的 I2C 端口上。 只要模块的 I2C 地址不同,那么它们都可以通过板上相同的单个 I2C 引脚工作。
如果确实存在地址冲突您可以阅读这些说明https://dronebotworkshop.com/multiple-i2c-bus/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.