Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By tjodork
#89143 I'm trying to count pulses from a hall effect switch that goes through an amplifier and schmitt trigger.
The scope signal looks clean but for every pulse on scope I get dozens of count (count is incremented in interrupt handler). I read somewhere that they were susceptible to problems if on esp and input logic were on different power supplies so I broke the 5v on the usb cable so i could still use the serial monitor while having the esp8266 nodemcu and logic powered by same 5v.
Here is the code
Code: Select allvolatile uint32_t pulseCount = 0;

#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
#define IRQ_HANDLER_ATTR ICACHE_RAM_ATTR
#else
#define IRQ_HANDLER_ATTR
#endif

void IRQ_HANDLER_ATTR onPulse()
{
   pulseCount++;
  Serial.println(pulseCount);
}

void setup() {
#define DIGITAL_INPUT_SENSOR D2
   // initialize our digital pins internal pullup resistor so one pulse switches from high to low (less distortion)
    pinMode(DIGITAL_INPUT_SENSOR, INPUT);

    attachInterrupt(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), onPulse, RISING);

  Serial.begin(9600);
   pulseCount = 0;
}



void loop() {
}


Here is a pic of scope
https://youtu.be/sGJrUbsZiQ4

Any help would be appreciated