Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
614 B
3
Indexable
Never
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

# Define GPIO pin
PPD42_PIN = 17

GPIO.setup(PPD42_PIN, GPIO.IN)

def get_dust_data():
    dust_data = 0

    # Read the digital output from the PPD42
    for _ in range(30):  # Read for 30 seconds
        dust_data += GPIO.input(PPD42_PIN)
        time.sleep(1)

    return dust_data

try:
    while True:
        dust_measurement = get_dust_data()
        print(f"Dust Measurement: {dust_measurement}")
        time.sleep(10)  # Wait for 10 seconds before the next measurement

except KeyboardInterrupt:
    GPIO.cleanup()
Leave a Comment