Impossible to wake up from sleep with ext the xiao esp32c3

Hi,

The wake up doesn’t work on XIAO ESP32C3

I use this
esp_deep_sleep_enable_gpio_wakeup(WAKEUP_PINS,ESP_GPIO_WAKEUP_GPIO_HIGH);
esp_deep_sleep_start();

A vibration sensor is on D4 therefore I use this for bit mask:

const uint64_t WAKEUP_PINS = 0b00100000;

It goes to deep sleep but can’t be waken up with ext event.
Any idea?

Sabey

Which pin did you use?

Hi I use the GPIO6 (D4)

Hi baboics,
can you post more code without giving away any proprietary ? I want to test it as well.
thx
GL :slight_smile:
PJ

also check you soulder job for pins to make sure the pin is electricly connected
and make sure not bridged to an adjacent pin

i recomend the xiao expansion boaed and or grove base for trouble shooting

also it appears that D4 and D5 form the standard IIC bus pins
you may want to select another pin it seems that 1 2 3 are more free for experimentation

Yes sure:

In the definition part:

const uint8_t pinWakeUp = D4;
//const uint64_t WAKEUP_PINS = 0b11111111111111111111111111111111;
const uint64_t WAKEUP_PINS = 0b00100000;

unsigned long gTimer = 0;

In the setup:

attachInterrupt(pinWakeUp, intTimerReset, CHANGE);

some functions:

void handleTimer(bool pGoSleep) {

if (HIGH == digitalRead(pinWakeUp)) {

gTimer = millis();  

}

if(pGoSleep && !gConnected && millis() - gTimer> sleepTime) {

  Serial.println("Sleep…");

  esp_deep_sleep_enable_gpio_wakeup(WAKEUP_PINS,ESP_GPIO_WAKEUP_GPIO_HIGH);

  esp_deep_sleep_start();    

}
}

//whereas gConnected refers to Bluetooth connection station (I use BLE bluetooth.) - here you can eliminate.

void intTimerReset(void) {

gTimer = millis();  

//gTR = true;

}

The loop:

void loop() {

char c;

handleTimer(true);
//… other commands
}

In the BLE callback:

static void notifyCallback(BLERemoteCharacteristic* pBLERemoteCharacteristic, uint8_t* pData, size_t length,bool isNotify) {

handleTimer(false);

//… other commands
}

I hope I copied all the necessary parts of the code.
Thx.

I’m wondering - Do I need a reset command in the wake up interrupt callback?

PS.: As I mentioned the sleep starting is OK, the wake up is not - or at least I can’t reconnect again the modul to the PC on the given port (without a complate restart (USB out and in)) So I deduct It hasn’t restarted.

Ok I will test it with another port too.

I cleaned up my code (remove the BLE connection) and here is the complete one

using namespace std;

const uint8_t pinWakeUp = D4;

const uint8_t pinMotContVCC = D5;

const uint8_t pinSerRX = D7;

const uint8_t pinSerTX = D6;

const uint8_t pinBeep = D9;

//const uint64_t WAKEUP_PINS = 0b11111111111111111111111111111111;

const uint64_t WAKEUP_PINS = 0b00111110;

#define sleepTime 5000 //in milisec

unsigned long gTimer = 0;

unsigned long gTimer2 = 0;

uint8_t gWrite = false;

void handleTimer(bool pGoSleep) {

if (HIGH == digitalRead(pinWakeUp)) {

gTimer = millis();  

}

if(pGoSleep && millis() - gTimer> sleepTime) {

  Serial.println("Sleep…");

      digitalWrite(pinBeep,LOW);

  esp_sleep_enable_timer_wakeup(10000);

  esp_deep_sleep_enable_gpio_wakeup(WAKEUP_PINS,ESP_GPIO_WAKEUP_GPIO_HIGH);

// esp_deep_sleep_start();

}

if (millis() - gTimer2 > 500) {

digitalWrite(pinBeep,LOW);

}

}

void intVibr(void) {

//ESP.restart();

gTimer = millis();  

gTimer2 = gTimer;

gWrite = true;

}

void setup() {

pinMode(D4, INPUT);

pinMode(pinWakeUp, INPUT);

pinMode(pinBeep, OUTPUT);

digitalWrite(pinBeep, HIGH);

delay(300);

digitalWrite(pinBeep, LOW);

delay(300);

digitalWrite(pinBeep, HIGH);

delay(300);

digitalWrite(pinBeep, LOW);

delay(300);

digitalWrite(pinBeep, HIGH);

gTimer2 =  millis();



attachInterrupt(pinWakeUp, intVibr, CHANGE);  

handleTimer(false);

Serial.begin(115200);

Serial.println("Starting Arduino BLE Client application...");

} // End of setup.

//*********************** This is the Arduino main loop function.

void loop() {

handleTimer(true);

Serial.write(".");

while (Serial.available()) {

    gTimer = millis();  

    gWrite = true;

Serial.write(Serial.read());

}

if (gWrite) {

digitalWrite(pinBeep,HIGH);

Serial.write("+");

gWrite = false;

}

delay(200); // Delay between loops.

} // End of loop

With an empty installation (I mean without bluetooth) and with D2 it seems to be working.