-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbidirectionalcommarduino.py
More file actions
23 lines (22 loc) · 962 Bytes
/
Copy pathbidirectionalcommarduino.py
File metadata and controls
23 lines (22 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import serial
import time
if __name__=="__main__":
ser=serial.Serial('/dev/ttyACM2',baudrate=9600,timeout=1) #definiamo la connessione seriale con l'arduino sulla porta,con bump 9600 e delay di 1 secondo
ser.flush() #flushiamo il buffer
print("eseguo")
while(True):
time.sleep(1)
if (ser.in_waiting>0):
#line1=ser.readline().decode("utf-8").rstrip()
#print(line1)
temperature=ser.readline().decode("utf-8").rstrip()
newtemperature=int(float(temperature))
humidity=ser.readline().decode("utf-8").rstrip()
newhumidity=int(float(humidity))
print(f"TEMPERATURE:{newtemperature} HUMIDITY:{newhumidity}%")
if (newtemperature>=23):
print(f"MAGGIORE >20 {temperature}")
ser.write(b"light\n")
else:
print(f"MINORE <20 {temperature}")
ser.write(b"off\n")