From f665f78155047838dc924634ebe4128f7add5542 Mon Sep 17 00:00:00 2001 From: ars Date: Wed, 17 Jun 2020 15:59:52 +0100 Subject: Initial commit --- dev_scripts/sds011.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 dev_scripts/sds011.py (limited to 'dev_scripts/sds011.py') diff --git a/dev_scripts/sds011.py b/dev_scripts/sds011.py new file mode 100644 index 0000000..98abaa1 --- /dev/null +++ b/dev_scripts/sds011.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +import serial, time + +# SDS011 air quality sensor +ser = serial.Serial('/dev/ttyUSB0') + +while True: + data = [] + for index in range(0,10): + # read sensor + datum = ser.read() + data.append(datum) + + # extract bits 2 and 3 for PM2.5 and divide by 10 to get micrograms per metre^3 + pmTwoFive = int.from_bytes(b''.join(data[2:4]), byteorder='little') /10 + # extract bits 4 and 5 for PM10 and divide by 10 to get micrograms per metre^3 + pmTen = int.from_bytes(b''.join(data[4:6]), byteorder='little') /10 + print(pmTwoFive) + print(pmTen) + time.sleep(10) -- cgit v1.2.3