So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By pxlstuermer
#61181 I'm trying to figure out how the AttachedInterrupt works on the NodeMCU.
Everything I found tells me that this code is OK?!

Code: Select allvoid setup() {
  Serial.begin(9600);
  pinMode(D4, INPUT);
  attachInterrupt(D4, doSth(), CHANGE);
}

void loop() {
  Serial.println(digitalRead(D4));
  delay(100);
}

void doSth() {
  Serial.println("Check!");
}


But I just get this error:

Image

I still have no idea after hours of research!
Thanks a lot in advance :-)
User avatar
By pxlstuermer
#61198
martinayotte wrote:Simple google search would have revealed you that you should not put parenthesis of the callback.

Finally figured it out some minutes ago as well. Sorry, but hours of searching didn't help with this bug, since the error message was not very detailed and I just overlooked the parentheses.

Thanks again :-)
User avatar
By penatenjoe
#61238 You also should write
Code: Select allvoid ICACHE_RAM_ATTR doSth(){
. My understanding is that this ensures the interrupt routine stays in the RAM. Also I think I read that the interrupt service routine has to be fast, using Serial.print is AFAIK not a good idea. Advice was to set a flag and check it in loop().