I've never been a fan of IoT devices for obvious reasons: not only do they tend to be excellent at being expensive vendor locked-in machines, but far too often, they also end up turning into e-waste after a short amount of time. Manufacturers can go out of business or simply decide to shut down the cloud servers for older models, and then you're stuck with a brick.
Well, this all changes today, as I've built my first IoT device and I love it. Introducing pymonitair.
What
pymonitair is a MicroPython project that aims to display weather data from a home weather station (like the ones sold by AirGradient) on a small display.
The source code was written for the Raspberry Pi Pico W, the Waveshare Pico OLED 1.3 display and the RevolvAir Revo 1 weather station, but can be adapted to other displays and stations easily, as I tried to keep the code as modular as possible.
The general MicroPython code itself isn't specific to the Raspberry Pi Pico and shouldn't need to be modified for other boards.
pymonitair features:
- 6 different pages for the supported weather data1, accessible via the
key0
button - Alerting2 on the PM2.5 page when the defined threshold has been crossed
- Automatic screen blanking after a defined amount of time to save the OLED screen from burn-in
- Manual screen blanking using the
key1
button
Here's a demo of me scrolling through the different pages and (somewhat failing) to turn the screen on and off:
Why?
If you follow my blog, you'll know that my last entry was about building a set of tools to collect and graph data from a weather station my neighbor set up.
Why on Earth would I need a separate device to show this data, when the website I've built works perfectly fine and is accessible on any computer or smartphone?
Mostly alerts. When the air quality here dropped following forest fires, I found out keeping track of if I had to close my windows and bunker down was quite a hassle.
Air quality would degrade during the day and I would only notice it hours later. With the pymonitair, I'll have a little screen flashing angrily at me whenever this happens.
A simpler solution would probably have been to forgo hardware altogether and code some icinga2 alert to ping me over Signal whenever the air quality got bad. Hacking on pymonitair was mostly a way to learn to use MicroPython and familiarize myself with this type of embedded hardware device.
I'll surely blog about this later this year, but I plan to use a very similar stack to mod my apartment's HVAC unit to stop pulling air from outside when an air quality sensor detects cigarette smoke (or bad air quality in general).
Things I've learnt
This project was super fun and taught me many things:
-
MicroPython is close enough to regular Python that I don't mind it. The standard library is much smaller, but there are ways to work around that.
-
The Raspberry Pi Pico W is a fantastic board. At around 10 CAD (~7 USD), it's much cheaper than anything Arduino offers, much more powerful than those boards and gives you the option of not having to code in some terrible and weird C variant. It also has a nice ecosystem of compatible modules and hats.
-
Displays, even if they advertise being "batteries included", often are not. I had the bad surprise of discovering the MicroPython driver for the Waveshare Pico OLED 1.3 was pretty bad and lacked a ton of features compared to their C code driver. Thankfully, I was lucky enough that the OLED panel it uses (the SH1107) is common enough for folks to have written their own drivers.
-
thonny, a Python IDE, is probably the best tool to transfer files to the Raspberry Pico and to debug code, as it provides a file manager and a shell3. I'm a little annoyed by it not being vim, but I got used to its quirks fairly quickly.
-
PM1, PM2.5, PM10, Temperature, Humidity and Pressure ↩
-
Part of the screen will flash repeatedly ↩
-
I did look for other solutions to transfer files to the board, but none of them were actually maintained. I nearly finished packaging ampy before realising it was officially unmaintained and its main alternative, rshell, has had its last release in December 2021. When I caught myself seriously considering writing a script to transfer files over the serial link, I gave up and decided thonny was not that bad after all. ↩