It’s now possible to build remote, low-power microcontroller projects that can operate indefinitely without batteries and still not crash, even if power is interrupted. Let that sink in.
As an example, we’ll show you how to build a LoRa-based weather station that’s powered solely by solar panels. Its code is written in CircuitPython, running on a popular hobby-grade microcontroller board: the Adafruit Metro M0 Express. The novelty is that it can keep the state of the weather measurement program, even during periods of complete darkness when it runs out of power. This is called intermittent computing or perpetual computing, and it opens up a new world of sustainable electronics, where many applications will work well, and practically forever, without reliance on a battery.
The trick is a specially modified version of the CircuitPython interpreter that is resilient to power failures. (Not the language — the CircuitPython syntax stays intact). This means we don’t have to supply our weather station with a continuous power source, such as a battery. Instead, we harvest energy from a solar cell and temporarily store it in a capacitor. The system will boot when the capacitor contains enough energy to execute some code, and the program will pick up where it left off before the power ran out. This way, we can opportunistically collect weather information without relying on a potentially polluting battery and frequent travel to replace that battery.
Finally we can build truly perpetual, battery-free, energy-autonomous embedded systems using off-the-shelf components! We proved the concept in 2020 with our Battery Free Game Boy project led by Jasper de Winkel, where we powered the game by solar panels and kinetic energy from the player’s button presses. Now we’ve brought it to CircuitPython.
We call our system BFree. You can program your microcontroller in regular CircuitPython, and a specially designed extension board stores the intermediate state of the computation during power failures. Then your microcontroller can pick up where it left off, and continue executing CircuitPython correctly when power resumes!
Battery Free Game Boy, September 2020, from Proceedings of the ACM on Interactive, Mobile, Wearable and Ubiquitous Technologies
How Does BFree Work?
BFree is two things: an extension board (“shield”) attached on top of the Metro M0 Express and a piece of software running transparently on the Metro M0. This combination enables CircuitPython applications written for the Metro M0 to continue where they left off after a power failure. BFree is designed to operate in an environment with insufficient energy to continuously power the Adafruit Metro M0.
The BFree shield houses a Texas Instruments MSP430FR series microcontroller. What’s special about this MCU is the presence of non-volatile RAM in the form of ferromagnetic RAM (FRAM). This type of non-volatile memory is low-power and byte-addressable. It functions just like standard SRAM, but with the bonus of not losing its data when power is removed. It is a better choice than flash memory, which is power-consuming to write and requires writing of a complete “page” at a time.
The BFree software is a modified version of CircuitPython (which we call BFree-core) that talks with the BFree shield over an SPI connection. BFree has several available checkpoint strategies for when and what to store in the shield’s FRAM memory from the CircuitPython program. The default strategy is creating a checkpoint every 100ms, but this can all be configured within CircuitPython.
When BFree-core decides it’s time for a checkpoint, it instructs the BFree shield to make one, and sends the CircuitPython Virtual Machine’s content to the shield, which stores it in non-volatile memory so that BFree-core can fetch it when power is restored. The shield’s microcontroller also acts as a memory controller, so that a valid checkpoint of the CircuitPython program is always available, even if power fails while creating a new checkpoint!
Additionally, the shield houses the energy harvesting system needed to provide BFree with bursts of energy. A capacitor on the board is connected to an energy harvesting source, such as a solar panel. The harvesting source will slowly charge the capacitor. When the voltage of the capacitor reaches a (configurable) threshold, a boost converter is enabled to supply the rest of BFree with constant 3.3V supply. When an on-board BFree comparator notices that the boost converter cannot maintain the target voltage of 3.3V, the boost converter is disabled, power to the Metro M0 is cut, and the charge cycle starts again.
To protect BFree from a harvesting source that produces too much energy, i.e. greater than 3.3V, the shield is equipped with over-voltage protection circuitry. This circuit dumps any surplus energy in a power resistor located on the back of the shield. This way, no energy is lost during typical operating conditions