Inspired by a post on Mastodon and this related blog post, I decided to build myself an environment logger to get some solid data on how cold my office is, so I can argue to get the thermostat set a little higher.
I started out getting the Raspberry Pi Pico, Adafruit PiCowbell Adalogger for Pico - MicroSD, RTC & STEMMA QT and BME280 as listed in the linked blog post, but then added a PiicoDev OLED Display Module to show temperature logging in real-time.
Started out by soldering some female headers onto the Adalogger and got a CR1220 battery for it., plugged them together, and then used some PiicoDev cables to connect the display and daisy-chain onto the BME280, which came with a Qwiic connect header that isn’t shown in the product page. (I had ordered a PiicoDev adapter that I didn’t end up requiring for this project).
The Getting Started for PiicoDev article got me up and running in Thonny for Micropython, and with a few stops and starts along the way, I have it all talking together and working nicely
This is the display I have running, showing the last 90 temperature readings.
Source code is here.
Thanks to the forum members who provided suggestions and guides that helped me get this all working!
Oh, just one extra thing was required - To set the clock I used Adafruit’s example code
set_time = False
if set_time: # change to True if you want to write the time!
# year, mon, date, hour, min, sec, wday, yday, isdst
t = time.struct_time((2023, 3, 6, 11, 05, 00, 1, -1, -1))
# you must set year, mon, date, hour, min, sec and weekday
# yearday is not supported, isdst can be set but we don't do anything with it at this time
You need to change set_time to True in order to actually set the time.
wday is 0 for Sunday, 1 for Monday, etc.
This looks really slick, nice work! As a cold weather enjoyer I don’t share your desire for warm thermostats, but I admire the desire to get the truth on temperature!
What are the ceil and floor functions doing? I am not familiar with these.
ceil(float) returns the rounded-up integer (the “ceiling” function), while
floor(float) returns the rounded-down integer (the “floor” function).
So if your float value from the temperature sensor is say, 21.4230094830283047, then
ceil() will give you 22 and
floor() will give you 21.
While if the highest value in your list is 21.004506, and the lowest value is 20.9999573849, then from my code
readings.maxim() will return 22 and
readings.minim() will return 20.
Code repository has been updated to actually use the RTC clock, rather than starting from 2020-01-01 00:00:00.000 on every boot when running just on power rather than via Thonny.
There’s also a little code snippet to set the RTC from localtime when run via Thonny.