LCD corrupt, print time under interrupt

I spend hours to try to find a solution of my problem.
I’m using a LCD 40*4 with a lot of info concerning inside and outside temperature, same for humidity, rain and wind info, also the time and date. (It’s a project to open and close roof window in my greenhouse)
My loop has a 10 sec delay for refreshing values.
I use the interrupt to print the time at one second rate. the first thing I do in my interrupt subroutine, is to re-enable interrupt. Then I print the time and date.
What I suspect is that in a middle of refreshing print, I get an interrupt. At the end of the time routine, the cursor point just after the “seconds”. So going to the standard loop, to continue the normal refreshing process, the cursor position is the one after “seconds” and not the correct one.
As solution, I want to save the cursor position at the beginning of the time routine and restore it at the end.
But I don’t find a ‘’ type of command.

As solution, I want to save the cursor position at the beginning of the time routine and restore it at the end.

The generally accepted solution is to restructure your program so that nothing is done by the interrupt except to set a flag indicting that something has to be done. The actual procedure, in your case the printing, is done by the main program when it spots the fact that the flag has been set.

But I don't find a '' type of command.

The LCD controller does have a command that will tell you the current cursor position - the information is returned along with the busy flag information.

This requires the ability to read information from the LCD controller which is accommodated for but not implemented in the LiquidCrystal library.

Also, the information is returned in the form of a hex address that is related to the location on the screen - but the relationship varies with the screen geometry (16x2, 20x4, etc).


Sounds as if you do not comprehend what the purpose of interrupts is.

Whatever your loop does, it should never "delay()", so that it will be able to determine when each second elapses and do your printing.

The same type of code that checks the time to see when a second has passed (by examining millis() or your RTC), also checks to see when ten seconds have passed to implement your "10 sec delay for refreshing values".

It's just a matter of knowing how to code. :roll_eyes: