Hey guys!
i’m working an a project for my school. Underneath you’ll see my errors:
It worked very well, till a moment i don’t remember exactly. I think it has something to do with threading. After this error happened, also the simpliest code isn’t working anymore.
pi@raspberrypi:~/Desktop $ python3 t.py ^CTraceback (most recent call last): File> >"/usr/local/lib/python3.7/dist-packages/grovepi-1.4.1-py3.7.egg/grovepi.py", line 227, in >read_i2c_block File “/usr/local/lib/python3.7/dist-packages/Dexter_AutoDetection_and_I2C_Mutex->0.0.0-py3.7.egg/di_i2c.py”, line 373, in read_list File “/usr/local/lib/python3.7/dist->packages/Dexter_AutoDetection_and_I2C_Mutex-0.0.0-py3.7.egg/di_i2c.py”, line 129, in transfer File >"/usr/local/lib/python3.7/dist-packages/Dexter_AutoDetection_and_I2C_Mutex-0.0.0->py3.7.egg/di_mutex.py", line 48, in acquire KeyboardInterrupt
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File “t.py”, line 5, in [temp,hum] = grovepi.dht(dht_sensor, 0) File >"/usr/local/lib/python3.7/dist-packages/grovepi-1.4.1-py3.7.egg/grovepi.py", line 335, in dht File >"/usr/local/lib/python3.7/dist-packages/grovepi-1.4.1-py3.7.egg/grovepi.py", line 242, in >read_identified_i2c_block File “/usr/local/lib/python3.7/dist-packages/grovepi-1.4.1->py3.7.egg/grovepi.py”, line 232, in read_i2c_block KeyboardInterrupt
my whole code:
import time
import datetime
import grovepi
import tkinter
from tkinter import messagebox
from tkinter import ttk
from tkinter import *
import threading
import sys
import math
#############################################################
#definition global variables
global str_temp
global str_hum
global str_moist
global thresh
global watered
global stop_thread
global button_status
#############################################################
#define some start values
thresh = 300
stop_thread = True
watered = False
#############################################################
#connect senosrs/actors
#connect grove LEDS to digital ports (green=7), (red=8)
green = 7
red = 8
#connect button tu digital port D2
button = 2
button_status = grovepi.digitalRead(button)
#connect relay to digital port D3
relay = 3
#connect dht sensor(temperature and humidity) to digital port D4
dht_sensor = 4
#connect moisture sensor to analog port A1
moisture = 1
#############################################################
#define pin modes
grovepi.pinMode(green, "OUTPUT")
grovepi.pinMode(red, "OUTPUT")
grovepi.pinMode(relay, "OUTPUT")
grovepi.pinMode(button, "INPUT")
#############################################################
#define functions
def on_closing():
close_gui = tkinter.messagebox.askquestion("Diplomarbeit Stanislav Shubenok", "Programm beenden?")
if close_gui == "yes":
grovepi.digitalWrite(relay, 0)
grovepi.digitalWrite(green, 0)
grovepi.digitalWrite(red, 0)
root.destroy()
else:
return
#############################################################
def green():
grovepi.digitalWrite(green, 1)
def red():
grovepi.digitalWrite(red, 1)
#############################################################
def emergency_stop():
while True:
button_status = grovepi.digitalRead(button)
if button__status == 0:
continue
else:
grovepi.digitalWrite(relay, 0)
grovepi.digitalWrite(green, 0)
grovepi.digitalWrite(red, 0)
root.destroy()
#############################################################
def stop_thread():
global stop_thread
stop_thread = False
def reset_stop_thread():
global stop_thread
stop_thread = True
#############################################################
def automatic():
return
#############################################################
def getdata():
stop_thread()
reset_stop_thread()
underlabel.config(text="Daten werden jede Sekunde aktualisiert")
time.sleep(3)
while True:
if not stop_thread:
break
else:
[temp,hum] = grovepi.dht(dht_sensor, 0)
mosit = grovepi.analogRead(moisture)
str_temp = str(temp)
str_hum = str(hum)
str_moist = str(moist)
named_tuple = time.localtime()
time_string = time.strftime("%H:%M")
second = tim.time()
local_time = time.ctime(second)
middleLabel1.config(text=str_temp)
middelLabel2.config(text=str_hum)
middleLabel3.config(text=str_moist)
upperLabel.config(text=local_time)
underLabel.config(text="")
time.sleep(1)
#############################################################
def manually():
stop_thread()
moist = grovepi.analogRead(moisture)
if (moist > thresh):
grovepi.digitalWrite(relay, 0)
underLabel.config(text="die Erde ist noch feucht")
reset_stop_thread()
time.sleep(3)
threadin.Thread(target=getdata).start()
else:
underLabel.config(text="es wird 5 Sekunden lang bewässert")
grovepi.digitalWrite(relay, 1)
time.sleep(5)
grovepi.digitalWrite(relay, 0)
underLabel.config(text="Bewässerung beendet")
reset_stop_thread()
time.sleep(2)
threading.Thread(target=getdata).start()
#############################################################
def read_button():
while True:
button_status = grovepi.digitalRead(button)
if button_status == 0:
print("nicht gedrückt")
else:
print("gedrückt")
#############################################################
#--------------------------main programm-------------------
root= tkinter.Tk()
root.wm_title("Diplomarbeit Stanislav Shubenok")
root.config(background="#C4C4C4")
#root.attribute('-zoomed')
root.geometry("400x400")
outerFrame = tkinter.Frame(root, bg="#000000", pady=10, padx=5)
outerFrame.pack(pady=1, padx=1)
mainFrame = tkinter.Frame(outerFrame, bg="#FFFFFF", pady=10, padx=5)
mainFrame.pack(pady=1, padx=1)
upperLabel = tkinter.Label(mainFrame, text=local_time, bg="#FFFFFF", font=('Arial', '20'))
upperLabel.grid(row=0, column=0, columnspan=3, pady=10, padx=5)
underLabel = tkinter.Label(mainFrame, text="Infos Hier", bg="#FFFFFF", font=('Arial', '20'))
underLabel.grid(row=0, column=4, columnspan=3, pady=10, padx=5)
leftLabel1 = tkinter.Label(mainFrame, text="Temperatur:", bg="#FFFFF", font=('Arial', '20'))
leftLabel1.grid(row=1, column=0, pady=10, padx=5)
leftLabel2 = tkinter.Label(mainFrame, text="Luftfeuchtigkeit:", bg="#FFFFFF", font=('Arial', '20'))
leftLabel2.grid(row=2, column=0, pady=10, padx=5)
leftLabel3 = tkinter.Label(mainFrame, text="Erdfeuchtigkeit", bg="#FFFFFF", font=('Arial', '20'))
leftLabel3.grid(row=3, column=0, pady=10, padx=5)
middleLabel1 = tkinter.Label(mainFrame, text=str_temp, bg="#FFFFFF", font=('Arial', '20'))
middleLabel1.grid(row=1, column=1, pady=10, padx=5)
middleLabel2 = tkinter.Label(mainFrame, text=str_hum, bg="#FFFFFF", font=('Arial', '20'))
middleLabel2.grid(row=2, column=1, pady=10, padx=5)
middleLabel3 = tkinter.Label(mainFrame, text=str_moist, bg="#FFFFFF", font=('Arial', '20'))
middleLabel3.grid(row=3, column=1, pady=10, padx=5)
B_getdata = tkinter.Button(mainFrame, text="Daten aktualisieren", bg="#FFFF00", width=15, font=('Arial', '20'), command=lambda:threading.Thread(target=getdata).start())
B_getdata.grid(row=1, column=2, pady=10, padx=5)
B_automatic = tkinter.Button(mainFrame, text="Automatisch", bg="#00FF00", width=15, font=('Arial', '20'), command=lambda:threading.Thread(target=automatic).start())
B_automatic.grid(row=2, column=2, pady=10, padx=5)
B_manually = tkinter.Button(mainFrame, text="Manuell", bg="#0088FF", width=15, font=('Arial', '20'), command=lambda:threading.Thread(target=manually).start())
B_manually.grid(row=3, column=2, pady=10, padx=5)
threading.Thread(target=getdata).start()
root.protocol("WM_DEKETE_WINDOW", on_closing)
root.mainloop()
sys.exit("Ein Fehler ist aufgetreten, das Programm wurde geschlossen.")
even if i’ll try to execute this it doesn’t work:
import grovepi
dht_sensor = 5
[temp,hum] = grovepi.dht(dht_sensor, 0)
print(temp)
and if i’m going to execute kind of the same just with tha moisture sensore, the error is still the same.:
import grovepi
dht_sensor = 5
moisture = 1
moist = grovepi.analogRead(moisture)
#[temp,hum] = grovepi.dht(dht_sensor, 0)
print(moist)
pi@raspberrypi:~/Desktop $ python3 t.py ^CTraceback (most recent call last): File “/usr/local/lib/python3.7/dist-packages/grovepi-1.4.1-py3.7.egg/grovepi.py”, line 228, in read_i2c_block KeyboardInterrupt
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File “t.py”, line 7, in moist = grovepi.analogRead(moisture) File “/usr/local/lib/python3.7/dist-packages/grovepi-1.4.1-py3.7.egg/grovepi.py”, line 261, in analogRead File “/usr/local/lib/python3.7/dist-packages/grovepi-1.4.1-py3.7.egg/grovepi.py”, line 242, in read_identified_i2c_block File “/usr/local/lib/python3.7/dist-packages/grovepi-1.4.1-py3.7.egg/grovepi.py”, line 232, in read_i2c_block KeyboardInterrupt pi@raspberrypi:~/Desktop $ ^C
i’ve searched in multiple forums, but somehow non of the mostly similar problems that had solutions, helped me…
Would be great if someone could tell me what i’m making wrong…
THANKS A LOT!!!