Skip to content

drjayvee/gpio-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

GPIO-cli

About

Many RaspberryPi users ask how to use GPIO without being root.

The short answer is that that's not possible.

The slightly longer answer is that GPIO really needs to be run as root. But that doesn't mean your whole python program needs to be run as root. This python module provides a command line interface (CLI) to GPI, so you can call it from shell, like so:

Using GPIO from shell

# Set pin 13 to HIGH, get its value, then set to LOW
sudo python gpiocli.py set 13 HIGH
sudo python gpiocli.py get 13
sudo python gpiocli.py set 13 LOW -q -v
sudo python gpiocli.py cleanup

Using it from python

import subprocess
subprocess.check_call(["sudo", "python", "gpiocli.py", "set", "13", "HIGH"])
subprocess.check_call(["sudo", "python", "gpiocli.py", "get", "13"])
# alternatively, depending on your shell environment
subprocess.check_call(["sudo python gpiocli.py get 13"], shell=True)

Why use sudo?

It's tempting to use setuid to make the module executable and run as root. However, that doesn't work!

Make script executable

Since the module starts with #!/usr/bin/python, you can chmod +x this script, and then run

sudo ./gpiocli.py 13 HIGH

About

Command line interface for RaspberryPi's GPIO

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages