带有 PulsesensorPlayground 的 ESP32

ESP32 with PulsesensorPlayground

我是开发 Arduino 的新手,我已经遇到了错误。我已经在互联网上搜索过,但仍然没有运气。

情况是,我有一个带 32 个引脚的 ESP32 开发套件,我有这个来自 pulsesensor.com 的 PulseSensor。我尝试了 PulseSensorPlayground 库中的示例 Getting_BPM_to_Monitor,但遇到了问题。

问题出在 void 设置函数 pulsesensor 不能在这里创建对象。

我的代码:

const int PulseWire = 0;     
const int LED13 = 13;       
int Threshold = 550;

PulseSensorPlayground pulseSensor;

void setup() {

    Serial.begin(9600);
    pulseSensor.analogInput(PulseWire);
    pulseSensor.blinkOnPulse(LED13);
    pulseSensor.setThreshold(Threshold);
    if (pulseSensor.begin()){
        Serial.println("We created a pulseSensor Object !");
    } else 
        Serial.println("Cannot create a pulseSensor Object !"); //this code is added to check if it creates the object
}

我从没用过PulseSensor,所以我不知道它是否支持ESP32。但我认为您的代码是直接从 Arduino 复制并尝试在 ESP32 上 运行 它。

您如何将 PulseSensor 连接到 ESP32?即脉冲传感器连接到 ESP32 的哪个引脚?

在 Arduino 中,您用于 analogRead 的 const int PulseWire = 0; 是有意义的,因为它指的是 A0,但对于 ESP32 Arduino Core,ADC0 位于 GPIO36(参见 ESP32 Arduino Core pinmap,它根本不起作用.

为了将模拟传感器连接到 ESP32 ADC0,您需要将 PulseWire 定义为 36。

const int PulseWire = 36;