Python module for reading CO2 concentration from a Senseair S8 sensor connected to a Raspberry Pi
Hook up the Senseair S8 to your Raspberry Pi using the following schematic:
Image source: http://co2meters.com/Documentation/AppNotes/AN168-S8-raspberry-pi-uart.pdf
pip install senseair-s8As a module:
from senseair_s8 import SenseairS8, SenseairS8Exception
sensor = SenseairS8()
try:
co2 = sensor.co2()
print(f"CO2 concentration: {co2} ppm")
except SenseairS8Exception as e:
print(f"Failed to read CO2: {e}")From the command line (this logs the CO2 concentration at ~1 second intervals):
python -m senseair_s8- This module expects the sensor to be connected to port
/dev/ttyS0. It was only tested using that port, but you can override this setting when initializing the sensor:
sensor = SenseairS8(port='/dev/ttyS0')- Out of the box,
/dev/ttyS0is disabled on a Raspberry Pi, resulting in apermission deniederror. You can enable it by:- Run
sudo raspi-config - Select Interfacing options
- Select P6 Serial
- Select No for login console
- Select Yes for serial port hardware
- OK, Finish, Reboot - Yes
- Run