Environmental sensor display

Posted on Sat 05 November 2022 in electronics


This is a Raspberry Pi in a SmartiPi case with an official Raspberry Pi touchscreen. It makes a good simple display! People like looking at it change.

Inside the case there are temperature, humidity, CO2, voltatile organic compounds, and particulate sensors. They're fairly safe in there and have a fan to feed them fresh air. The more sensors you add, the more variety the dashboard has.

A photo of the dashboard active, showing its temperature, humidty, etc gauges

What it looks like

Measuring soldering fumes


Neat stuff

I have the code on GitHub.

Systemd user services

I followed this guide. These services will run the code when the user logs in, so you can have your data logging scripts going right away.

(Services in Linux are like those hundreds on programs you see running in the background in the Windows Task Manager. They're background processes.)

I think that when I upgrade to actual system services (not user-dependant), I'll have a really powerful solution. Shutdown or reboot the computer and everyhting starts up again. It's also possible to have the services restart themselves automatically if they crash or need to restart for whatever reason.

Efficiently reading files

Python reading a file in binary mode can skip to the end of it. So with a CSV you don't need to read the whole thing. This Stack Overflow post shows how.

with open(filename, "rb") as file:
    # Go to the end of the file before the last break-line
    file.seek(-2, os.SEEK_END) 
    # Keep reading backward until you find the next break-line
    while file.read(1) != b'\n':
        file.seek(-2, os.SEEK_CUR) 
    data = file.readline().decode()
data = data.replace("\n", "").split(",")