0

I have a Python 3 script running on a Raspberry Pi (Buster) which writes some instrument data to my Nextion Display using the serial/UART interface. I have, for now, setup my code to sleep for 5 minutes after the current data are displayed. This working.

The Nextion Display is touch sensitive so that if I touch it, it will send a serial data string which can be read via my script and will tell me where on the screen it was touched.

Now, I would like to modify my code such that it will react to the touch-screen even during the sleep period. I could put the program into a tight loop instead of using time.sleep(300) and check the elapsed time and read the serial port during each loop. This sounds to me like I would be overworking the Pi and wasting CPU cycles. Is there a better way to pause certain sections of code while allowing other to continue?

RDK
  • 355
  • 2
  • 7
  • 24
  • You're not saving CPU cycles by using sleep, so you might as well just poll shorter but more frequently. – Vasili Syrakis Mar 18 '20 at 11:12
  • Thank you for you reply. I guess my question dates me a bit, as I recall issues when accidental tight-loops got me in trouble at the university many years ago. I guess with these little stand-alone computers, that is less of an issue. Again thanks for your comments. – RDK Mar 23 '20 at 16:44

0 Answers0