Thanks,
I have come a lot further now, in fact I am done with the basic reasearch on
how to do the I/O.
What I found is that the pigpio.pas file found in the lazarus wiki needs
some slight modifications
and then it is perfectly OK to use. No need for any bigger driver than this
to do the RPi2 I/O.

I have added a define for RPi2 and used it thus:

[code]
interface

// The following option controls whether the code is optimized for Raspberry
PI 2.
// Added 2015-10-10 by Bo Berglund following web advice to get it working on
the Pi2 hardware
{$DEFINE RPi2}
...
const
  REG_GPIO = {$IFDEF RPi2} $3F000 {$ELSE} $20000 {$ENDIF};//bcm2835/bcm2836
gpio register 
...
  // Mapping the RPi GPIO pin functions to GPIO I/O, should be here rather
than in user code
  RPI_P3  =  2; //GPIO2
  RPI_P5  =  3; //GPIO3
  RPI_P7  =  4; //GPIO4
  RPI_P8  = 14; //GPIO14
  RPI_P10 = 15; //GPIO15
  RPI_P11 = 17; //GPIO17
  RPI_P12 = 18; //GPIO18
  RPI_P13 = 27; //GPIO27
  RPI_P15 = 22; //GPIO22
  RPI_P16 = 23; //GPIO23
  RPI_P18 = 24; //GPIO24
  RPI_P19 = 10; //GPIO10
  RPI_P21 =  9; //GPIO9
  RPI_P22 = 25; //GPIO25
  RPI_P23 = 11; //GPIO11
  RPI_P24 =  8; //GPIO8
  RPI_P26 =  7; //GPIO7
...
function TIoDriver.MapIo: boolean;
begin
 Result := True;
 {$IFDEF RPi2}
   fd := fpopen('/dev/gpiomem', O_RdWr or O_Sync); // Open the master
/dev/memory device
 {$ELSE}
   fd := fpopen('/dev/mem', O_RdWr or O_Sync); // Open the master
/dev/memory device
 {$ENDIF}
  if fd < 0 then
  begin
    Result := False; // unsuccessful memory mapping
  end;
 //
end;
[/code]

With this in place the standard user pi will have access to the needed
/dev/gpiomem device and no root is required.
I have successfully used several ports to drive a relay board now.


Best Regards, 

Bo Berglund 



-----Original Message-----
From: fpc-other-boun...@lists.freepascal.org
[mailto:fpc-other-boun...@lists.freepascal.org] On Behalf Of Travis Siegel
Sent: den 11 oktober 2015 18:02
To: Other FPC related discussions.
Subject: Re: [fpc-other] [fpc-pascal] Access GPIO pins on RPi2 without root?

You can add any user to any group you like, by using the groupadd program 
in the terminal.  For example,
usermod  -a -G audio pi
would add the pi user to the audio group, allowing them to use audio 
functions without  having to be root or use sudo for the access.
Of course, the usermod command needs to be run as root, either with sudo, 
or as being logged in as root
If you can figure out what group the io pins are in, this could solve your 
problem.

_______________________________________________
fpc-other maillist  -  fpc-other@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-other

_______________________________________________
fpc-other maillist  -  fpc-other@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-other

Reply via email to