I am doing a rather easy project that many have done before. Here is my hardware setup:
Raspberry Pi 3 w/16GB SD card
DHT11 Temperature Humidity sensor
Raspberry Pi 7" display
I am using Tkinter with Python 2.7 and Adafruit_DHT library.
The code is very basic
from Tkinter import *
import tkFont
import Adafruit_DHT
import sys
import time
temp = 0
win = Tk()
win.title("Temperature")
sans = tkFont.Font(family='FreeSansBold', size=28, weight=tkFont.BOLD)
Label(win, text="Temperature", relief=SUNKEN, width=15, font=sans).grid(row=0, column=0)
Label(win, text="Humidity", relief=SUNKEN, width=15, font=sans).grid(row=1, column=0)
Label(win, text="Date/Time", relief=SUNKEN, width=15, font=sans).grid(row=2, column=0)
def READ():
global temp
humidity, temperature = Adafruit_DHT.read_retry(11, 4)
temp = temperature*9/5.0 + 32
Label(win, text=temp, relief=RIDGE, width=15, fg="black", bg="white", font=sans).grid(row=0, column=1)
Label(win, text=humidity, relief=RIDGE, width=15, fg="black", bg="white", font=sans).grid(row=1, column=1)
Label(win, text=time.strftime("%b %d %I:%M"), relief=RIDGE, width=15, fg="black", bg="white", font=sans).grid(row=2, column=1)
def read_every_second():
READ()
win.after(1000, read_every_second)
win.after(1000, read_every_second)
mainloop()
It works great except that it causes a memory leak. I am sure that it is forcing endless loops with the "win.after(1000, read_every_second) call however, I do not know how to fix it.
Any help would be appreciated.