Untitled
unknown
python
2 years ago
970 B
5
Indexable
import matplotlib.pyplot as plt # wykres
import time # sleep
import serial # port z arduino
ser = serial.Serial("/dev/ttyACM3", 9600, timeout = 1)
tab_temp = [] # zbiór tempertarur
tab_hum = [] # zbiór wilgotności
start_time = time.time()
while time.time() - start_time < 30:
line = ser.readline().decode().split("|")
if line != ['']:
cur_temp = line[1].split(":")
temp = float(cur_temp[1])
cur_temp = line[0].split(":")
hum = float(cur_temp[1])
print("Temperature: ", temp)
print("Humidity: ", hum)
tab_temp.append(temp)
tab_hum.append(hum)
time.sleep(1)
ser.close()
# Plotting the graph
x = range(len(tab_temp)) # Time axis
plt.plot(x, tab_temp, 'orange', label='Temperature')
plt.plot(x, tab_hum, 'blue', label='Humidity')
plt.xlabel('Time (seconds)')
plt.ylabel('Value')
plt.title('Temperature and Humidity')
plt.legend()
plt.show()Editor is loading...