im writing a sensor program with python 3 that has a GUI and if the accelerometer detects motions it goes into an interrupt routine and saves and plots the data for a specific timeframe.
Now onto the problem, sometimes when the interrupt routine starts i get an error, sometimes it does not. The error doesnt always stop at the same location, it can stop when it goes into the readACCx/y/z() methods or when it initialises some registers outside of the interrupt routine. Can anyone make sense of the error or what i should do? Thanks already for the help
Here is the error:
interrupt 1
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/usr/lib/python3/dist-packages/pigpio.py", line 1213, in run
cb.func(cb.gpio, newLevel, tick)
File "/home/pi/Masterarbeit/tkinter/mix/mix.py", line 330, in my_callback1
self.pi.i2c_read_byte_data(self.acc_sensor, FF_MT_SRC)
File "/usr/lib/python3/dist-packages/pigpio.py", line 2874, in i2c_read_byte_data
return _u2i(_pigpio_command(self.sl, _PI_CMD_I2CRB, handle, reg))
File "/usr/lib/python3/dist-packages/pigpio.py", line 1011, in _u2i
raise error(error_text(v))
pigpio.error: 'I2C read failed'
Here is my interrupt routine. I know its pretty full but tbh i dont know how to shorten it.
Interrupt routine:
def my_callback1(self, gpio, level, tick): #first interrupt function
print("interrupt 1")
self.pi.i2c_read_byte_data(self.acc_sensor, FF_MT_SRC)
print("interrupt cleared")
print(gpio, level, tick)
self.x_graph = []
self.y1_graph = []
self.y2_graph = []
self.y3_graph = []
a = datetime.datetime.now()
start_time = time.time()*1000
while(time.time()*1000-start_time) < self.timeframe:
try:
b = datetime.datetime.now()
delta = b-a
self.x_graph.append(delta.total_seconds()*1000)
self.y1_graph.append(self.readACCx())
self.y2_graph.append(self.readACCy())
self.y3_graph.append(self.readACCz())
except pigpio.error as e:
print("error:", e)
#time.sleep(1)
#self.save_data()
self.plot_data()