esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 36 forks source link

Strange behavior A0 pin on ESP8266 E-paper board #3427

Closed Triko42 closed 1 year ago

Triko42 commented 2 years ago

The problem

Hello, I usually use normal ESP8266 nodemcu v2, but ones time I decided to build something with e-paper display. I bought new board ESP8266 e-paper https://www.waveshare.com/w/upload/a/a7/E-Paper_ESP8266_Driver_Board_EN.pdf. Unfortunately I noticed one issue and I have no idea what's going on. I have to use pulse sensor Heart_Rate_Sensor_SKU__SEN0203, so rebuilt the default arduino code to compatibility with ESPHome.

#include "esphome.h"
#include "DFRobot_Heartrate.h"

class PulseSensor : public PollingComponent, public Sensor {
 public:

  int rateValue;

  PulseSensor() : PollingComponent(20) {}
  DFRobot_Heartrate* heartsensor;

  void setup() override {
    Serial.begin(115200);
    heartsensor = new DFRobot_Heartrate(1);
    publish_state(-1);
  }

  void update() override {
    heartsensor->getValue(A0); 
    pulse_value = rateValue;
    rateValue = heartsensor->getRate();

      if(rateValue) {
         publish_state(rateValue);

         ESP_LOGI("main", "Pulse sensor value: %d",rateValue);
       }
    }    
};

ESPHome:

esphome:
  name: pulse-test
  platform: ESP8266
  board: nodemcuv2
  includes:
    - PulseSensor/PulseSensor.h
  libraries:
    - "dfrobot/DFRobot_Heartrate@^1.0.0"

logger:

wifi:
  ssid: "###"
  password: "###"

web_server:
  port: 12345

sensor:
- platform: custom
  lambda: |-
    auto pulse_sensor = new PulseSensor();
    App.register_component(pulse_sensor);
    return {pulse_sensor};

  sensors:
  - name: "Pulse Sensor"
    id: pulse_sensor
    unit_of_measurement: "bpm"

The code works, but when I install the code on ESP8266 e-paper, the pulse value from sensor is not read correctly or not at all. On the sensor read light blink chaotically, should evenly. I thought the board is broken, but I installed the same code on ESP8266 nodemcuv2 and works well.

What's interesting, the default sensor code for arduino uploaded by Arduino IDE works correctly for both board.

Anyone have any idea what's wrong with ESP8266 e-paper and ESPHome? Thanks!

Which version of ESPHome has the issue?

v2022.6.2

What type of installation are you using?

Docker

Which version of Home Assistant has the issue?

I don't use

What platform are you using?

ESP8266

Board

Probably nodemcu

Component causing the issue

Custom component with A0 pin

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

ssieb commented 2 years ago

I think I remember this from Discord. Did you get it resolved?

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.