ESP8266 not waking up Arduino UNO

Hello,

in my project I am trying to wake up Arduino UNO by an external interrupt from ESP8266. However as this is my first time, I am not very sure about what I am doing.
For some reason the Arduino never wakes up with the signal.
Could you please take a look at the code if there is any error? The pins should be connected correctly.

Arduino code :

#include <LowPower.h>
bool firstDry = false;
bool secondDry = false;
int firstPin = 3;
int interruptPin = 4;
int secondPin = 5;

void setup() {
  Serial.begin(9600);
  pinMode(firstPin, OUTPUT);
  pinMode(secondPin, OUTPUT);
}

void wakeUp() {
}

void loop() {
  delay(500);
  attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), wakeUp, FALLING);
  LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);  
  delay(100);
  detachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN));

...
 #program logic, not related to sleep
...
}

ESP code:

#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include "variables.h"

int address = 0;
const int interruptPin = 2;
byte value;
String incomingByte;
 
void setup() {
  delay(1000);
  Serial.begin(9600);                 //Serial connection
  WiFi.begin(WIFI_SSID,WIFI_PASSWD);   //WiFi connection
  
  while (WiFi.status() != WL_CONNECTED) {  //Wait for the WiFI connection completion
    delay(500);
    Serial.println("Waiting for connection"); 
  } 
}
 
void loop() {
  while (Serial.available() == 0){
    digitalWrite(interruptPin,HIGH);
    delay(100);
    digitalWrite(interruptPin,LOW);
    delay(500);
  }
  if (Serial.available() > 0) {
      // read the incoming byte:
      incomingByte = Serial.readString();
    
 ...
 #program logic, not related to sleep
...
 
}

Thanks!

An ATmega328p cannot wake up on an edge external interrupt. You either have to use a level interrupt or use a pin change interrupt if power down sleep mode is a must. You can use your existing code/circuitry if for example an idle sleep mode is sufficient.

you mean use HIGH/LOW instead of FALLING in the attachInterrupt? Also what do you mean by pin change interrupt?

Hi @archer785
The UNO has only pins 2 e 3 for RISING/FALLING/HIGH/LOW interrupt.
And yow are using pin 4.
See:
Arduino Pin Change Interrupts – The Wandering Engineer.

No, he's not using any of them because the code won't compile. C code is case-sensitive!

Yes, try to use LOW, that should work given you didn't change the ESP code.

Is there a difference between HIGH and LOW in this case? Because if I use LOW, I would have to have HIGH on the pin in the rest of the loop function which would make the microcontroller use more juice, no?

No, you remove the interrupt handler just after the wake up so after that the pin may have any state.
Having the pin HIGH while the Arduino sleeps shouldn't use any relevant current (there is no load).

1 Like

@pylon so unfortunately not even LOW works :frowning: This is how I send the interrupts on the ESP:

void setup() {
 .......
  digitalWrite(interruptPin,HIGH);
.......
}
 
void loop() {
  delay(100);
  ESP.deepSleep(10e6);
  delay(100);
  digitalWrite(interruptPin,LOW); //setting LOW, trying to wake up Ardunio
  while (Serial.available() == 0){
    delay(100);
  }
  if (Serial.available() > 0) {
      // read the incoming byte:
      incomingByte = Serial.readString();
  }  
  digitalWrite(interruptPin,HIGH);
....

I even tried to change the interrupt pin on Arduino to 2, just to be sure and it does not work either. Arduino code:

  attachInterrupt(digitalPinToInterrupt(interruptPin), wakeUp, LOW);
  LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);  
  delay(100);
  detachInterrupt(digitalPinToInterrupt(interruptPin));

I will do a test only for the pin signals, if arduino can even recognize HIGH/LOW from the ESP and move on from there

That's a good idea because pin 4 isn't an external interrupt pin.

Remove the delay() call.

If that doesn't work, post your complete code, a complete wiring diagram and a link to the schematics of the used level converter (between the UNO and the ESP). Maybe the hardware isn't working as you intended.

@pylon so I moved ahead a bit, but now I have learned that ESP8266 has undefined GPIO state after deep sleep.

This is my Arduino code:

#include <LowPower.h>
int interruptPin = 2;
int val = 0;


void setup() {
  Serial.begin(9600);
}

void wakeUp(){
}

void loop() {
  delay(1000);
  Serial.println("Going to sleep");
  delay(500);
  attachInterrupt(digitalPinToInterrupt(interruptPin), wakeUp, LOW);
  LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);  
  delay(100);
  detachInterrupt(digitalPinToInterrupt(interruptPin));
  Serial.println("Woke up!");
}

And this is my ESP code:

const int interruptPin = 4;
 
void setup() {
  pinMode(interruptPin, OUTPUT);
  digitalWrite(interruptPin,HIGH);
}
 
void loop() {
  delay(10000);
  //  ESP.deepSleep(10e6);
  digitalWrite(interruptPin,LOW);
  delay(1000);
  digitalWrite(interruptPin,HIGH);

}

When using delay() on the ESP, everything works as intended, waking the Arduino up as it should. However, when I switch to the deepSleep() it suddenly becomes undeterministic and it seems like the pins dont follow the value set by digitalWrite(), its just random (i.e. the pins stay LOW, constantly waking arduino up, even when I set them to HIGH).

Do you have any experience with this issue?

I have some experience with AVR sleeping but very little about ESP sleeping states.

okay, let me ask this question in a proper place, thank you for your help!

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