I have a python code that runs when the Raspberry Pi boots up using crontab. It is something like this:
import time while True: # beginning of the loop loop_start_time = time.time() # to print the time in the shown format print time.strftime("%Y-%m-%d %H:%M:%S") # do a few things that may take some time, but not more than 10 seconds # control the delay if time.time()>10: pass else: time.sleep(10 - (time.time() - loop_start_time))
If I run the same code on PC, it will give me the exact timing and a perfect increment of 10 seconds for every loop : e.g I will get 10:24:04 when I start the program. If I come back next day at exactly the same time it will still give me the same without changing to 10:24:05 for example.
However, when I implemented this on Raspberry Pi, I found that the seconds increment every around 20 mins, e.g 10:24:04 -> 10:44:05. How should I deal with this? What is the reason and how do I eliminate this problem? I want it to be show perfect timing.