Python Forum
Show real time temperature and storage with Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Show real time temperature and storage with Python
#1
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.
Reply
#2
>>> data = b'27.39 27.22\r\n'
>>> data.decode()
'27.39 27.22\r\n'
>>> print(data.decode())
27.39 27.22

>>>
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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 ?
Reply
#4
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()
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  uploading files from a ubuntu local directory to Minio storage container dchilambo 0 398 Dec-22-2023, 07:17 AM
Last Post: dchilambo
  Upload Files to Azure Storage Container phillyfa 6 581 Dec-22-2023, 06:11 AM
Last Post: Pedroski55
  Non-blocking real-time plotting slow_rider 5 3,455 Jan-07-2023, 09:47 PM
Last Post: woooee
  Multiple.ui windows showing at the same time when I only want to show at a time eyavuz21 4 993 Dec-20-2022, 05:14 AM
Last Post: deanhystad
  Help gathering Temperature from API response road102 5 1,019 Dec-16-2022, 08:30 PM
Last Post: road102
  PIL Image im.show() no show! Pedroski55 2 927 Sep-12-2022, 10:19 PM
Last Post: Pedroski55
  How to change UTC time to local time in Python DataFrame? SamKnight 2 1,527 Jul-28-2022, 08:23 AM
Last Post: Pedroski55
  python basemap, cant show the right coordinates dbsr 0 939 Jun-08-2022, 01:55 PM
Last Post: dbsr
  Real time database satyanarayana 3 1,623 Feb-16-2022, 01:37 PM
Last Post: buran
  Real time data satyanarayana 3 20,233 Feb-16-2022, 07:46 AM
Last Post: satyanarayana

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020