I've got a Mega 2560 connecting to a YwRobot I2C backpack on a 20x4 LCD, via pins 20 and 21. The system also uses an Adafruit Ultimate GPS on Serial2, and I'm using the serial monitor via USB. Additionally, I have falling interrupts setup for buttons on pins 2, 3, 18 and 19, using the associated interrupts (0, 1, 5, 4). I'm using the internal pullups for the interrupt pins. I am using the LiquidCrystal_I2C library for driving the LCD display.
Without the LCD being updated in my loop() method, the interrupts work fine, and the GPS works fine. With the LCD being updated in the loop, however, my pin 19 interrupt is being triggered by something (w/o touching the button), about every 300ms. I can write to the LCD just fine in my setup() method (ie, not in loop()) - I do some initialization of the LCD, and that works fine, but when I update the LCD in my loop() (even just a call to lcd.setCursor() will cause the problem), the interrupt on pin 19 is getting fired. It doesn't happen on every data push to the LCD, but it is happening very repeatably at ~300ms. If I set my LCD display update period to every 50ms, it happens every 6th update. If I set it to a 150ms update period, it happens every other update. (Where an update is an lcd.setCursor() followed by an lcd.print(), but either one of those alone will cause the problem.) The LCD works just fine through all of this - its just the triggering of interrupt 4 (pin 19) that is a problem.
Does the I2C do anything w pin 19 or interrupt #4?
I've tried updating the LCD as infrequently as every 10 seconds, just to see if maybe I was running into a timing problem w/ trying to update the LCD too frequently, but it still causes the problem. (Any update rate over 300ms results in the interrupt being triggered on every LCD update cycle.)
I'm kind of at my wit's end on this. If I disconnect the input to pin 19, everything works fine (but, of course, I lose the functionality of the button connected to that pin.
I've tried using an external pull-up on pin 19, as well, with no change in behavior.
Thoughts or suggestions?
Thanks!