GPIO app launches as Root but not as Pi

I’m having terrific success with all kinds of Pi projects, however I’m not sure what’s going on with possible hangs on app launch with GPIO. If I log in as Root then I can launch and use apps that use the GPIO module (and they work great!). However, when I log into Pi as user ID of ‘Pi’, then launching GPIO-based apps fails. The failure is simply that the app doesn’t launch, and seems to immediately and quietly die.

Under both the Root and Pi login these two commands return the same good results:

gpio -v
gpis readall

I’d seen a note on http://wiringpi.com regarding “export WIRINGPI_GPIOMEM=1” and I’m not 100% certain I know what that does - however I ran it and it doesn’t seem to remedy the issue.

Thanks for any help!

Best regards,
-Bill

Linux raspberrypi 4.4.11-v7+ #888 SMP Mon May 23 20:10:33 BST 2016 armv7l GNU/Linux

Raspberry Pi Details:
Type: Pi 3, Revision: 02, Memory: 1024MB, Maker: Embest

  • Device tree is enabled.
  • This Raspberry Pi supports user-level GPIO access.
    -> See the man-page for more details
    -> ie. export WIRINGPI_GPIOMEM=1

I’m hardly and expert on GPIO since I have had no need of it in the past four years.

That needs to be in the profile so it is there every boot. You also need to make sure the kernal module is loaded:

http://wiringpi.com/wiringpi-update-to-2-29/

Solved it with some trial/error and Bob’s tip.

I was able to get the app running by going to it’s folder (in an X GUI window) and using the “File Manager > Tools > Run a Command in the Current Folder…”

Instead of simply executing “./MyAppName” I entered “sudo ./MyAppName”, and this made it launch with full GPIO access. I didn’t have to edit any files or make any Profile entries etc.

Using this info I created both a .desktop (shortcut) and an entry into the ‘autostart’ file.

For the desktop file instead of using…

Exec=/home/pi/Desktop/MyAppName

…I used:

Exec=sudo /home/pi/Desktop/MyAppName

…so this let’s me have a simple double-clickable shortcut on my pi-user desktop.

I also wanted it to launch on login by pi-user, so I edited:

/home/pi/.config/lxsession/LXDE-pi/autostart

…and added this line:

@sudo /home/pi/Desktop/MyAppName

That’s it, it all seems to work fine.

Editing /etc/rc.local is recomended for autostarting applications.
Read more here:
Raspberry Pi Foundation rc.local usage