noInterrupts(); does not work on Wemos D1 mini?

Hi there,
As I have written in the link below I´m controlling my stepper with interrupts

Now I need to disable the interrupt routine to do some other stuff.
But when I call the function noInterrupts(); this will have no effect.
The interrupt will still trigger I do not understand why ?

Does someone know if the interrupt is enabled by thees functions?

void loop()
{
  Blynk.run();
  ArduinoOTA.handle();
}

AFAIK, they are not.
I think you should be looking at attachInterrupt and detachInterrupt not “noInterrupts()”.

@Costas
Thank you very much for your advice.
Sorry for asking again but I do not understand the reference @ https://www.arduino.cc/en/Reference/detachInterrupt

Could you please advice me how to use "detachInterrupt " for the example below ?

  noInterrupts();
  timer0_isr_init();
  timer0_attachInterrupt(timer0_ISR);
  timer0_write(ESP.getCycleCount() + 80000000L); // 80MHz == 1sec
  interrupts();

Take a look at the last post in this thread http://www.esp8266.com/viewtopic.php?f=32&t=4694&sid=07e9f4237d5251af95c5b7327cb6cbd3&start=4

@Costas your link explains how “attachInterrupt” is used
But how to use "detachInterrupt " ??
I tried several versions but I got always Error messages from the compiler.
detachInterrupt (); causes : too few arguments to function ‘void detachInterrupt(uint8_t)’
detachInterrupt (timer0_ISR); causes : invalid conversion from ‘void (*)()’ to ‘uint8_t {aka unsigned char}’ [-fpermissive]

I didn’t look too closely at the sketch. assumed it would include detachInterrupt.

I will dig out one of my sketches and post it here.

1 Like

@Brummer take a look through this and pull out the bits you need. I haven’t looked at the sketch for 6 months but I do have interrupt stuff in sketches I use fairly regularly.

// DoorInterrupt.ino     15 July 2016  Blynk project name VPinTest (not fully working)
// test with a momentary or regular switch between GND and D3 (no resistors required)

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
//#define HIGH 255   // alternative method for LED's
//#define LOW 0      // alternative method for LED's
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
WidgetLED led1(V1);  // green - door closed
WidgetLED led2(V2);  // red   - door open

int Door_Sensor_Pin = 0;     // choose the Door_Sensor_Pin, D3 on WeMos, has builtin 10K pullup resistor
float Milliseconds;
int reedswitchstatus; // 1 is connected (door closed) and 0 is notconnected (door open)

int ledState = LOW;
int btnState = HIGH;
SimpleTimer timer;

void setup()
{
  Serial.begin(115200);
  pinMode(Door_Sensor_Pin, INPUT_PULLUP);  // declare Door_Sensor_Pin as input
  //attachInterrupt(Door_Sensor_Pin, highInterrupt, RISING); // use for Gnd connection
  attachInterrupt(Door_Sensor_Pin, changeInterrupt, CHANGE); // use for Gnd connection
  Blynk.begin(auth, "xxxxxxxxxx", "xxxxxxxxxx");
  while (Blynk.connect() == false) {
    // wait for connection to Blynk server before proceeding
  }
  Blynk.virtualWrite(V1, 0);   // green LED off until reedswitch is checked
  Blynk.virtualWrite(V2, 0);   // red LED off until reedswitch is checked
  digitalWrite(Door_Sensor_Pin, ledState);
  timer.setInterval(100L, updateLEDs); // every half second (500L milliseconds) update the LED's
}

void changeInterrupt(){  // can't update LED's within interrupt as it will reset the ESP
    Serial.println("Door Opened or Closed");  // LOW, (default state is HIGH, door open)
    reedswitchstatus = !reedswitchstatus;
    detachInterrupt(Door_Sensor_Pin);
    Milliseconds = millis()+50;  //debounce delay
    while (Milliseconds > millis()) ;    
    attachInterrupt(Door_Sensor_Pin,  changeInterrupt, CHANGE);
}


void lowInterrupt(){  // can't update LED's within interrupt as it will reset the ESP. NOT CURRENTLY USED.
    Serial.println("Door Closed");  // LOW, (default state is HIGH, door open)
    reedswitchstatus = 1;
    detachInterrupt(Door_Sensor_Pin);
    Milliseconds = millis()+50;  //debounce delay
    while (Milliseconds > millis()) ;    
    attachInterrupt(Door_Sensor_Pin,  highInterrupt, RISING);
}

void highInterrupt(){  // can't update LED's within interrupt as it will reset the ESP. NOT CURRENTLY USED.
    Serial.println("Door Open");  // HIGH, default state
    reedswitchstatus = 0;
    detachInterrupt(Door_Sensor_Pin);
    Milliseconds = millis()+50;  //debounce delay
    while (Milliseconds > millis()) ;    
    attachInterrupt(Door_Sensor_Pin, lowInterrupt, FALLING);    
}


void updateLEDs(){
  if((reedswitchstatus == 1) || (digitalRead(Door_Sensor_Pin) == LOW)){  // door closed, illuminate GREEN LED
  //if(digitalRead(Door_Sensor_Pin) == LOW){  // door closed, illuminate GREEN LED
    // btnState is used to avoid sequential toggles
    if (btnState != LOW) {
      Serial.print("Door sensor is now ");
      Serial.println(ledState);  
      // Toggle LED state
      ledState = !ledState;
      Blynk.virtualWrite(V1, (255 * ledState));   // Green LED
      Blynk.virtualWrite(V2, (255 * !ledState));   // Red LED
      
      Blynk.virtualWrite(V0, ledState);           // Blynk button
    }
    btnState = LOW;
  } 
  else {
    btnState = HIGH;
  }       
}

BLYNK_WRITE(V0) // Button to open and close door
{
  ledState = param.asInt();
  digitalWrite(Door_Sensor_Pin, ledState);
  Serial.print("Button status is ");
  Serial.println(ledState);
  if(ledState == 1){
    led1.on();  
    led2.off();     
  }
  else{
    led1.off();  
    led2.on();     
  }
}  

BLYNK_WRITE(V3) // Timer1  // todo
{
  int Timer1 = param.asInt();
  if (Timer1 == 1) {
    digitalWrite(Door_Sensor_Pin, 0);    // door closed
    Serial.println("Timer closed the door");
  }
  //else{
  //  digitalWrite(Door_Sensor_Pin, 1);  // door open  
  //  Serial.println("Timer opened the door");  
  //}
  Serial.print("Got a value: ");
  Serial.println(param.asStr());
}  
void loop()
{
  Blynk.run();
  timer.run();
}

I finally found the solution to disable the interrupt routine.
It is very simple but because I´m not family with this stuff it was hard to find.

timer0_detachInterrupt(); // will stop the interrupt

1 Like