I'm trying to do a project where several aggregated data sources are displayed on a LCD at regular intervals (500ms). I want to use a timer which breaks out of the main program loop to access the LCD to display this data. The strange thing is that it works OK to have the timer interrupt blink a LED on pin 13 at regular intervals, or have the timer interrupt print something on the serial output.
However as soon as I put a LCD function (lcd.print, lcd.clear, or anything else) the program 'freezes'.
I'm using the TimerThree library on an Arduino Mega. Below the bare minimal code which reproduces the problem:
#include <TimerThree.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27,20,4);
void setup()
{
Serial.begin(9600);
lcd.init();
lcd.backlight();
pinMode(13,OUTPUT);
Timer3.initialize(500000);
Timer3.attachInterrupt(updateLCD);
}
void updateLCD()
{
digitalWrite(13,digitalRead(13)^1);
Serial.println("Timer");
lcd.setCursor(0,0); //when inserted this line no more blinking of LED and Serial output
}
void loop()
{
}
Any suggestions?