I wrote a program using Lazarus and it checks for GPIO2 pin's status every 3 seconds using TProcess component to run a terminal command for retrieving GPIO pin status as follows...

 procedure TForm1.Timer1Timer(Sender: TObject);
    Process1.CommandLine:='gpio -g read 2';

This works great with no issue. However, when I let my program run for several hours or all day, my program starts to freeze or become unresponsive. Probably due to repeatedly calling TProcess over and over again every 3 seconds. I have looked up on the Internet about this and found many options available but a lot of them are too complicated or the libraries just won't work or outdated. So, what is the simplest and not over complicated ways of reading GPIO pin status? fpSystem seems promising but I can't find any code where you capture the return values for the terminal command.


1 Answer 1


Using a WiringPi utility to poll a pin seems inefficient but there are alternatives.

Some years ago I did a survey of libraries and the available Command line tools.

I use raspi-gpio and pigs
e.g. raspi-gpio get 2 returns GPIO 2: level=1 fsel=4 alt=0 func=SDA1
pigs r 2 returns 1

The gpiochip libgpiod interface has a couple of command line tools.
gpioget 0 2 returns 1

The rgpiod daemon should allow your pascal program to access GPIO using the socket interface.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.