Skip to content

NodeMCU Interrupt not wokring (Arduino IDE) #3825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rajendran20 opened this issue Nov 13, 2017 · 2 comments
Closed

NodeMCU Interrupt not wokring (Arduino IDE) #3825

rajendran20 opened this issue Nov 13, 2017 · 2 comments

Comments

@rajendran20
Copy link

Hardware

Hardware: ESP-12
Core Version: ?2.1.0-rc2?

Hi Guys, I am new to nodeMCU and have been trying out the following code to test the interrupt. In normal sequence the LED will blink (yellow, green, red). Once interrupt is triggered by a switch, a blue LED will blink once. Now the issue is, while main sequence is running, and interrupt is triggered, the blue led turns on and stays and worst still the main sequence is still running. The blue LED is just on.
Switch is pulled up to 3.3V when not pressed.
Rare times, it works but the blue LED will only turn off after 8s.

Problem description

Settings in IDE

Module: Generic ESP8266 Module
Flash Size: ?4MB
CPU Frequency: ?80Mhz?
Flash Mode: ?qio?
Flash Frequency: ?40Mhz?
Upload Using: SERIAL?
Reset Method: nodemcu?


Sketch

int yellow = D2; // declare yellow ledPin as variable
int green = D3; // declare green ledPin as variable
int red = D4; // declare red ledPin as variable
int blue = D5; // declare blue ledPin as variable

void setup()
{
// put your setup code here, to run once:
pinMode(yellow,OUTPUT); //configure ledPin as OUTPUT
pinMode(green,OUTPUT); //configure ledPin as OUTPUT
pinMode(red,OUTPUT); //configure ledPin as OUTPUT
pinMode(blue,OUTPUT); //configure ledPin as OUTPUT
pinMode(SW,INPUT); //configure switch as INPUT
attachInterrupt(digitalPinToInterrupt(SW), interruptISR, FALLING);

}

void loop()
{

digitalWrite(yellow, HIGH); // turn on yellow LED
delay(1000); // delay 1s 
digitalWrite(yellow, LOW); // turn off yellow LED
digitalWrite(green, HIGH); // turn on green LED
delay(1000); // delay 1s 
digitalWrite(green, LOW); // turn off green LED
digitalWrite(red, HIGH); // turn on red LED
delay(1000); // delay 1s 
digitalWrite(red, LOW); // turn off red LED

}

void interruptISR() {
digitalWrite(blue, HIGH); // turn on yellow LED
delay(1000); // delay 1s
digitalWrite(blue, LOW); // turn off yellow LED // Wait for two seconds (to demonstrate the active low LED)
}

@coelner
Copy link

coelner commented Nov 13, 2017

I guess an interrupt has to be an atomic operation. The delay is probably jumping to the loop() and not back to the interrupt.

@devyte
Copy link
Collaborator

devyte commented Nov 13, 2017

@rajendran20 your ISR has to have the ICACHE_RAM_ATTR decorator.
Also, you can't call delay() in an ISR, let alone such a long one.
Set a flag in the ISR, check it in the loop.
Finally, you don't have wifi set up anywhere, but you also don't erase the config to remove any prior sdk params. Did you erase the flash before flashing this sketch? Having such long delays in the loop doesn't play well with the wifi stack, if it's active.

If you need further help, please discuss at a community forum.
Closing as user error, and per #3655 .

@devyte devyte closed this as completed Nov 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants