TIP: Click on subject to list as thread! ANSI
echo: rberrypi
to: EWHOLZ@GMAIL.COM
from: THE NATURAL PHILOSOPHER
date: 2018-02-24 13:29:00
subject: Re: How to use while loop

On 24/02/18 02:41, ewholz@gmail.com wrote:
>   I also plan to look into interrupts, may well be a better way to do the
whole thing.

Interrupts have a steeper learning curve, but they are usually a far
better way to detect events that do in fact trigger them, than polling a
status register.

The problem ytou ahve is that tin a single tasking environment they are
no better.

e.g. in pseudocode
PIN_STATUS=readpin();

Interrupts-service()
 {
 PIN-STATUS-readpin();
// readpin has to be written so it CAN be called from an ISR
 }
will set the status but you haven't really gained anything unless you
have a multitasking environment where the task that monitors the pin
status and might print it out, has been put to sleep...

Interrupts-service()
 {
 PIN-STATUS-readpin();
// readpin has to be written so it CAN be called from an ISR
 resume(sleeping_task_pin_monitor);
//wake up sleepy task to do something in foreground
 }


That is to say that with a single task using a poll loop to do various
things, there is no advantage really to using interrupts to improve the
main loop performance: At that level one uses interrupts solely to 'keep
up' with asynchronous events that might have happened too fast for the
poll loop to detect. E.g. a pin going high and then low between being
polled would not be detected. But by using an ISR and a buffer, to stack
up pin values it would not be missed.

However Linux does have multi-tasking, and multi-threading and although
I am not familiar with the 'Pi' architecture, it should be possible to
write a thread that sleeps until an asynchronous event wakes it up. Cf
'Posix threads'

Nit sure if Python would have the tools though.

Oh. yes it does, Some nice tutorials here:

http://raspi.tv/2013/how-to-use-interrupts-with-python-on-the-raspberry-pi-and-
rpi-gpio-part-3



--
All political activity makes complete sense once the proposition that
all government is basically a self-legalising protection racket, is
fully understood.

--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)

SOURCE: echomail via QWK@docsplace.org

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.