Skip to content

Instantly share code, notes, and snippets.

@mandyRae
Last active December 1, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mandyRae/36fa783e91a5cbb3e5c5 to your computer and use it in GitHub Desktop.
Save mandyRae/36fa783e91a5cbb3e5c5 to your computer and use it in GitHub Desktop.
This is a super simple Python module that's used for quicker access to the GPIO pins on the Raspberry Pi, mainly for use in interactive mode.
"""
iopi module ... Input/Output Pi Version 0.0
For instructions on how to install this module on
Raspberry Pi, visit https://electrothoughts.wordpress.com/2015/06/23/the-python-raspi-gpio-module-remade-iopi-py/
This is a module to simplify use of GPIO pins,
including faster setup and control
especially within interpreter/IDLE
"""
"""
Functions defined here:
setup(inputs, outputs, initial = False) - setup for input(s) and output(s) in one line
on(pins) - turns output pin(s) to True
off(pins) - turns output pin(s) to False
read(pin) - returns state of input pin
clean() - resets all pins to their default state
data() - prints to console a list of pins and their names for reference
"""
version = 0.0
version_data = 'June 23 2015'
warnings = False
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(warnings)
#These variables define the pins with nonnumeric names
SDA = 2
SCL = 3
MOSI = 10
MISO = 9
SCLK = 11
TXD = 14
RXD = 15
CE0 = 8
CE1 = 7
#Dictionary defining the GPIO pins with names
pin_names = {'SDA':2, 'SCL':3, 'MOSI':10, 'MISO':9,
'SCLK':11, 'TXD':14, 'RXD':15,
'CEO':8, 'CE1':7}
#Setup function that incorporates inputs and outputs at once
def setup(inputs=[], outputs=[], initial_output_state=False):
"""
inputs: list or tuple of input pin ints
outputs: list or tuple of input pin ints
initial_output_state: (optional) Boolean or int
"""
GPIO.setup(inputs,GPIO.IN)
GPIO.setup(outputs, GPIO.OUT, initial = initial_output_state)
def on(pins):
"""
pins: int or list of int of pins
"""
GPIO.output(pins, True)
def off(pins):
"""
pin: int or list of ints
"""
GPIO.output(pins, False)
def read(pin):
"""
pin: int number
"""
return GPIO.input(pin)
def clean():
"""
Sets all pins to default state
"""
GPIO.cleanup()
def data():
'''
Prints pin data
'''
print('Valid for all models of Raspberry Pi')
for pin in pin_names:
print(pin, ' ', pin_names.get(pin))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment