https://github.com/drjayvee/gpio-cli
Command line interface for RaspberryPi's GPIO
https://github.com/drjayvee/gpio-cli
Last synced: over 1 year ago
JSON representation
Command line interface for RaspberryPi's GPIO
- Host: GitHub
- URL: https://github.com/drjayvee/gpio-cli
- Owner: drjayvee
- License: other
- Created: 2012-12-23T08:30:38.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2013-01-02T07:42:28.000Z (over 13 years ago)
- Last Synced: 2025-01-24T06:17:29.304Z (over 1 year ago)
- Language: Python
- Size: 137 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# 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](http://www.tuxation.com/setuid-on-shell-scripts.html) to make the module executable and run as root.
However, that [doesn't work](http://stackoverflow.com/a/8314858)!
## 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
```