Inky Frame — Battery powered photoframe — RTC troubles

Hi everyone 👋🏻

Goal
I’m trying to build a really simple battery powered photoframe with the fantastic Inky Frame 7.3. I use a SD card to store the pictures and I want to update the picture one time per day (every 24 hours).

Setup

  • MicroPython: 1.19.18
  • Battery: 2200mAh from Pimoroni shop
  • SDHC Transcend 16 GB
  • My main.py is here on GitHub

Problems

  • My code seems to work correctly when it’s connected over USB
  • Apparently, the sleep_for function does not work if I want an update every 24 hours
  • I don’t really understand how to use the RTC chip and how to activate the deep sleep. I’ve seen some examples from inky_frame_news.py and from the popular slideshow.py but it’s not really clear for me.

Can you help me better understand how to use RTC and deep sleep?
Also, how can I wake up the Frame only every 24 hours?

Thanks a lot for your help!

Cheers

Update on 04/07:
ahnlak created an issue about the weird behavior of the sleep_for function: Inky Frame sleep_for >= 1 day? · Issue #744 · pimoroni/pimoroni-pico · GitHub

It might be a bit confusing at first (due to the misnaming of the method), but technically the pico does not use deep-sleep, but powers down. A button-press or an interrupt from the rtc enables power again, and the pico boots and your program runs again from the beginning.

When on USB, the pico is not powered down but running idle and your while-loop is running. Otherwise the while-loop is only executed once.

When on battery, I suppose you have tried to wake up the inkyframe once using a button (necessary) and then waited for the next startup?

Hi bablokb,

Thanks for your answer!

When on battery, this is what I do:

  1. I plug the battery
  2. I press one button to wake up the Frame
  3. The main.py is executed then go to sleep
  4. The RTC wakes up the Frame and the main.py is executed again

I experimented since yesterday and I replaced the inky_frame.sleep_for() function in my while loop with the following:

rtc.set_timer(VALUE, ttp=PCF85063A.TIMER_TICK_1_OVER_60HZ)
hold_vsys_en_pin.init(Pin.IN)

It seems to work like expected, however I would like to use a value > 255 (here it’s 255min). The RTC seems like it’s limited to 255 because it’s 8 bit? 🤔

Do you know how to use the RTC with a much bigger value like 24 hours or many days?

The rtc supports countdown-timer(s) and alarms. The former is based on a 8-bit register, the latter not.

The timer counts down the value supplied in tick-intervals, the longest tick-interval is 1/60 Hz, i.e. one tick per minute. So for timers, 255 minutes is the absolute limit.

In contrast to timers, which fires when the countdown reaches zero, the alarm fires when certain conditions are met. E.g. you could configure an alarm to fire every time the minute is 5 (i.e. once per hour at xx:05). Or when the minute is 15 and the hour is 12 (i.e. once a day at 12:15). Or when the day is 1 and the hour is 8 and the minute is 0 (i.e. on every first of a month at 08:00).

The function for this is rtc.set_alarm(). A few things to watch out for:

  • take care that the rtc-clock is set to the correct value. You must update the rtc-clock from a reliable source, e.g. a time-server. If you just want to wake up once a day and don’t care about the exact time, this is not strictly necessary.
  • don’t confuse the external pcf85063a-rtc of the InkyFrame with the builtin internal rtc of the Raspberry Pi Pico. Ideally, you would update the internal rtc of the pico at every start from the external rtc. The latter will be powered even if the pico is shut down and therefore won’t loose it’s value
  • make sure that you clear any alarm at boot. This is usually the first thing what I do in my program. This also prevents some nasty problems when you use a button once in a while to start the pico

If you want some inspiration, my code for this is micropython-examples/sdslideshow.py at master · kevinjwalters/micropython-examples · GitHub

One gotcha I found was on 5.7" I would get errors on early attempts to mount SD card.

More info on

Thanks for your help 🙂 I’m going to dig alarms and continue to experiment.