Help with random deep sleep pin voltages

Tranzmetro
Posts: 9
Joined: Fri Jan 05, 2018 1:38 am

Help with random deep sleep pin voltages

Postby Tranzmetro » Mon Mar 16, 2020 2:18 am

I put my esp32 into deep sleep to save energy. Attached to pin 21 I have the anode of the led of an opto isolator and a 10k resistor to ground. The cathode of the led is connected to ground through a 330 ohm resistor.

When the esp32 is awake I can make pin 21 go high of low as I wish. When the esp32 is in deep sleep mode I get a random voltage on the pin which is often enough to turn the opto isolator on.

How do I make pin 21 low or floating when the esp32 is in deep sleep?

The following is an example app. The code is from the web but doesn't seem to make any difference to the output. I have also tried to make the pin input only but this made no difference. The 10k resistor is to pull the pin low when it is floating or when it is an input.

I'm new to this and I'm missing something obvious. Any advice will be appreciated.
#include <Arduino.h>
#include <WiFi.h>
#include <driver/rtc_io.h>
void setup()
{
pinMode(GPIO_NUM_21, OUTPUT);
digitalWrite(GPIO_NUM_21, HIGH); // Pin at 3.3v
vTaskDelay(pdMS_TO_TICKS(5 * 1000));
digitalWrite(GPIO_NUM_21, LOW); // Pin at 0v
vTaskDelay(pdMS_TO_TICKS(5 * 1000));
//
rtc_gpio_init(GPIO_NUM_21);
rtc_gpio_set_direction(GPIO_NUM_21, RTC_GPIO_MODE_OUTPUT_ONLY);
rtc_gpio_hold_dis(GPIO_NUM_21);
rtc_gpio_set_level(GPIO_NUM_21, LOW);
rtc_gpio_hold_en(GPIO_NUM_21);
//
esp_sleep_enable_timer_wakeup(5 * 1000000);
esp_deep_sleep_start(); // Pin 21 voltage varies randomly between .7v and 2.5v
}

void loop()
{
}
/* RTC code from:
https://electronics.stackexchange.com/q ... e-too-weak
*/

Who is online

Users browsing this forum: No registered users and 34 guests