mirror of
git://soft.sys114.com/WiringPi2-Python
synced 2026-02-09 12:54:22 +09:00
Updated readme to reflect rename to wiringpi2, added examples
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,4 +1,4 @@
|
|||||||
build/
|
build/
|
||||||
wiringpi.egg-info/
|
wiringpi2.egg-info/
|
||||||
dist/
|
dist/
|
||||||
__pycache__
|
__pycache__
|
||||||
|
|||||||
33
README
33
README
@@ -4,10 +4,13 @@ WiringPi: An implementation of most of the Arduino Wiring
|
|||||||
|
|
||||||
WiringPi2: WiringPi version 2 implements new functions for managing IO expanders.
|
WiringPi2: WiringPi version 2 implements new functions for managing IO expanders.
|
||||||
|
|
||||||
|
Testing:
|
||||||
|
Build with gcc version 4.6.3 (Debian 4.6.3-14+rpi1)
|
||||||
|
Built against Python 2.7.2, Python 3.2.3
|
||||||
|
|
||||||
Prerequisites:
|
Prerequisites:
|
||||||
You must have python-dev and python-setuptools installed
|
You must have python-dev and python-setuptools installed
|
||||||
If you manually rebuild the bindings with swig -python wiringpi.i
|
If you manually rebuild the bindings with swig -python wiringpi.i
|
||||||
then cat wiringpi_class.py >> wiringpi.py to get the class-based wrapper
|
|
||||||
|
|
||||||
Get/setup repo:
|
Get/setup repo:
|
||||||
git clone https://github.com/Gadgetoid/WiringPi2-Python.git
|
git clone https://github.com/Gadgetoid/WiringPi2-Python.git
|
||||||
@@ -23,30 +26,30 @@ Class-based Usage:
|
|||||||
No classes have been created for this version yet.
|
No classes have been created for this version yet.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
import wiringpi
|
import wiringpi2
|
||||||
wiringpi.wiringPiSetup // For sequential pin numbering, one of these MUST be called before using IO functions
|
wiringpi2.wiringPiSetup // For sequential pin numbering, one of these MUST be called before using IO functions
|
||||||
OR
|
OR
|
||||||
wiringpi.wiringPiSetupSys // For /sys/class/gpio with GPIO pin numbering
|
wiringpi2.wiringPiSetupSys // For /sys/class/gpio with GPIO pin numbering
|
||||||
OR
|
OR
|
||||||
wiringpi.wiringPiSetupGpio // For GPIO pin numbering
|
wiringpi2.wiringPiSetupGpio // For GPIO pin numbering
|
||||||
|
|
||||||
Setting up IO expanders (This example was tested on a quick2wire board with one digital IO expansion board connected via I2C):
|
Setting up IO expanders (This example was tested on a quick2wire board with one digital IO expansion board connected via I2C):
|
||||||
wiringpi.mcp23017Setup(65,0x20)
|
wiringpi2.mcp23017Setup(65,0x20)
|
||||||
wiringpi.pinMode(65,1)
|
wiringpi2.pinMode(65,1)
|
||||||
wiringpi.digitalWrite(65,1)
|
wiringpi2.digitalWrite(65,1)
|
||||||
|
|
||||||
General IO:
|
General IO:
|
||||||
wiringpi.pinMode(1,1) // Set pin 1 to output
|
wiringpi2.pinMode(1,1) // Set pin 1 to output
|
||||||
wiringpi.digitalWrite(1,1) // Write 1 HIGH to pin 1
|
wiringpi2.digitalWrite(1,1) // Write 1 HIGH to pin 1
|
||||||
wiringpi.digitalRead(1) // Read pin 1
|
wiringpi2.digitalRead(1) // Read pin 1
|
||||||
|
|
||||||
Bit shifting:
|
Bit shifting:
|
||||||
wiringpi.shiftOut(1,2,0,123) // Shift out 123 (b1110110, byte 0-255) to data pin 1, clock pin 2
|
wiringpi2.shiftOut(1,2,0,123) // Shift out 123 (b1110110, byte 0-255) to data pin 1, clock pin 2
|
||||||
|
|
||||||
Serial:
|
Serial:
|
||||||
serial = wiringpi.serialOpen('/dev/ttyAMA0',9600) // Requires device/baud and returns an ID
|
serial = wiringpi2.serialOpen('/dev/ttyAMA0',9600) // Requires device/baud and returns an ID
|
||||||
wiringpi.serialPuts(serial,"hello")
|
wiringpi2.serialPuts(serial,"hello")
|
||||||
wiringpi.serialClose(serial) // Pass in ID
|
wiringpi2.serialClose(serial) // Pass in ID
|
||||||
|
|
||||||
Full details at:
|
Full details at:
|
||||||
http://www.wiringpi.com
|
http://www.wiringpi.com
|
||||||
|
|||||||
13
examples/quick2wire-io.py
Normal file
13
examples/quick2wire-io.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import wiringpi2
|
||||||
|
|
||||||
|
pin_base = 65
|
||||||
|
i2c_addr = 0x20
|
||||||
|
pins = [65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80]
|
||||||
|
|
||||||
|
wiringpi2.wiringPiSetup()
|
||||||
|
wiringpi2.mcp23017Setup(pin_base,i2c_addr)
|
||||||
|
|
||||||
|
for pin in pins:
|
||||||
|
wiringpi2.pinMode(pin,1)
|
||||||
|
wiringpi2.digitalWrite(pin,1)
|
||||||
|
|
||||||
297
wiringpi2.py
Normal file
297
wiringpi2.py
Normal file
@@ -0,0 +1,297 @@
|
|||||||
|
# This file was automatically generated by SWIG (http://www.swig.org).
|
||||||
|
# Version 2.0.7
|
||||||
|
#
|
||||||
|
# Do not make changes to this file unless you know what you are doing--modify
|
||||||
|
# the SWIG interface file instead.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
from sys import version_info
|
||||||
|
if version_info >= (2,6,0):
|
||||||
|
def swig_import_helper():
|
||||||
|
from os.path import dirname
|
||||||
|
import imp
|
||||||
|
fp = None
|
||||||
|
try:
|
||||||
|
fp, pathname, description = imp.find_module('_wiringpi2', [dirname(__file__)])
|
||||||
|
except ImportError:
|
||||||
|
import _wiringpi2
|
||||||
|
return _wiringpi2
|
||||||
|
if fp is not None:
|
||||||
|
try:
|
||||||
|
_mod = imp.load_module('_wiringpi2', fp, pathname, description)
|
||||||
|
finally:
|
||||||
|
fp.close()
|
||||||
|
return _mod
|
||||||
|
_wiringpi2 = swig_import_helper()
|
||||||
|
del swig_import_helper
|
||||||
|
else:
|
||||||
|
import _wiringpi2
|
||||||
|
del version_info
|
||||||
|
try:
|
||||||
|
_swig_property = property
|
||||||
|
except NameError:
|
||||||
|
pass # Python < 2.2 doesn't have 'property'.
|
||||||
|
def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
|
||||||
|
if (name == "thisown"): return self.this.own(value)
|
||||||
|
if (name == "this"):
|
||||||
|
if type(value).__name__ == 'SwigPyObject':
|
||||||
|
self.__dict__[name] = value
|
||||||
|
return
|
||||||
|
method = class_type.__swig_setmethods__.get(name,None)
|
||||||
|
if method: return method(self,value)
|
||||||
|
if (not static):
|
||||||
|
self.__dict__[name] = value
|
||||||
|
else:
|
||||||
|
raise AttributeError("You cannot add attributes to %s" % self)
|
||||||
|
|
||||||
|
def _swig_setattr(self,class_type,name,value):
|
||||||
|
return _swig_setattr_nondynamic(self,class_type,name,value,0)
|
||||||
|
|
||||||
|
def _swig_getattr(self,class_type,name):
|
||||||
|
if (name == "thisown"): return self.this.own()
|
||||||
|
method = class_type.__swig_getmethods__.get(name,None)
|
||||||
|
if method: return method(self)
|
||||||
|
raise AttributeError(name)
|
||||||
|
|
||||||
|
def _swig_repr(self):
|
||||||
|
try: strthis = "proxy of " + self.this.__repr__()
|
||||||
|
except: strthis = ""
|
||||||
|
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
|
||||||
|
|
||||||
|
try:
|
||||||
|
_object = object
|
||||||
|
_newclass = 1
|
||||||
|
except AttributeError:
|
||||||
|
class _object : pass
|
||||||
|
_newclass = 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def wiringPiSetup():
|
||||||
|
return _wiringpi2.wiringPiSetup()
|
||||||
|
wiringPiSetup = _wiringpi2.wiringPiSetup
|
||||||
|
|
||||||
|
def wiringPiSetupSys():
|
||||||
|
return _wiringpi2.wiringPiSetupSys()
|
||||||
|
wiringPiSetupSys = _wiringpi2.wiringPiSetupSys
|
||||||
|
|
||||||
|
def wiringPiSetupGpio():
|
||||||
|
return _wiringpi2.wiringPiSetupGpio()
|
||||||
|
wiringPiSetupGpio = _wiringpi2.wiringPiSetupGpio
|
||||||
|
|
||||||
|
def piFaceSetup(*args):
|
||||||
|
return _wiringpi2.piFaceSetup(*args)
|
||||||
|
piFaceSetup = _wiringpi2.piFaceSetup
|
||||||
|
|
||||||
|
def piBoardRev():
|
||||||
|
return _wiringpi2.piBoardRev()
|
||||||
|
piBoardRev = _wiringpi2.piBoardRev
|
||||||
|
|
||||||
|
def wpiPinToGpio(*args):
|
||||||
|
return _wiringpi2.wpiPinToGpio(*args)
|
||||||
|
wpiPinToGpio = _wiringpi2.wpiPinToGpio
|
||||||
|
|
||||||
|
def pinMode(*args):
|
||||||
|
return _wiringpi2.pinMode(*args)
|
||||||
|
pinMode = _wiringpi2.pinMode
|
||||||
|
|
||||||
|
def getAlt(*args):
|
||||||
|
return _wiringpi2.getAlt(*args)
|
||||||
|
getAlt = _wiringpi2.getAlt
|
||||||
|
|
||||||
|
def pullUpDnControl(*args):
|
||||||
|
return _wiringpi2.pullUpDnControl(*args)
|
||||||
|
pullUpDnControl = _wiringpi2.pullUpDnControl
|
||||||
|
|
||||||
|
def digitalWrite(*args):
|
||||||
|
return _wiringpi2.digitalWrite(*args)
|
||||||
|
digitalWrite = _wiringpi2.digitalWrite
|
||||||
|
|
||||||
|
def digitalWriteByte(*args):
|
||||||
|
return _wiringpi2.digitalWriteByte(*args)
|
||||||
|
digitalWriteByte = _wiringpi2.digitalWriteByte
|
||||||
|
|
||||||
|
def gpioClockSet(*args):
|
||||||
|
return _wiringpi2.gpioClockSet(*args)
|
||||||
|
gpioClockSet = _wiringpi2.gpioClockSet
|
||||||
|
|
||||||
|
def pwmWrite(*args):
|
||||||
|
return _wiringpi2.pwmWrite(*args)
|
||||||
|
pwmWrite = _wiringpi2.pwmWrite
|
||||||
|
|
||||||
|
def setPadDrive(*args):
|
||||||
|
return _wiringpi2.setPadDrive(*args)
|
||||||
|
setPadDrive = _wiringpi2.setPadDrive
|
||||||
|
|
||||||
|
def digitalRead(*args):
|
||||||
|
return _wiringpi2.digitalRead(*args)
|
||||||
|
digitalRead = _wiringpi2.digitalRead
|
||||||
|
|
||||||
|
def pwmSetMode(*args):
|
||||||
|
return _wiringpi2.pwmSetMode(*args)
|
||||||
|
pwmSetMode = _wiringpi2.pwmSetMode
|
||||||
|
|
||||||
|
def pwmSetRange(*args):
|
||||||
|
return _wiringpi2.pwmSetRange(*args)
|
||||||
|
pwmSetRange = _wiringpi2.pwmSetRange
|
||||||
|
|
||||||
|
def pwmSetClock(*args):
|
||||||
|
return _wiringpi2.pwmSetClock(*args)
|
||||||
|
pwmSetClock = _wiringpi2.pwmSetClock
|
||||||
|
|
||||||
|
def wiringPiISR(*args):
|
||||||
|
return _wiringpi2.wiringPiISR(*args)
|
||||||
|
wiringPiISR = _wiringpi2.wiringPiISR
|
||||||
|
|
||||||
|
def piThreadCreate(*args):
|
||||||
|
return _wiringpi2.piThreadCreate(*args)
|
||||||
|
piThreadCreate = _wiringpi2.piThreadCreate
|
||||||
|
|
||||||
|
def piLock(*args):
|
||||||
|
return _wiringpi2.piLock(*args)
|
||||||
|
piLock = _wiringpi2.piLock
|
||||||
|
|
||||||
|
def piUnlock(*args):
|
||||||
|
return _wiringpi2.piUnlock(*args)
|
||||||
|
piUnlock = _wiringpi2.piUnlock
|
||||||
|
|
||||||
|
def delay(*args):
|
||||||
|
return _wiringpi2.delay(*args)
|
||||||
|
delay = _wiringpi2.delay
|
||||||
|
|
||||||
|
def delayMicroseconds(*args):
|
||||||
|
return _wiringpi2.delayMicroseconds(*args)
|
||||||
|
delayMicroseconds = _wiringpi2.delayMicroseconds
|
||||||
|
|
||||||
|
def millis():
|
||||||
|
return _wiringpi2.millis()
|
||||||
|
millis = _wiringpi2.millis
|
||||||
|
|
||||||
|
def micros():
|
||||||
|
return _wiringpi2.micros()
|
||||||
|
micros = _wiringpi2.micros
|
||||||
|
|
||||||
|
def serialOpen(*args):
|
||||||
|
return _wiringpi2.serialOpen(*args)
|
||||||
|
serialOpen = _wiringpi2.serialOpen
|
||||||
|
|
||||||
|
def serialClose(*args):
|
||||||
|
return _wiringpi2.serialClose(*args)
|
||||||
|
serialClose = _wiringpi2.serialClose
|
||||||
|
|
||||||
|
def serialFlush(*args):
|
||||||
|
return _wiringpi2.serialFlush(*args)
|
||||||
|
serialFlush = _wiringpi2.serialFlush
|
||||||
|
|
||||||
|
def serialPutchar(*args):
|
||||||
|
return _wiringpi2.serialPutchar(*args)
|
||||||
|
serialPutchar = _wiringpi2.serialPutchar
|
||||||
|
|
||||||
|
def serialPuts(*args):
|
||||||
|
return _wiringpi2.serialPuts(*args)
|
||||||
|
serialPuts = _wiringpi2.serialPuts
|
||||||
|
|
||||||
|
def serialPrintf(*args):
|
||||||
|
return _wiringpi2.serialPrintf(*args)
|
||||||
|
serialPrintf = _wiringpi2.serialPrintf
|
||||||
|
|
||||||
|
def serialDataAvail(*args):
|
||||||
|
return _wiringpi2.serialDataAvail(*args)
|
||||||
|
serialDataAvail = _wiringpi2.serialDataAvail
|
||||||
|
|
||||||
|
def serialGetchar(*args):
|
||||||
|
return _wiringpi2.serialGetchar(*args)
|
||||||
|
serialGetchar = _wiringpi2.serialGetchar
|
||||||
|
|
||||||
|
def shiftOut(*args):
|
||||||
|
return _wiringpi2.shiftOut(*args)
|
||||||
|
shiftOut = _wiringpi2.shiftOut
|
||||||
|
|
||||||
|
def shiftIn(*args):
|
||||||
|
return _wiringpi2.shiftIn(*args)
|
||||||
|
shiftIn = _wiringpi2.shiftIn
|
||||||
|
|
||||||
|
def wiringPiSPIGetFd(*args):
|
||||||
|
return _wiringpi2.wiringPiSPIGetFd(*args)
|
||||||
|
wiringPiSPIGetFd = _wiringpi2.wiringPiSPIGetFd
|
||||||
|
|
||||||
|
def wiringPiSPIDataRW(*args):
|
||||||
|
return _wiringpi2.wiringPiSPIDataRW(*args)
|
||||||
|
wiringPiSPIDataRW = _wiringpi2.wiringPiSPIDataRW
|
||||||
|
|
||||||
|
def wiringPiSPISetup(*args):
|
||||||
|
return _wiringpi2.wiringPiSPISetup(*args)
|
||||||
|
wiringPiSPISetup = _wiringpi2.wiringPiSPISetup
|
||||||
|
|
||||||
|
def wiringPiI2CRead(*args):
|
||||||
|
return _wiringpi2.wiringPiI2CRead(*args)
|
||||||
|
wiringPiI2CRead = _wiringpi2.wiringPiI2CRead
|
||||||
|
|
||||||
|
def wiringPiI2CReadReg8(*args):
|
||||||
|
return _wiringpi2.wiringPiI2CReadReg8(*args)
|
||||||
|
wiringPiI2CReadReg8 = _wiringpi2.wiringPiI2CReadReg8
|
||||||
|
|
||||||
|
def wiringPiI2CReadReg16(*args):
|
||||||
|
return _wiringpi2.wiringPiI2CReadReg16(*args)
|
||||||
|
wiringPiI2CReadReg16 = _wiringpi2.wiringPiI2CReadReg16
|
||||||
|
|
||||||
|
def wiringPiI2CWrite(*args):
|
||||||
|
return _wiringpi2.wiringPiI2CWrite(*args)
|
||||||
|
wiringPiI2CWrite = _wiringpi2.wiringPiI2CWrite
|
||||||
|
|
||||||
|
def wiringPiI2CWriteReg8(*args):
|
||||||
|
return _wiringpi2.wiringPiI2CWriteReg8(*args)
|
||||||
|
wiringPiI2CWriteReg8 = _wiringpi2.wiringPiI2CWriteReg8
|
||||||
|
|
||||||
|
def wiringPiI2CWriteReg16(*args):
|
||||||
|
return _wiringpi2.wiringPiI2CWriteReg16(*args)
|
||||||
|
wiringPiI2CWriteReg16 = _wiringpi2.wiringPiI2CWriteReg16
|
||||||
|
|
||||||
|
def softToneCreate(*args):
|
||||||
|
return _wiringpi2.softToneCreate(*args)
|
||||||
|
softToneCreate = _wiringpi2.softToneCreate
|
||||||
|
|
||||||
|
def softToneWrite(*args):
|
||||||
|
return _wiringpi2.softToneWrite(*args)
|
||||||
|
softToneWrite = _wiringpi2.softToneWrite
|
||||||
|
|
||||||
|
def softServoWrite(*args):
|
||||||
|
return _wiringpi2.softServoWrite(*args)
|
||||||
|
softServoWrite = _wiringpi2.softServoWrite
|
||||||
|
|
||||||
|
def softServoSetup(*args):
|
||||||
|
return _wiringpi2.softServoSetup(*args)
|
||||||
|
softServoSetup = _wiringpi2.softServoSetup
|
||||||
|
|
||||||
|
def softPwmCreate(*args):
|
||||||
|
return _wiringpi2.softPwmCreate(*args)
|
||||||
|
softPwmCreate = _wiringpi2.softPwmCreate
|
||||||
|
|
||||||
|
def softPwmWrite(*args):
|
||||||
|
return _wiringpi2.softPwmWrite(*args)
|
||||||
|
softPwmWrite = _wiringpi2.softPwmWrite
|
||||||
|
|
||||||
|
def mcp23s17Setup(*args):
|
||||||
|
return _wiringpi2.mcp23s17Setup(*args)
|
||||||
|
mcp23s17Setup = _wiringpi2.mcp23s17Setup
|
||||||
|
|
||||||
|
def mcp23017Setup(*args):
|
||||||
|
return _wiringpi2.mcp23017Setup(*args)
|
||||||
|
mcp23017Setup = _wiringpi2.mcp23017Setup
|
||||||
|
|
||||||
|
def mcp23s08Setup(*args):
|
||||||
|
return _wiringpi2.mcp23s08Setup(*args)
|
||||||
|
mcp23s08Setup = _wiringpi2.mcp23s08Setup
|
||||||
|
|
||||||
|
def mcp23008Setup(*args):
|
||||||
|
return _wiringpi2.mcp23008Setup(*args)
|
||||||
|
mcp23008Setup = _wiringpi2.mcp23008Setup
|
||||||
|
|
||||||
|
def sr595Setup(*args):
|
||||||
|
return _wiringpi2.sr595Setup(*args)
|
||||||
|
sr595Setup = _wiringpi2.sr595Setup
|
||||||
|
# This file is compatible with both classic and new-style classes.
|
||||||
|
|
||||||
|
cvar = _wiringpi2.cvar
|
||||||
|
|
||||||
Reference in New Issue
Block a user