0

I have problems with a 2x16 LCD Display controlled via I2C. I use python 2.7 and have a Raspberry Pi Zero W. When called from the main loop everything works fine and I can access the display with

my_lcd.lcd_display_string("test", 1 , 0)

without problems. But when I call the same with a procedure called by interrupt I just get garbage on the LCD and everything is messed up.

The source code is like that

GPIO.setup(TasteHoch, GPIO.IN)  

def SWH( pin ):
   global my_lcd
   my_lcd.lcd_display_string("test", 1 , 0)  


my_lcd = I2C_LCD_driver.lcd()

GPIO.add_event_detect(TasteHoch, GPIO.FALLING, callback=SWH, bouncetime = 200)

The interrupt pin is wired (pull-up with capacitor bebouncing) to a breadboard push button, there are no other interrupts involved. As I checked the interrupt routine is only triggered once per push.

  • We need context. How often are the interrupts generated? Can they interrupt each other? Please EDIT your question to include more detail of what is going on. – joan Mar 4 at 13:35
  • @joan: more details added – A.Schulz Mar 4 at 15:03
  • There is nothing obviously wrong the way you describe. You probably need to add all the code and a photo of your connections to the question. – joan Mar 4 at 15:51
  • @joan: I finally found out, what was going on. The main loop was still executed when running the interrupt-code. So both calls on the I2C were interfering with each other. I have fixed it now by syncing the requests. Does anybody know if the execution of the remaining program can be paused when entering an interrupt routine? – A.Schulz Mar 4 at 17:13
  • I'm a bit surprised that gave a problem. I'd have thought Linux would have made the I2C calls atomic. Perhaps you need to set/clear a flag around the I2C calls and not call the I2C function if the flag is set. – joan Mar 4 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.