Uncle Deadly Image

Hi there. Welcome to blog.oddbit.com! I post articles here on a variety of technical topics. Mostly I’m posting for myself (writing things up helps me remember them in the future), but I always hope the content I put here is helpful to someone else. If you find something here useful and want to say thanks, feel free to buy me a coffee!

To sleep or not to sleep?

To sleep or not to sleep?

lastrun_1 = 0 lastrun_2 = 0

while True: now = time.time()

if (lastrun_1 == 0) or (now - lastrun_1 >= 60):
    read_sensor_1()
    lastrun_1 = now
if (lastrun_2 == 0) or (now - lastrun_2 >= 300):
    read_sensor_2()
    lastrun_2 = now

machine.idle()

If we were only reading a single sensor (or multiple sensors at the same interval), we could drop the loop and juse use the ESP8266’s deep sleep mode (assuming we have wired things properly):

read more →