Blathering | Raspberry Pi to Monitor Air Quality with an Arduino based Thermostat

Arduino Test Board.jpg

I’d like to call myself a tinkerer, but I don’t tinker enough hold that badge. I do like to look at other projects and see what is out there for things to make my life more efficient. My target is to make my home, work for me, to automate every aspect that is feasible that has real value to me that will make life a little more efficient and have a bit better resolution on the control of the world around me. One area that needs some work is the HVAC (Heating, Ventilation and Air Conditioning) controls. I have been pondering this for a while and I think I have a good project plan to make my house work for me just a little bit better.

This is just a blathering of a project to come. If you have any thoughts or suggestions, think that this is ridiculous and a waste of time, fire those off too. I’m open. It may not change my mind but it is always worth listening to a dissenting opinion.

Project Goal

I want a home thermostat and environmental control system that is under my control and doesn’t babble off to a cloud someplace. I want it to be intelligent enough to manage the room temperatures, know if a window is open in the house, adjust the dampers in my ducting to cycle air between the floors differently depending on the time of year. I want it to be aware of the current outdoor weather as well.

Why Weather Aware?

Weather Station.jpgI want the system to know how humid it is inside and outside of the house. Much of the summer in Michigan, I don’t need to have the air conditioning on, but I do want to keep the humidity down inside of the house. I also prefer my windows open to closed, so it would be nice if I could have my thermostat would know if windows are open. There is no reason to dehumidify the house when my windows are open.

Targeted Features

The Arduino portion can handle a lot of the functions I am targeting but there is another angle, I am interested in knowing what the pollution is inside the house. I have only dug into this a little bit but the Enviro Raspberry Pi Accessory is able to measure indoor air quality, humidity, pressure, light and noise levels. This could even tell me how effective my filter is too and find the most cost effective filter that does the job. It would allow me to run a Design of Experiments to test and maximize the cleanliness of the air in my home. I don’t know the extent of the on board air quality sensor but it could really do the job.

The Plan

Thermostat.jpgConfigure and build the Arduino thermostat, that is robust, reliable and extensible to control the HVAC system. Once I can do that reliably, I’ll add more sensors to it, window sensor, temperature sensors of different rooms, duct pressure at the blower, then I can start to add automated dampers in the system to control temperature leveling in the house more precisely. Also, to shunt airflow to unused rooms in the house as well during extreme weather conditions. I want to have all the data, inputs, outputs, status and so forth to be accessible on my network so that at any point in time from any computer terminal, I can look at my “environmental system” status. Of course, it will somehow be running openSUSE Linux, someplace. Either a Raspberry Pi running openSUSE or better yet, something x86 based. It’ll be incredibly, joyously nerdy.

Next Steps

For now, I am still gathering information, parts lists and so forth. The first step in this chain will be to replace the thermostat with an Arduino Smart Thermostat that will have better functionality. Once that is working and I have a good understanding of how to manipulate it. I will start to add sensors to it. From there, I’ll figure out my greatest need to further improve efficiency and add the functionality needed.

References

Enviro Raspberry Pi Accessory to Monitor Air Quality at FOSSBYTES.com

Arduino Smart Thermostat

JohnsonControls.com equipment dampers and louvers

RasberryPi Info Center

Rpi3_boardI have a RaspberryPi that is doing absolutely nothing. I got it to dink around with it but it just hasn’t been all that useful to me. I much prefer the x86 platform for, pretty much everything. Not so recently, my church expressed a need for a slideshow like machine for things, events, announcements, pictures and the like. Since I have a Pi3 doing absolutely nothing this sounded like a great fit.

Project Requirements

  • Low or no maintenance device that just rotates through a selection of pictures and a given interval
  • Add and remove content from the directory without the slide show software either skipping or borking
  • Be able to FTP into the Pi to drop pictures onto it.

I downloaded Rasbpian and to play along with the written recommendations, I downloaded the image writer, Etcher.

The Etcher AppImage is built against 32 bit architecture so some additional software was required for openSUSE Tumbleweed on a 64 bit architecture

sudo zypper install libXtst6-32bit libXss1-32bit gconf2-32bit

To start out, I needed to make sure I could remotely access this Pi through Secure Shell. I checked the status of the service

systemctl status ssh

I’m going to pause here just to say, Systemd rocks. What a great service for controlling services on Linux via the terminal. It makes using the terminal on different distributions quite comfortable.

The service was “dead” so I started and enabled the ssh service

sudo systemctl start ssh
sudo systemctl enable ssh

After much searching about, I landed on feh as the application to play a slideshow.

sudo apt-get install feh

To test it out, I needed to transfer some pictures to the Pi. Using my favorite file manager, Dolphin.

File Transfer to RPi

After the files had transferred. Ran a test command to see if it worked

feh -Y -x -q -D 5 -B black -F -Z -r /home/pi/Pictures/

And it worked smashingly… except if I added pictures it wouldn’t automatically update the images displayed and eventually, after taking away too many pictures the application borked. Upon scanning through the man pages…

