Show real time temperature and storage with Python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Show real time temperature and storage with Python (/thread-20738.html) |
Show real time temperature and storage with Python - linkxxx - Aug-28-2019 import serial import matplotlib.pyplot as plt from drawnow import * values = [] plt.ion() cnt=0 serialArduino = serial.Serial('COM3', 115200) def plotValues(): plt.title('Serial value from Arduino') plt.grid(True) plt.ylabel('Values') plt.plot(values, 'rx-', label='values') plt.legend(loc='upper right') #pre-load dummy data while True: while (serialArduino.inWaiting()==0): pass valueRead = serialArduino.readline() print(valueRead)I'm getting the temperatures like this: --------------------------------------- b'27.39 , 27.22\r\n' b'27.35 , 27.27\r\n' b'27.44 , 27.33\r\n' b'27.41 , 27.37\r\n' b'27.39 , 27.33\r\n' ------------------------------------------------- How I can fix this error and get clean result, and also how I can graph in real time and storage the data? Thank you so much for the help. RE: Show real time temperature and storage with Python - buran - Aug-28-2019 >>> data = b'27.39 27.22\r\n' >>> data.decode() '27.39 27.22\r\n' >>> print(data.decode()) 27.39 27.22 >>> RE: Show real time temperature and storage with Python - linkxxx - Aug-28-2019 Thank you so much for the answer, but if I I wanna decode not on the shell but inside the module, how I have to write ? RE: Show real time temperature and storage with Python - buran - Aug-28-2019 my example is in the console because I cannot reproduce your code with Aurdino. Use decode() e.g. line 25 should be print(valueRead.decode())note thar you will get 2 new lines after each printed value because of \r\n if you want to remove these, use strip(), e.g. valueRead.decode().strip()
RE: Show real time temperature and storage with Python - linkxxx - Aug-28-2019 really thank you so much for the help, now it's appearing really well. I will try to fix now the part about the graph, because I defined, but I don't get. |