Python Forum

Full Version: Read 2 temperatures in Real Time from Arduino
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Guys sorry if I'm disturbing again, but I am not able to find the errors on my code, how you can see in the picture attached I'm able to show the temperatures, but are not the correct values, after the measurement my temperature is always around 24.78 24,9 Degrees, and also when I save the file in csv is encode, how I can decode?
import serial

import numpy as np

import adafruit_max31856

import matplotlib.pyplot as plt

from drawnow import *

import datetime

import math

import csv

Temp1= []

Temp2=[]

plt.ion()

cnt=0

def makeFig():

plt.title('My Super Beautiful Live Streaming Sensor Data :-)')

plt.grid(True)#Turn the grid on

plt.xlabel('Time') #set xlabels

plt.ylabel('Temperature') #Set ylabels

plt.plot(Temp1, 'ro-',label='Temp1') #plot the temperature

plt.plot(Temp2, 'b^-',label='Temp2')

plt.legend(loc='upper right') #plot the legend

plt.show()

## user-defined params

serialPort = 'COM3'

path = 'C:\\Users\\Alphinity\\Desktop\\python3\\'

outputFile = "signalSerial.csv"

ser = serial.Serial('COM3', 115200)

outputFile = path + outputFile

f = open(outputFile,'w')

f.write(outputFile)

f.close()

print ("Writing the serial stream into file: " + outputFile)

print (" [to see the stream: tail -f '+outputFile+' ]")

print (" [to exit: ctrl+c (the elegant way :) ]")

while True:

line = ser.readline()

string = line

Temp1.append(string[0])

Temp2.append(string[1])

drawnow(makeFig)

plt.pause(.000001)

cnt=cnt+1

if(cnt>50):

Temp1.pop(0)

Temp2.pop(0)

if (string != ''):

f = open(outputFile, 'a')

f.write(str(string))

f.write("\n")

f.close()

print(string.decode())

valueRead.decode().strip()