Python Forum
Read 2 temperatures in Real Time from Arduino
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read 2 temperatures in Real Time from Arduino
#1
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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Formatting a date time string read from a csv file DosAtPython 5 1,162 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  Non-blocking real-time plotting slow_rider 5 3,455 Jan-07-2023, 09:47 PM
Last Post: woooee
  Real time database satyanarayana 3 1,623 Feb-16-2022, 01:37 PM
Last Post: buran
  Real time data satyanarayana 3 20,323 Feb-16-2022, 07:46 AM
Last Post: satyanarayana
  Real time Detection and Display Gilush 0 1,764 Feb-05-2022, 08:28 PM
Last Post: Gilush
  How to read rainfall time series and insert missing data points MadsM 4 2,124 Jan-06-2022, 10:39 AM
Last Post: amdi40
  Real-Time output of server script on a client script. throwaway34 2 2,011 Oct-03-2021, 09:37 AM
Last Post: ibreeden
  Real Time Audio Processing with Python Sound-Device not working Slartybartfast 2 3,882 Mar-14-2021, 07:20 PM
Last Post: Slartybartfast
  Is there a way to read the time between clicks? penahuse 1 2,435 Jan-30-2021, 10:46 PM
Last Post: Larz60+
Question I can't get my real-time chart with Python (Help!) Bastian_ElProfe 1 2,189 Jan-20-2021, 01:34 PM
Last Post: wostan

Forum Jump:

User Panel Messages

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