import time from simple_pid import PID from itertools import count import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation import minimalmodbus tempSens = minimalmodbus.Instrument('/dev/ttyUSB0', 1) tempSens.serial.baudrate = 38400 plt.style.use('fivethirtyeight') x_values = [] y_values = [] index = count() def animate(i): try: #temp1 = tempSens.read_float(1, functioncode=4, byteorder=0) / 100 #temp2 = tempSens.read_float(3, functioncode=4, byteorder=0) / 100 #temp3 = tempSens.read_float(5, functioncode=4, byteorder=0) / 100 #temp = tempSens.read_register(1) temp2 = tempSens.read_float(3, functioncode=4) y_values.append(temp2) x_values.append(next(index)) print(tempSens.read_float(11, functioncode=4), end="\t") print(temp2) plt.cla() plt.scatter(x_values, y_values) except Exception as e: print(e) ani = FuncAnimation(plt.gcf(), animate, 2000) plt.tight_layout() plt.show()