man feh

I discovered an option,

-R, --reload int

This would allow for reloading the directory at a specified interval, int, in seconds. I set it for 15 seconds and gave it another series of successful tests, adding and removing images remotely.

feh -Y -x -q -D 5 -B black -F -Z -R 15 -r /home/pi/Pictures/

An explanation of the options:

-Y : Hide the mouse pointer

-x : Create borderless window

-q : quite, don’t report non-fatal errors

-D : Delay between slides

-B : background for transparent images “black” is the value

-F : Fullscreen

-Z : Zoom pictures to screen size in full screen

-R : Reload the file list, after a period of time in seconds

-r : Recursively expand any directories in the path

It all behaved just as I had hoped it would, so much so that I had that natural dose of endorphins for this little success. It was good to see that the Pi was doing just what I needed it to do.

Add FTP Service

Since it is likely there will be a Windows machine accessing the Pi, I wanted to make adding and removing images is as simple as possible. The best solution, I find, is to set up an ftp server. I tried using sftp but that is not something the Windows file manager can do.

I decided that I would go with proftp as that is the one for which I am most familiar.

sudo apt-get install proftpd-basic

Checked the status of the server, post install

systemctl status proftpd

The service reported that it was running and active. Should that not be the case for you simply run this to start and enable the service:

sudo systemctl start ssh
sudo systemctl enable ssh

Since this is an internal ftp server on a RaspberryPi with no need for multiple users. The default “pi” user was adequate and I used those credentials for ftp access.

Autostart Slideshow on Boot

I didn’t want to have to have anyone fiddle with the Pi should it lose power. It just needs to work. A script was necessary.

Created the folder bin in the home directory, because, that is just where I like to stick my scripts.

mkdir ~/bin

Changed Directory into that folder

cd ~/bin

Created script with all the right bits in my slideshow

nano slideshow.sh

Copy and paste this into the nano editor

#!/bin/bash

feh -Y -x -q -D 8 -B black -F -Z -R 120 -r /home/pi/Pictures/

Save it: Ctrl+o, Enter

Exit nano: Ctrl+x

Next you have to make the script executable

chmod +x slideshow.sh

Now it is possible to run the command in terminal

Since I want this thing to basically just be an appliance where you plug it in and it just does its thing. I need to make this script run when the RaspberryPi starts up.

To do this, I will use my trusty nano editor to edit the desktop startup

nano ~/.config/lxsession/LXDE-pi/autostart

Scroll to the bottom of this script and add this to the very end:

@/home/pi/bin/slideshow.sh

Save and Exit

Reboot the machine to test.

sudo systemctl reboot

Success.

Disable Screen Blanking

As I was testing the slide show program, I discovered that the screen blanks out after a period of time. That is an unacceptable state for this device. Sure, it makes it energy star compliant but it makes it real hard for people to see information from it. The fix is easy, though, it would have been easier if it was a point and click option in Raspbian.

Back in the terminal:

sudo nano /etc/lightdm/lightdm.conf

Look for the heading

[Seat:*]

At the end of that rather large block of “options” add this line:

xserver-command=X -s 0 -dpms

Reboot the machine and test to see if it performs as expected. For me, this worked exactly as expected and I now call the project complete

Syncthing Addition

In order to keep things a bit simpler for the interested parties. I added Syncthing to the RaspberryPi. Just Syncthing, not the GTK GUI. The problem with the setup was that the browser would open up and cover up the slideshow, which, do an average observer could look like an error. The solution, was another autostart modification:

nano ~/.config/lxsession/LXDE-pi/autostart

I added this line:

@/usr/bin/syncthing/binary -no-browser

Now, should the RaspberryPi be rebooted, the Syncthing WebGUI will not sit in front of feh.

Final Thoughts

I am very glad the Internet exists with so many others describing how they solved their problems. I feel like I cheated because I was able to pick different solutions and mash them up to satisfy my requirements for a properly fitting and robust solution.

RPi3_slideshow

With rebooting the machine, I am rather impressed by how quickly the system goes from off to playing the slide show. A testiment to the work of the RaspberryPi folks hard work.

This was my first RaspberryPi experience and after completing the project, I am mostly happy with the whole process but ultimately, I think I would have preferred setting this all up on an x86 based machine. There were numerous little unique Pi niggles that I found annoying that kind of reminded me of noodling around in Linux circa 2005. At the same time, it was kind of a nice throwback to the last decade in working through a myriad of challenges to have a properly working computer.

For the technical adventurous, I highly recommend playing around with Raspberry Pi devices. It is certainly a great little hobby machine to perform special tasks. At the end of this project, I can think of several other things that I would like to do with a Raspberry Pi or similar device to solve other problems that come to mind.

References

Instructables Easy Raspberry Pi Screensaver Slideshow

Raspbian Download

Etcher

feh – Linux man page

How to Disable the Blank Screen on Raspberry Pi (Raspbian)

ProFTP.org

Geek3D.com Disable the Blank Screen on RaspberryPi