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?

1 Like
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.

1 Like

Which Pi, and what operating system is running?

If you’re using a Pi-4, that might be part of the problem as the Pi-4 is way too fast for the older Grove-Pi software.

Viz.:

Let us know what’s happening.

The whole case seems strange to me. As i told it was working with the Pi 4 ai also have a Pi 3 B and know as it wasn’t working with the Pi 4 it works with the Pi 3. But it was the same before. I tried in the first time the Pi 4, it worked til a certain point i can’t remember exactly and then i tried the whole thing with the Pi 3 bc in the documentation of GrovePi its only compatible with the Pi 3. and Pi 4 Is like a beta. But then i switched again to the Pi 4. I’ve instelled the system new and flashed the firmwar of the GrovePi again from that moment on it worked again but then again to a later point it started to make problems and stop working finaly. Currently i’m working wth the pi 3 but the Pi 4 seems a lot quicker so i’d like to use that. but i think it is enought for that case… i will tell you guys if i’ll find a solution for that…

but thanks a lot for tying to help!!

1 Like

This does not surprise me.

The Grove Pi software is considerably older than the Pi-4, and may depend on older Python, (etc.) libraries to work.

Note that I am guessing here, but what may have happened is that it worked on the original Pi-4 O/S, then you did an update which updated a critical dependency, and blammo! - it doesn’t work anymore.

This is not unique to the Pi, or even Grove. I’ve had Windows 10 go pear-shaped after an update to the sound drivers, and my installation of Linux Mint sometimes has its quirks.

In this case, my earnest recommendation is to stay with a known-working configuration for now, learn as much about it as possible, and only then try to port it to the latest Pi-4 O/S.

Also note that the architecture of the Pi-4 is sufficiently different that certain things that worked on the earlier Pi versions do not work on the Pi-4 - or work in weird ways. Sorry but that’s the nature of the beast. If you’re interested, look up several videos on YouTube where people tried to install Windows 98 on modern hardware. Needless to say it was, (ahem!), “interesting”, (in the Chinese Curse sense of the word.)

Stick with a known working configuration and save yourself the grief.

Just in case you are wondering why I am suggesting this is because it’s usually best to consider the simplest possibility first.

My logic and thinking here:

  1. The program WAS working before. It stopped for some unknown reason.
  2. Reverting to an older, prior, version of the code also does not work.

Conclusion:
This code is not the problem since both earlier versions that DID work are also failing, something external to your specific code is the problem.

Since both the older version and the new version stopped working at essentially the same time, obviously something changed that is not a part of your code.

Some possibilities are:

  1. Did you modify or change any of the code in the supporting libraries?

  2. Did you do an update to the operating system?

  3. Did you switch to a different version of the Pi?
    The internal architecture of the Pi-4 differs markedly from its predecessors and there are a number of reported cases on the Raspberry Pi forums where the Pi-4 broke existing functionality. This may require changes to your basic config.txt file to improve compatibility.

  4. Did you change operating systems?
    Since Raspbian for Robots is based on Stretch, (for Pi, version 3 or earlier), or Buster, (which includes compatibility for the Pi-4), there may be significant changes in underlying libraries and/or essential API’s that the Grove Pi depend on.

  5. Are you using a compatible version of Python?
    These libraries, and this code may have been written for an earlier version of Python than you have now. (i.e. Python version 2, or an earlier version of Python 3, as later versions of Python are, unfortunately, NOT guaranteed to be backward compatible - Python 8 or 9 breaks compatibility with earlier versions of Python 3, and so on.)

All of these things are possibilities and I would examine them before suspecting the actual code itself. In some cases, like a change in Python, you may need to modify your code - or dependent libraries - to make it work.

If you do that, please share that here and/or create a pull request to the master on GitHub.

Let us know what happens.