Hello arduino giants out there. This a humble doubt form a newbie.
OK to start with, I am using a normal arduino UNO board and I wanted to turn on/off a latching solenoid valve for say 1 hour duration at a frequency of one day.
And the Millis() came in handy to implement this without any fuss. But unfortunately from my observations the arduino millis() is not working after 7.2 hours.
I wanted to test the millis() and i developed a code where in I just diplayed the millis() value on a LCD.Here goes my code
I have also attached a photo of the lcd screen when it got stuck.
My question is, did the lcd get stuck by any means or the controller got stuck. Or can anybody explain me what happened. Even in the worst case of an overflow, the values should have at least been reset to 0. But nothing logical happened.
I request you friends to please help me with a fix and suggest me any reliable alternatives if any.
Does lcd.print() handle long integers properly? I suspect that it doesn't and it's trying to use an int version of that function. The question mark in the middle of the numbers looks very odd. What could put a question mark there?
You sketch does not match with what is shown in the display. You have used a different sketch for that
The first row is '0' and the second row is row '1', you use '2'.
By the way, millis() is working good.
It rolls over after 50 days.
A rollover problem can be avoided when unsigned long variables are used for millis() and it is programmed the right way. It means that you can do the hour delay every day, and will work perfect even when millis() does a rollover.
(While I was typing this, MorganS suspects that lcd.print might not print unsigned long very well. The LiquidCrystal library uses the Print class, which is also used by Serial.print. It should print an unsigned long without problem).
Guys I appreciate your response. But I think I have found something new to bother your minds. When i use an arduino standlaone with its internal RC at 1MHz, and the same program, for the past 74 hours, the program is running as smooth as a ferrari with no glitches. But when ever i used the external clock(16 MHz) for timing, roughly after 9 hours I get a problem.
Can any one give a reasonable justification.
And for your kind information, I have used the same conventional millis() formula. i.e. current -previous. to tackle the overflow issues. Yet I have tried it for nearly six or seven times, I progrmmed the arduino to turn on a relay after 12 hours. But all the six times, it was turned on roughly at 9 hours it self.
And also to add pepper to the soup, the same relay(program) works fine if i program the arduino within 9 hours delay.
Its really strange, there must be some valid reason for this. I am pretty exhausted after hunting down reasons, but none are satisfying.
Please share your experience and suggestions guys.