I know, I’ve been absent so long that you’ve probably given up on me! However, I have been doing some Python coding with my lovely little air quality set-up which measures the VOCs (Volatile Organic Compounds) in the air in my study room.
I bought the sensor from: Pimoroni BME 680 air quality and decided to get a Pimoroni small form factor Breakout Garden* and an LED matrix, with 11 x 7 white LEDs, to show the results in an graphic way. I had a Pi Zero WH (Wi fi enabled and with male Header) already, to attach the Breakout Garden to, which I’d taken from a previous project so all I needed then was a micro SD card from my local supermarket.
*I used the Breakout Garden because, with no soldering needed, it was easy to get up and running quickly. It also looks beautiful which I appreciate!
The python program indoor-air-quality.py was in the linked Python Library from:
Pimoroni BME 680 Air Quality and was just what I needed so I was able to get started.
Costs were roughly: £
Pi Zero WH 13.00
Micro SD card 9.00
Breakout Garden 9.50
11 x 7 LED Matrix 9.00
Booster header* 2.00
You may also need a £5 set of Pi Zero adapters, which can be used again and again, and a USB hub so that you can connect a wired keyboard and mouse.
After an initial trial to check the BME680 was working OK, I realised there was a lot to know and found this: Forum post on air quality in which Sandy J Macdonald explains in detail how to use the BME680.
Next my task was to get the result from the BME680 and show it on the LED matrix. Again there’s a link to the Python Library for the LED matrix from: 11×7 LED matrix and I cobbled together bits of code to get a circle which I could put a smiley mouth in when the air quality was good.
Air Quality good
I decided to just stick with a blank face when the air quality was bad. (My Python’s not great yet so I don’t want to run before I can walk!)
Air Quality bad
So I defined a function called face which could be used within the code to do the graphics.
Here’s my code. It’s not great, but remember I’m a newbie to python!
from matrix11x7 import Matrix11x7
matrix11x7 = Matrix11x7()
# Avoid retina-searage!
n = 400
pi_over180 = 3.14159265/180.0
radius = 2
angle = 1
i = 0
for i in range(n):
timestep = 360/n
localx = (math.cos(angle*pi_over180)*radius*2)
localy = (math.sin(angle*pi_over180)*radius*2)
localx = int(localx)+ 5
localy = int(localy)+ 3
matrix11x7.set_pixel(localx, localy, 0.5)
angle = angle + timestep
# If air quality good, light up smile!
if air_quality > 89.9:
matrix11x7.set_pixel(4, 3, 0.5)
matrix11x7.set_pixel(5, 4, 0.5)
matrix11x7.set_pixel(6, 3, 0.5)
matrix11x7.set_pixel(4, 3, 0)
matrix11x7.set_pixel(5, 4, 0)
matrix11x7.set_pixel(6, 3, 0)
Also, all the indentations went when I pasted it into here – so if they’re wrong I hold my hands up!
Then I added, at the end of the BME680 part, the statement:
into indoorairquality.py and placed the function, face , in near the top and it worked!
Anyway, I can see me spending happy hours investigating the air quality in my study and messing about with VOCs, such as nail varnish remover, to really understand the topic of air quality.
If you’re doing a similar air quality project please get in touch.
*I’ve added a booster header so the BME680 air quality sensor isn’t so affected by the heating of the Pi Zero.