summaryrefslogtreecommitdiff
path: root/dev_scripts/sds011.py
diff options
context:
space:
mode:
Diffstat (limited to 'dev_scripts/sds011.py')
-rw-r--r--dev_scripts/sds011.py21
1 files changed, 21 insertions, 0 deletions
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)