The Final Countdown - An RP3250 based Event Timer
Sometimes, we are counting down the days to an important event, such as a trip or an anniversary. A few years ago, I built a timer for this, using an ESP-8266 board and two LED bar displays:
It worked fine, but powering it through the USB connector was a bit of a pain. So, I started thinking about a battery-powered device. Looking at my parts stash, I found a few components that could be used in this project:
- An e-paper display: it shows the last image even if powered down.
- A tinyRTC module, with a DS1307 with battery backup and an AT24C32 EEProm: it can save the event date and keep track of the current date and time.
- A XIAO RP2350 board: it has support for a rechargeable battery.
I had enough experience with the first two modules, the XIAO RP2350 brought the adventure of learning about power saving with the RP2350.
Before delving into the project details, a word of caution regarding the tinyRTC module: it was designed for use with a rechargeable LR2032 battery, but it typically comes with a CR2032 non-rechargeable battery. The charging circuit also does not follow the LR2032 specifications. So, I am using a CR2032 and removing the D1 diode to disable the recharge circuit.
The interconnections are straightforward:
- The display utilizes a three-wire SPI interface (MOSI, SCK, and CS), three digital signals (BUSY, RES, and D/C), plus power (3.3V) and ground.
- The tinyRTC utilizes an I2C interface (SDA and SCL), plus power (3.3V) and ground.
- A button is connected between a digital input and ground.
- The XIAO has pins connected to the spi0 and i2c1 interfaces in the RP2350. The digital signals were assigned to the other pins more or less randomly..
The assembly was done using a protoboard PCB, female pin connectors, and wire-wrapping wires.
The code for interfacing the tinyRTC module is also straightforward. I store my "configuration" (the event date and time) in the EEProm with a simple XOR checksum.
The display itself is a little more complicated; the code for initializing and updating the display is adapted from a manufacturer's example. With enough RAM in the RP2350, I could keep an image of the display in memory.
For text, I chose a 12x16 font. This requires some bit-shifting, as the characters are not byte-aligned. To draw a simple clock dial, I added routines to draw lines and circles. The algorithm for these routines is based on my 1990 book, "PC Assembler: Usando Gráficos e Sons".
The program will wake the RP2350 every 15 minutes to update the display. That leaves us with the task of putting the RP2350 to sleep. The RP2350 documentation is not particularly informative on this matter, nor is the SDK documentation. The SDK has a module named hardware_powman with a few routines, and there are a couple of examples at a fork of the pico-examples. Not much, but enough for this project:
- We will switch between two power states: P0_0 (where everything is turned on) and P1_7 (where most of the hardware is turned off).
- The change from P0_0 to P1_7 is commanded by the software.
- The change from P1_7 back to P0_0 can be commanded by a timer alarm or a GPIO change.
- The change from P1_7 back to P0_0 will result in a reset, with the previous RAM content lost.
For now, I am using the timer alarm to wake up the RP2350. The downside is that this timer is not very precise, but I can not use the tinyRTC to drive a GPIO (more about this at the end).
I am not using the USB in normal operation; it is used for configuring the timer and debugging purposes. To reduce power consumption, the USB hardware must be disabled before the device goes to sleep. This is done by a kind of "magic incantation" copied from the powman_timer example.
The full code is available on my github: https://github.com/dquadros/FinalCountdown.git
As a future enhancement, I plan to replace the tinyRTC module with one that utilizes the DS3231 chip. This RTC has better precision and an alarm feature, allowing me to wake the RP2350 through a GPIO pin. Best yet, I found a DS3231 module with a pinout that allows for the replacement without altering the wiring of the RTC connector.
Comments
Post a Comment