DHT read_i2c_block error

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!!!

1 Like

Hey Dexter,

is there nothign known about htat issue?

If i’m only going to read the moisture with an analogRead everything getsx stuck and the same alert appears???

1 Like

The errors indicate a “keyboard interrupt”. (i.e. something like a ctrl-C was pressed")

Are you sure you don’t have a stuck key?  Is something simulating a key-press somewhere?
 

Another thought, and no I’m not being silly here:  Is there something leaning on your keyboard?

No kidding - I had this happen to me.  I’m working on a joystick project for the GoPiGo and - to make room for my (big) joystick/throttle, I pushed my keyboard forward to the front edge of my laptop.  (I’m using an external keyboard and mouse instead of the silly keys on the laptop itself)

After a while, the program would - occasionally - spontaneously abort with some strange errors.  I’d reboot my GoPiGo and the problem would go away.

Eventually it happened so often that something had to be done.  I looked at my hardware configuration, checked jumpers on the GPIO that I was using to do mode-setting, etc. etc. etc.

Eventually I found the problem:
My keyboard had ridden-up onto the keyboard of the laptop and the legs of the external keyboard were pressing random keys!

Boy did I feel like an idiot!  However, I learned something and am now more careful of my keyboard.
 

Just in case the problem is more complex than that, I’m going to ask @cyclicalobsessive, the resident i2c expert, to step in and take a peek.

Did you ever figure out what was happening here?

The keyboard interrupt is coming from me because if i’m running a simple program like this:

import grovepi


#dht_sensor = 4

#[temp,hum] = grovepi.dht(dht_sensor,1)

#print(temp)
#print(hum)

moisture = 0

moist = grovepi.analogRead(moisture)

print(moist)

i’m starting the programm from the command prompt like that:

and it will stay like that for ever until i’m giving him a keyboard interrupt.

everything is plugged in properly and on the right place…

i did the troubleshooting.
is it possible because of the blacklisted i2c? But why is it blacklisted???

i did the installation like described on the dexter homepage.

log.txt (2.9 KB)

any suggestions?

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 185, in transfer
  File "/usr/local/lib/python3.7/dist-packages/Dexter_AutoDetection_and_I2C_Mutex-0.0.0-py3.7.egg/di_i2c.py", line 472, in transfer
  File "/usr/local/lib/python3.7/dist-packages/Dexter_AutoDetection_and_I2C_Mutex-0.0.0-py3.7.egg/di_i2c.py", line 557, in __read__
  File "/usr/local/lib/python3.7/dist-packages/Dexter_AutoDetection_and_I2C_Mutex-0.0.0-py3.7.egg/di_i2c.py", line 607, in __write_byte__
KeyboardInterrupt

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "t.py", line 15, in <module>
    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 $

this is an other example with the same short code shown above.