-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (38 loc) · 1.21 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Raspberry Pi Tumbler Code
# EDD 2022 - Condurso Class 7
# Imports
import time
import board
import busio
import pwmio
import adafruit_motor # Servo interfacing
import Adafruit_DHT # DHT20 lib
import adafruit_sgp30 # SGP30 lib
from w1thermsensor import W1ThermSensor, Unit #DS18B20 lib
# Initializes sensors
# TODO: Fix DHT initialization
#dhtDevice = Adafruit_DHT.DHT22(board.D18)
i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)
sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c)
print("SGP30 serial #", [hex(i) for i in sgp30.serial])
tempsensor = W1ThermSensor()
# create a PWMOut object on Pin A2.
# TODO: Determine PWM pin
pwm = pwmio.PWMOut(board.D2, duty_cycle=2 ** 15, frequency=50)
# Initializes servo
servo1 = servo.Servo(pwm)
# MAIN
def main():
# Main loop
while(True):
# Get temperature from DS18B20
tempC = tempsensor.get_temperature()
tempF = tempsensor.get_temperature(Unit.DEGREES_F)
print("TempC = %d \t TempF = %d" % (tempC, tempF))
# Gets eC02 and TVOC from SGP30
eC02 = sgp30.eCO2
TVOC = sgp30.TVOC
print("eCO2 = %d ppm \t TVOC = %d ppb" % (eCO2, TVOC))
# Runs main function
if __name__ == "__main__":
main()