Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- # import matplotlib.animation as animation
- # import time
- import serial
- plt.style.use('seaborn')
- fig = plt.figure()
- ax1 = fig.add_subplot(1, 1, 1)
- serial_port = serial.Serial('COM12', timeout=None)
- def temperatureSubData():
- data_start_index = serial_data.find('T') + 1
- data_end_index = serial_data.find('H')
- print('Temperature: ' + serial_data.strip()[data_start_index:data_end_index])
- temperature_collector = serial_data.strip()[data_start_index:data_end_index]
- return temperature_collector
- def humiditySubData():
- data_start_index = serial_data.find('H') + 1
- data_end_index = serial_data.find('P')
- print('Humidity: ' + serial_data.strip()[data_start_index:data_end_index])
- humidity_collector = serial_data.strip()[data_start_index:data_end_index]
- return humidity_collector
- def pressureSubData():
- data_start_index = serial_data.find('P') + 1
- data_end_index = serial_data.find('L')
- print('Pressure: ' + serial_data.strip()[data_start_index:data_end_index])
- pressure_collector = serial_data.strip()[data_start_index:data_end_index]
- return pressure_collector
- def lightSubData():
- data_start_index = serial_data.find('L') + 1
- print('Light: ' + serial_data.strip()[data_start_index:])
- light_collector = serial_data.strip()[data_start_index:]
- return light_collector
- # def realTimePlot():
- #
- # ax1.plot(y, x_temp)
- # time.sleep(0.3)
- temp_co = []
- while 1:
- serial_data = serial_port.readline()
- if serial_data != 0:
- temperatureSubData()
- humiditySubData()
- pressureSubData()
- lightSubData()
- # temp_co.append(temperatureSubData())
- # print(temp_co)
- # animation.FuncAnimation(fig, realTimePlot, interval=300)
- # plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement