Thank you very much for your response. I will make these changes to the 
code asap. As for the list teml, I agree it is not implemented well. I plan 
to improve the code as soon as I make these changes.

On Thursday, February 23, 2017 at 1:15:19 AM UTC-6, Eric Afyouni wrote:
>
> Hi,
>
> I've just recently started learning Python and wrote this code to plot 
> temperature data coming from an Arduino Uno over serial to a Raspberry Pi. 
> I've been researching and trying different methods to try and stop the 
> memory leak, but nothing seems to work. I'm not sure if the issue is with 
> plotting or collecting the data. I've slowed down the accumulation, but at 
> this point I need help figuring out what I have done wrong. Any help that 
> can be provided is great. 
>
> import re
> import datetime
> import pyqtgraph as pg
> from PyQt5 import QtCore,QtGui
> import numpy as np
> import serial
> import csv
>
> ser = serial.Serial('/dev/ttyACM0', 9600)
>
> teml = []
> numeric_const_pattern = r'[-+]?(\d+\.\d+|\d+)'
>
> def parser(command):
>     
>     first_bit = re.findall(r'\b[A-Za-z]+',command)
>     command_value = re.findall(numeric_const_pattern,command)
>     
>     decision(first_bit, command_value)
>
> def decision(letter, number):
>
>     cmd_bits = 'Temp', 'X', 'A'
>      
>     if cmd_bits[0] in letter:
>         Temperature_plotting(number[0])
>         del number[:]
>     else:
>         pass
>         
> def Temperature_plotting(temperature):
>     
>     ctim = datetime.datetime.now().time()    
>     resetim = datetime.time(0, 0, 10, 0)
>
>     teml.append(float(temperature))
>
>     if len(teml) >= 1000:
>         
>         with open('daily_temp_data.csv', 'a') as csvfile:
>             fieldnames = ['Date Stamp','Max','Min']
>             writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
>             x = datetime.date.today()
>             max_temp = max(teml)
>             min_temp = min(teml)
>             writer.writerow({'Date Stamp': x,'Max': max_temp,'Min': 
> min_temp})
>     
>         del teml[:]
>
>     return(teml)
>
>    
> pw = pg.plot(clear=True)
> pw.setLabel('left', text='Temp', units='F')
> pw.setLabel('bottom', text='Time', units='n*5sec')
> pw.setTitle('Temperature')
> pw.showGrid(True, True)
> pw.showLabel('left', True)
> pw.showLabel('bottom', True)
> pw.showLabel('top')
> pw.setYRange(20, 100, padding=0)
>            
> while True:
>     
>     if ser.inWaiting:
>         cmd = str(ser.readline())
>         parser(cmd)
>         ser.flushInput()
>         
>     pw.plot(teml[:-1], clear=True)
>
>     pg.QtGui.QApplication.processEvents()
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/f5690285-2ed6-4f8a-b46e-82af1b8e86a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to