diff options
author | ars <asav1410@gmail.com> | 2020-06-17 15:59:52 +0100 |
---|---|---|
committer | ars <asav1410@gmail.com> | 2020-06-17 15:59:52 +0100 |
commit | f665f78155047838dc924634ebe4128f7add5542 (patch) | |
tree | fa0b6d2fd4a7b26d7fac2d557066044384d33010 /dev_scripts/sds011.py |
Diffstat (limited to 'dev_scripts/sds011.py')
-rw-r--r-- | dev_scripts/sds011.py | 21 |
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) |