Recent

Author Topic: Polling GPIO ports from worker threads / GPIO interrupt (rpi - PXL)  (Read 2767 times)

Tibb

  • New Member
  • *
  • Posts: 26
Hello,

How much millisecond pass while getting from the first read to the last one? Is there any advantage using more threads for this purpose?

Code: Pascal  [Select][+][-]
  1. procedure Tthread.Execute;
  2. begin
  3.    while not terminated do begin
  4.       rPINs.vPIN01 := GPIO.GetPinValue(PIN01);  //1..20 logical PIN numbering
  5.       rPINs.vPIN02 := GPIO.GetPinValue(PIN02);
  6.       rPINs.vPIN03 := GPIO.GetPinValue(PIN03);
  7.       ...
  8.       rPINs.vPIN20 := GPIO.GetPinValue(PIN20);
  9.  
  10.       synchronize();
  11.    ...
  12.    end;
  13. ...
  14. end;
  15.  

If im using more threads, should i use a separate TFastGPIO (PXL) instance for every thread or i can call method GetPinValue of the same TFastGPIO instance from more concurrently running threads?

What about interrupts? Is there any way to handle GPIO interrupts with Pascal/Lazarus?

Thank You.
« Last Edit: March 26, 2017, 11:02:00 am by Tibb »

ykot

  • Full Member
  • ***
  • Posts: 141
Re: Polling more GPIO ports (rpi)
« Reply #1 on: March 26, 2017, 12:48:38 am »
Using multiple threads could improve latency if you are doing any I/O operations while polling, like writing something to SD card, etc. However, you should be sharing the same TFastGPIO instance between the polling threads. Reading each of the pins should be pretty fast since essentially you are just reading a value from a mapped memory location. If you are using Raspberry PI 2 or later, make sure to compile with "RPi2" define enabled to use better instructions for GPIO.

As for interrupts, I'm not sure you can use them directly from the application; BCM does expose some information for the pins like what pin has changed its value recently, but haven't looked into that.

Tibb

  • New Member
  • *
  • Posts: 26
Re: Polling more GPIO ports (rpi)
« Reply #2 on: March 26, 2017, 10:17:20 am »
Thank You, greatly appreciated.

Tibb

  • New Member
  • *
  • Posts: 26
Re: Polling GPIO ports from worker threads / GPIO interrupt (rpi)
« Reply #3 on: March 26, 2017, 11:01:21 am »
While running my app, i get the message:
Quote
"Cannot open file </dev/mem> for memory mapping"

Running the app with sudo, the application can be started. Is there any way to run without sudo?
User is member of the gpio group, would not be better to use /dev/gpiomem in PXL?

 

TinyPortal © 2005-2018