https://github.com/projectweekend/pi-pin-manager
Setup Raspberry Pi GPIO pins using a configuration file, not boilerplate.
https://github.com/projectweekend/pi-pin-manager
Last synced: 11 months ago
JSON representation
Setup Raspberry Pi GPIO pins using a configuration file, not boilerplate.
- Host: GitHub
- URL: https://github.com/projectweekend/pi-pin-manager
- Owner: projectweekend
- License: mit
- Created: 2014-12-20T04:07:47.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-09-23T02:38:48.000Z (almost 11 years ago)
- Last Synced: 2024-04-23T20:53:59.945Z (about 2 years ago)
- Language: Python
- Homepage:
- Size: 500 KB
- Stars: 21
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.txt
- License: LICENSE
Awesome Lists containing this project
README
Boilerplate code is annoying and sometimes there can be a lot of it working with [Raspberry Pi GPIO](https://pypi.python.org/pypi/RPi.GPIO). I got tired of setting the board mode and declaring GPIO channels in every script so I made a library that uses a config file instead. In addition to getting rid of the boilerplate, **Pi-Pin-Manager** offers a cleaner interface for working with [RPi.GPIO](https://pypi.python.org/pypi/RPi.GPIO).
### Install it
```
pip install Pi-Pin-Manager
```
#### Example Config File
The following snippet shows an example configuration file:
```yaml
18:
mode: OUT
initial: LOW
23:
mode: OUT
initial: HIGH
24:
mode: IN
resistor: PUD_UP
```
#### Notes
* Add a numbered item for each pin
* `mode` - This controls whether the pin will be used for input or output. Accepted values are: `IN`, `OUT`. (Required)
* `initial` - This controls the starting value of the pin. Accepted values are: `LOW`, `HIGH`. (Optional - defaults to `LOW`)
* `resistor` - This controls the software defined pull up/pull down resistor available in the Broadcom SOC. Accepted values are: `PUD_UP`, `PUD_DOWN`, `PUD_OFF`. (Optional - defaults to `PUD_OFF`)
For full documentation about available GPIO input pin configurations see the [documentation](http://sourceforge.net/p/raspberry-gpio-python/wiki/Examples/).
#### Example
The following snippet demonstrates a `PinManager` instance using the example config file referenced above. The `PinManager` instance will have named attributes for each pin number you defined in the config file.
```python
import RPi.GPIO as GPIO
from pi_pin_manager import PinManager
CONFIG_FILE = 'path/to/config/file.yml'
manager = PinManager(config_file=CONFIG_FILE, gpio=GPIO)
# Turn on pin 18
manager.pin_18.on()
# Turn off pin 18
manager.pin_18.off()
# Read pin 18
manager.pin_18.read()
# Settings dictionary for pin 18
manager.pin_18.settings
# Attach an action to pin with threaded callback
def my_action(channel):
# do something here
pass
# Valid event types: RISING, FALLING, BOTH
manager.pin_18.attach_action(event_type='RISING', action=my_action, bounce=200)
```
#### Run Tests
```
nosetests -v --with-coverage --cover-erase --cover-package=pi_pin_manager --cover-html
```