WEMOS D1R1 Interrupt repeats continuously, when triggered, how to fix bouncing?

Hello everyone, I am having such a nightmare to make it work, I am using a WEMOS D1R1 to handle the movement of an encoder via external interrupts.

Instead if detecting the edge (L to H), it detects the status, so the interrupt function repeats continuously if the state is H, so its behaving like a while(state==H){...}, instead of triggering once per H to L .

Here is my code so far:

void ICACHE_RAM_ATTR ISRC();
void setup() { 
  Serial.begin(115200); 
  pinMode(D9,OUTPUT); 
  pinMode(D8, INPUT_PULLUP); 
  attachInterrupt(digitalPinToInterrupt(D8), ISRC, RISING);  
  Serial.println("Started"); 
} 

void loop() 
{} 

//This function is supposed to get executed when interrupt happens, instead it happens looply while D8 is HIGH
 void ISRC() { 
 Serial.println("Interrupt Detected"); 
}

I dont know what else to try here is what the monitor says, please, note the time marks:

20:41:49.935 -> Interrupt Detected
20:41:49.935 -> Interrupt Detected
20:41:49.935 -> Interrupt Detected
20:41:49.935 -> Interrupt Detected
[...]

I have readed here that setting the input as INPUT_PULLUP fixes the issue, but it didnt happen with me.

I had tried wiring the interrupt input (D8), to a "clean" source, as it is the BUILTIN_LED (D9) pin, and then it does work perfectly.

The problem comes when I connect it to the encoder or a button.

I guess its a bouncing problem...

How can I avoid this supposed bouncing?

Is it really a bouncing problem?

How can I make it work?

Thanks everyoune in advance.

Hello tgtech,
++Karma; // For posting your code correctly on your first post.

It's not a bounce problem, if were then it would stop after a few times once the bounce settled down.

I think it's because you are trying to print inside an interrupt, which is bad practice anyway. I don't have a D1R1 but I do have a D1 mini, so I modified your code to work on it as follows:

void ICACHE_RAM_ATTR ISRC();
bool inputDetected;

void setup() {
  Serial.begin(115200);
  pinMode(13, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt (13), ISRC, RISING); 
  Serial.println("Started");
}

void loop(){
  if (inputDetected){
    inputDetected = 0;
    Serial.println("Interrupt Detected");
  }
}

//This function is supposed to get executed when interrupt happens, instead it happens looply while D8 is HIGH
 void ISRC() {
 Serial.println("Interrupt Detected");
  inputDetected = 1;
}

This does not have the problem yours has, although it bounces a little bit.

Interrupts are not the right tool for handling button presses and are very difficult to debounce. You should be polling the input every so often, if you do that debouncing is easy.

If you look in the IDE under examples 02 digital there is a demonstration of one way to debounce inputs.

tgtech:
I have readed here that setting the input as INPUT_PULLUP fixes the issue, but it didnt happen with me.

How have you wired the encoder? Are you using external pull-up or pull-down resistors? Are you using an encoder module with built-in pull-up/down resistors? (If so, please post a link to the module.) If you are doing none of these things and you are not using INPUT_PULLUP and have the encoder wired to ground, then your inputs will be floating, which would explain the continuous interrupts.