Forum > Embedded

How to access GPIO on RPi

<< < (2/2)

avra:

--- Quote from: Thaddy on January 25, 2021, 11:10:38 am ---Go to the directory where you compiled blinky to and do ./blinky or sudo ./blinky
--- End quote ---
According to https://sourceforge.net/p/asphyre/code/HEAD/tree/trunk/Samples/FreePascal/SingleBoard/RaspberryPI/Blinky/ it seams that Blinkey example should be typed with capital B. Not ideal but that's the way it is.

Koot33:

--- Quote from: Thaddy on January 25, 2021, 11:10:38 am ---Go to the directory where you compiled blinky to and do ./blinky or sudo ./blinky ( I run GPIO code under group rights, more or less as per the above )
Also note the convention is all lowercase, make sure that you keep to that. (Linux will not even execute Blinky if the binary is blinky, contrary to windows and dos)

PS. It is only -5 C, here..

--- End quote ---

OMG!
I knew it was something stupid like that. Thanks!!!

Koot33:
Running
  sudo adduser pi gpio
  sudo adduser pi i2c
  sudo adduser pi spi

Gave me "pi is already a user of xx"

However, I did find this information at some point in the night and emailed it to myself:

--- Quote ---I don't know if this is too late, but in Free Pascal I changed
fd := fpopen('/dev/mem', O_RdWr or O_Sync);
to
fd := fpopen('/dev/gpiomem', O_RdWr or O_Sync);
and that solved the problem
--- End quote ---

Did the trick for me too! The only problem is I don't remember who offered this or where but a big thank you to whoever it was.

PascalDragon:

--- Quote from: Koot33 on January 25, 2021, 08:28:48 pm ---However, I did find this information at some point in the night and emailed it to myself:

--- Quote ---I don't know if this is too late, but in Free Pascal I changed
fd := fpopen('/dev/mem', O_RdWr or O_Sync);
to
fd := fpopen('/dev/gpiomem', O_RdWr or O_Sync);
and that solved the problem
--- End quote ---

Did the trick for me too! The only problem is I don't remember who offered this or where but a big thank you to whoever it was.

--- End quote ---

Ah, yes, that is an important point as well. The access to /dev/mem is limited to root no matter what user/group the device has while /dev/gpiomem was explicitly created to only cover the GPIO area and be useable by the specified user/group of the device file. Thus the former works only with sudo.

MarkMLl:

--- Quote from: PascalDragon on January 26, 2021, 09:13:02 am ---Ah, yes, that is an important point as well. The access to /dev/mem is limited to root no matter what user/group the device has while /dev/gpiomem was explicitly created to only cover the GPIO area and be useable by the specified user/group of the device file. Thus the former works only with sudo.

--- End quote ---

Or by assigning appropriate capabilities to the binary. In any event, don't consider that to be portable: the Linux APIs for GPIO access go either through /sys/class/gpio/* or /dev/gpiochip* (the latter is newer and supposedly higher-performance, but I've not played with it yet).

MarkMLl

Navigation

[0] Message Index

[*] Previous page

Go to full version