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
...
}
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.
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).
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.
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).