summaryrefslogtreecommitdiff
path: root/dev_scripts/sds011.py
blob: 98abaa1fd43935ff8c7a7074a723622d4cf3125c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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)