ESP-01s - Issue after deepsleep

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
bene
Posts: 2
Joined: Thu Jul 21, 2022 9:36 pm

ESP-01s - Issue after deepsleep

Post by bene » Thu Jul 21, 2022 9:53 pm

Hi,

I want to build several battery powered sensors with an ESP-01s. However, I face an issue with the deepsleep.

Let me try to explain:
I want to periodically read some sensor values (e.g. every 10min). Until recently I didn't know about webrepl and I did everything with uPyCraft which was properly working (GPIO16 properly connected to RST).
Now I decided to use webrepl (no need for USB adapter and I don't have to disassemble my sensors in case I want to change something). But if needed, I still want to be able to easily access my board. My idea was to use GPIO3 as in input. If it is high, the board will do the sensor reading and goes to deepsleep afterwards. If it is low, it won't go to deepsleep and I am able to reprogram.

The issue now is, that in general I am able to put the board to deepsleep for an defined amount of time. It will power up again, but then I am not able to connect to it anymore. Also the sensor reading is not happening. On the first start of the board however, it properly reads the values.

I added the relevant part of the main.py below. Reading GPIO3 input properly works on start of the board, I verified the value. Do you have any idea, what could go wrong, that I'm not able to connect to the board after deepsleep?

Code: Select all

import machine
from machine import Pin

def deep_sleep(msecs):
  rtc = machine.RTC()
  rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
  rtc.alarm(rtc.ALARM0, msecs)
  machine.deepsleep()
  
p3 = Pin(3, Pin.IN)
v = p3.value()

# sensor reading happenes here

if v == 1:
  deep_sleep(5000)

User avatar
karfas
Posts: 193
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: ESP-01s - Issue after deepsleep

Post by karfas » Fri Jul 22, 2022 11:17 am

Where in your code your WLAN and WebREPL starts ?

I have no experience with the 8266, but for an ESP32 the deactivation of any WIFI functions (e.g. wlan.active(False)) is a requirement für deep sleep.
A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

bene
Posts: 2
Joined: Thu Jul 21, 2022 9:36 pm

Re: ESP-01s - Issue after deepsleep

Post by bene » Fri Jul 22, 2022 8:37 pm

Hi,

Wifi is configured in boot.py and webrepl starts there as well, see code below.
To my knowledge, it should not make a difference if it is in boot.py or main.py

Until now I never had an issue with deepsleep, I always had it implemented as in the first post. Just when I added the GPIO3 as written in the first post, I got to the issue.

Code: Select all

import network
import os

import esp
esp.osdebug(None)

import gc
gc.collect()

ssid = 'xxx'
password = 'yyy'

station = network.WLAN(network.STA_IF)
station.config(dhcp_hostname='ESP-01s-02')
station.ifconfig(('192.168.178.162', '255.255.255.0', '192.168.178.1', '192.168.178.1'))
station.active(True)
station.connect(ssid, password)

while station.isconnected() == False:
  pass

import ntptime
ntptime.settime()

import webrepl
webrepl.start()

Post Reply