Raspberry Pi Temperatursensoren Anzeige im Tkinter spinnt

Fragen zu Tkinter.
Antworten
mexxwell
User
Beiträge: 6
Registriert: Sonntag 24. Februar 2013, 14:55

Halli-Hallo,

kann mir bitte jemand sagenw as ich falsch mache? Ich lese bei einem Raspberry Pi 2 Tempsensoren ein, und zeige diese dann in einer Tkinter GUI an (tick und tick2). Solange ich nur einen von beiden aufrufe funktioniert es bestens, rufe ich jedoch beide hintereinander mit tick() und tick2() auf steht die Mühle.
Hat jemand ein Idee? Hier ist der Code:

Code: Alles auswählen

import Tkinter as tk
import ttk
from Tkinter import *
import Image as PIL
import ImageTk
import time
import os
import glob
import time
import math

# Abfrage der Temperatur #

os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')

#base_dir = '/sys/bus/w1/devices/'
#device_folder = glob.glob(base_dir + '10*')[0]
#device_file = device_folder + '/w1_slave'

# 1. Sensor 
def read_temp_raw():
    #f = open(device_file, 'r')
    f = open('/sys/bus/w1/devices/10-0008028e9bb9/w1_slave', 'r')
    lines = f.readlines()
    f.close()
    return lines

def read_temp():
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
        temp_c = float(temp_string) / 1000.0
        temp_f = temp_c * 9.0 / 5.0 + 32.0
        return temp_c
# 2. Sensor
def read_temp_raw2():
    #f = open(device_file, 'r')
    f = open('/sys/bus/w1/devices/10-0008028ea0bf/w1_slave', 'r')
    lines = f.readlines()
    f.close()
    return lines

def read_temp2():
    lines = read_temp_raw2()
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw2()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string2 = lines[1][equals_pos+2:]
        temp_c2 = float(temp_string2) / 1000.0
        temp_f2 = temp_c2 * 9.0 / 5.0 + 32.0
        return temp_c2

main= Tk();
main.title('Toplevel')

##########################################################
# Definition der oberen Umgebungstemperatur Widgets

Label(main,text='Umgebungstemperatur').grid(row=1,column=1)

Grad=Label(main, font=('times', 25, 'bold'), text='             C').grid(row=2,column=1)
Umg_temp_text = Label(main,font=('times', 25, 'bold'), text=read_temp())
Umg_temp_text.grid(row=2,column=1)

image = PIL.open('Ice-icon.png')
photo = ImageTk.PhotoImage(image)
Label(main,image=photo).grid(row=2,column=0)

image2 = PIL.open('Status-weather-clear-icon.png')
photo2 = ImageTk.PhotoImage(image2)
Label(main,image=photo2).grid(row=2,column=2)


##########################################################
# Definition der unteren Innenraumtemperatur Widgets

Label(main,text='Innenraumtemperatur').grid(row=5,column=1)
#Inn_temp_text = Label(main,text='12')
#Inn_temp_text.grid(row=5,column=2)

image3 = PIL.open('Ice-icon.png')
photo3 = ImageTk.PhotoImage(image3)
Label(main,image=photo3).grid(row=6,column=0)

image4 = PIL.open('Status-weather-clear-icon.png')
photo4 = ImageTk.PhotoImage(image4)
Label(main,image=photo4).grid(row=6,column=2)

Grad2=Label(main, font=('times', 25, 'bold'), text='             C').grid(row=6,column=1)
Inn_temp_text = Label(main,font=('times', 25, 'bold'), text=read_temp2())
Inn_temp_text.grid(row=6,column=1)

def tick():
    temp = round(read_temp(),1)
    Umg_temp_text.config(text=temp)
    Umg_temp_text.after(100, tick)
   
def tick2():
    temp2 = round(read_temp2(),1)
    Inn_temp_text.config(text=temp2)
    Inn_temp_text.after(200, tick2)

tick()

tick2()

main.mainloop()
Antworten