Interrupt issue with Wemos D1 R1

Hello,
I am trying to count the pulses of an external device with this simple sketch:

#define cpmPin 3
int count = 0;

void ICACHE_RAM_ATTR impulseCount(void) {
  count++;
}

void setup() {
    Serial.begin(115200);
    Serial.println("Setup");
    pinMode(cpmPin, INPUT_PULLUP); 
    attachInterrupt(digitalPinToInterrupt(cpmPin), impulseCount, FALLING);
    Serial.println("End Setup");
}

void loop() {
  Serial.print("Count: ");
  Serial.println(count);
  delay(5000);
}

The counter does not increment whatever happens on pin 3.

Just to ensure my board was not failing with pin 3, I changed to pin 6 and got every 5 seconds:

Am I doing something wrong?

Answering myself, it works with D4 ?!

Hi
Pin 3 (GPIO03) depending on the WEMOS model, whether RX and if it is connected to a PC, it is likely that the interrupt will not work.

About this problem when using pin 6 and by using large delay.
Using too large a delay on the ESP8266 causes
reset by wdt.
To avoid long-delayed wtd, use the yield() function; .
It can be used before the delay() function;
Looking like this:

yield();
delay(5000);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.