Python Forum

Full Version: Show real time temperature and storage with Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
>>> data = b'27.39 27.22\r\n'
>>> data.decode()
'27.39 27.22\r\n'
>>> print(data.decode())
27.39 27.22

>>>
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 ?
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()
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.