Created
July 26, 2021 20:01
-
-
Save johnty/1504d18238b6a4492a269c5f136c6dc2 to your computer and use it in GitHub Desktop.
simple code to poll two SDS011 sensors connected via CH340G USB adapters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sds011 import SDS011 | |
from datetime import datetime | |
import time | |
#CH340G adapters seem to give port names | |
#based on which port you plug them into: | |
s1 = SDS011("/dev/tty.wchusbserial1410") #Left USB Port | |
s2 = SDS011("/dev/tty.wchusbserial1420") #Right USB Port | |
def read_sensor(): | |
#turn on sensors | |
s1.sleep(sleep=False) | |
s2.sleep(sleep=False) | |
#15 seconds for sensor to get ready | |
time.sleep(15) | |
now = datetime.now() | |
current_time = now.strftime("%H:%M:%S") | |
d1 = s1.query() | |
d2 = s2.query() | |
print (current_time+ " # S1: " + str(d1[0]) + " " + str(d1[1]) + " S2: " + str(d2[0]) + " " + str(d2[1])) | |
#turn them off again | |
s1.sleep() | |
s2.sleep() | |
now = datetime.now() | |
current_time = now.strftime("%H:%M:%S") | |
print("Test Start = ", current_time) | |
while True: | |
read_sensor() | |
time.sleep(45) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment