From 1b9c63aa440c7d975c14c75e898d35f545fc61aa Mon Sep 17 00:00:00 2001 From: Joe Rickerby Date: Wed, 20 Jul 2016 11:39:04 +0100 Subject: [PATCH 01/21] Add `apt-get install wiringpi` to README Fix #37 --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a2034ff..ec0aee0 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ WiringPi implements new functions for managing IO expanders. A quick and dirty build script is supplied to install WiringPi-Python for Python 2 and 3. Just: ``` +sudo apt-get install wiringpi git clone --recursive https://github.com/WiringPi/WiringPi-Python.git cd WiringPi-Python ./build.sh @@ -26,9 +27,10 @@ git submodule update --init ##Prerequisites To rebuild the bindings -you **must** first have python-dev, python-setuptools and swig installed. +you **must** first have python-dev, python-setuptools and swig installed. Wiring Pi should also be installed system-wide +for access to the `gpio` tool. ```bash -sudo apt-get install python-dev python-setuptools swig +sudo apt-get install python-dev python-setuptools swig wiringpi ``` ##Build WiringPi From 76db7e6658eed2b383b6cb315b0c47d4395955a3 Mon Sep 17 00:00:00 2001 From: Brett Reinhard Date: Fri, 16 Dec 2016 07:37:29 -0800 Subject: [PATCH 02/21] Missing a letter in a return value Missing a letter in a return value for sofPwmWrite, changed to softPwmWrite to keep consistency --- wiringpi-class.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wiringpi-class.py b/wiringpi-class.py index 74ca602..a14df56 100644 --- a/wiringpi-class.py +++ b/wiringpi-class.py @@ -154,7 +154,7 @@ def wiringPiISR(self,*args): def softPwmCreate(self,*args): return softPwmCreate(*args) def softPwmWrite(self,*args): - return sofPwmWrite(*args) + return softPwmWrite(*args) def softToneCreate(self,*args): return softToneCreate(*args) From 91b71d701f7b1b56d7e25a7d21a351e104abfb8f Mon Sep 17 00:00:00 2001 From: neuralassembly Date: Wed, 29 Mar 2017 17:25:14 +0900 Subject: [PATCH 03/21] Add fix for kernel 4.9. --- WiringPi | 2 +- bindings.i | 50 +++++++++++++++++++++++++++++++++++++++----------- setup.py | 5 +++-- wiringpi.i | 8 ++++++++ 4 files changed, 51 insertions(+), 14 deletions(-) diff --git a/WiringPi b/WiringPi index 9a8f8be..c947643 160000 --- a/WiringPi +++ b/WiringPi @@ -1 +1 @@ -Subproject commit 9a8f8bee5df60061645918231110a7c2e4d3fa6b +Subproject commit c9476436016c995d3327e4765a73de7848d4af56 diff --git a/bindings.i b/bindings.i index dc8bf05..0766221 100644 --- a/bindings.i +++ b/bindings.i @@ -4,31 +4,35 @@ extern int wiringPiFailure (int fatal, const char *message, ...) ; extern struct wiringPiNodeStruct *wiringPiFindNode (int pin) ; extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) ; +extern void wiringPiVersion (int *major, int *minor) ; extern int wiringPiSetup (void) ; extern int wiringPiSetupSys (void) ; extern int wiringPiSetupGpio (void) ; extern int wiringPiSetupPhys (void) ; -extern void pinModeAlt (int pin, int mode) ; -extern void pinMode (int pin, int mode) ; -extern void pullUpDnControl (int pin, int pud) ; -extern int digitalRead (int pin) ; -extern void digitalWrite (int pin, int value) ; -extern void pwmWrite (int pin, int value) ; -extern int analogRead (int pin) ; -extern void analogWrite (int pin, int value) ; -extern int piBoardRev (void) ; +extern void pinModeAlt (int pin, int mode) ; +extern void pinMode (int pin, int mode) ; +extern void pullUpDnControl (int pin, int pud) ; +extern int digitalRead (int pin) ; +extern void digitalWrite (int pin, int value) ; +extern void pwmWrite (int pin, int value) ; +extern int analogRead (int pin) ; +extern void analogWrite (int pin, int value) ; +extern int piGpioLayout (void) ; +extern int piBoardRev (void) ; // Deprecated extern void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) ; extern int wpiPinToGpio (int wpiPin) ; extern int physPinToGpio (int physPin) ; extern void setPadDrive (int group, int value) ; extern int getAlt (int pin) ; extern void pwmToneWrite (int pin, int freq) ; -extern void digitalWriteByte (int value) ; -extern unsigned int digitalReadByte (void) ; extern void pwmSetMode (int mode) ; extern void pwmSetRange (unsigned int range) ; extern void pwmSetClock (int divisor) ; extern void gpioClockSet (int pin, int freq) ; +extern unsigned int digitalReadByte (void) ; +extern unsigned int digitalReadByte2 (void) ; +extern void digitalWriteByte (int value) ; +extern void digitalWriteByte2 (int value) ; extern int waitForInterrupt (int pin, int mS) ; extern int piThreadCreate (void *(*fn)(void *)) ; extern void piLock (int key) ; @@ -141,6 +145,27 @@ extern void softToneWrite (int pin, int freq) ; extern int sr595Setup (const int pinBase, const int numPins, const int dataPin, const int clockPin, const int latchPin) ; +// Header file WiringPi/wiringPi/bmp180.h +extern int bmp180Setup (const int pinBase) ; + +// Header file WiringPi/wiringPi/drcNet.h +extern int drcSetupNet (const int pinBase, const int numPins, const char *ipAddress, const char *port, const char *password) ; + +// Header file WiringPi/wiringPi/ds18b20.h +extern int ds18b20Setup (const int pinBase, const char *serialNum) ; + +// Header file WiringPi/wiringPi/htu21d.h +extern int htu21dSetup (const int pinBase) ; + +// Header file WiringPi/wiringPi/pseudoPins.h +extern int pseudoPinsSetup (const int pinBase) ; + +// Header file WiringPi/wiringPi/rht03.h +extern int rht03Setup (const int pinBase, const int devicePin) ; + +// Header file WiringPi/wiringPi/wpiExtensions.h +extern int loadWPiExtension (char *progName, char *extensionData, int verbose) ; + // Header file WiringPi/devLib/ds1302.h extern unsigned int ds1302rtcRead (const int reg) ; extern void ds1302rtcWrite (const int reg, const unsigned int data) ; @@ -220,3 +245,6 @@ extern void scrollPhatPrintf (const char *message, ...) ; extern void scrollPhatPrintSpeed (const int cps10) ; extern void scrollPhatIntensity (const int percent) ; extern int scrollPhatSetup (void) ; + +// Header file WiringPi/devLib/piFace.h +extern int piFaceSetup (const int pinBase) ; diff --git a/setup.py b/setup.py index 0189589..9e40f3e 100755 --- a/setup.py +++ b/setup.py @@ -12,12 +12,13 @@ _wiringpi = Extension( '_wiringpi', include_dirs=['WiringPi/wiringPi','WiringPi/devLib'], - sources=sources + sources=sources, + extra_link_args=['-lcrypt', '-lrt'] ) setup( name = 'wiringpi', - version = '2.32.1', + version = '2.44', author = "Philip Howard", author_email = "phil@gadgetoid.com", url = 'https://github.com/WiringPi/WiringPi-Python/', diff --git a/wiringpi.i b/wiringpi.i index 847ac76..e34fe3a 100644 --- a/wiringpi.i +++ b/wiringpi.i @@ -34,6 +34,13 @@ #include "WiringPi/wiringPi/softServo.h" #include "WiringPi/wiringPi/softTone.h" #include "WiringPi/wiringPi/sr595.h" +#include "WiringPi/wiringPi/bmp180.h" +#include "WiringPi/wiringPi/drcNet.h" +#include "WiringPi/wiringPi/ds18b20.h" +#include "WiringPi/wiringPi/htu21d.h" +#include "WiringPi/wiringPi/pseudoPins.h" +#include "WiringPi/wiringPi/rht03.h" +#include "WiringPi/wiringPi/wpiExtensions.h" #include "WiringPi/devLib/ds1302.h" #include "WiringPi/devLib/font.h" #include "WiringPi/devLib/gertboard.h" @@ -43,6 +50,7 @@ #include "WiringPi/devLib/piGlow.h" #include "WiringPi/devLib/piNes.h" #include "WiringPi/devLib/scrollPhat.h" +#include "WiringPi/devLib/piFace.h" %} %apply unsigned char { uint8_t }; From 04a3e26b49cc0c4d8cca1f2135bb5d3453bf0d4a Mon Sep 17 00:00:00 2001 From: Philip Howard Date: Sat, 12 Aug 2017 10:07:12 +0100 Subject: [PATCH 04/21] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 2ca8dc4..993a037 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +### Note + +This is an unofficial port of Gordon's WiringPi library. Please do not email Gordon if you have issues, he will not be able to help. + # WiringPi for Python WiringPi: An implementation of most of the Arduino Wiring From 6a99cd63495736bd338bd9512bc9fc02f4cc5e04 Mon Sep 17 00:00:00 2001 From: Philip Howard Date: Sat, 12 Aug 2017 11:04:25 +0100 Subject: [PATCH 05/21] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b386333..377a07d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ This is an unofficial port of Gordon's WiringPi library. Please do not email Gordon if you have issues, he will not be able to help. +For support, comments, questions, etc please join the WiringPi Discord channel: https://discord.gg/SM4WUVG + # WiringPi for Python WiringPi: An implementation of most of the Arduino Wiring From 36449079858f22cf1a78a5ec3e3af1a1fc23a745 Mon Sep 17 00:00:00 2001 From: Mark Liffiton Date: Sat, 12 Aug 2017 16:47:21 -0500 Subject: [PATCH 06/21] Fix for building new WiringPi from source dist; build simplifications. --- MANIFEST.in | 9 +++---- README.md | 78 +++++++++++++++++++---------------------------------- build.sh | 3 --- setup.cfg | 7 ++++- setup.py | 20 ++++++-------- 5 files changed, 45 insertions(+), 72 deletions(-) delete mode 100755 build.sh diff --git a/MANIFEST.in b/MANIFEST.in index d252ee2..b146ec8 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,7 +1,6 @@ -graft WiringPi/wiringPi -graft WiringPi/devLib +recursive-include WiringPi *.h include README.md include LICENSE.txt -include setup.cfg -include wiringpi.py -include wiringpi_wrap.c +include bindings.i +include constants.py +include wiringpi-class.py diff --git a/README.md b/README.md index 377a07d..516b8d2 100644 --- a/README.md +++ b/README.md @@ -11,59 +11,11 @@ WiringPi: An implementation of most of the Arduino Wiring WiringPi implements new functions for managing IO expanders. -# Quick Build +# Quick Install -A quick and dirty build script is supplied to install WiringPi-Python for Python 2 and 3. Just: +`pip install wiringpi` -``` -sudo apt-get install wiringpi -git clone --recursive https://github.com/WiringPi/WiringPi-Python.git -cd WiringPi-Python -./build.sh -``` - -# Manual Build - -## Get/setup repo -```bash -git clone --recursive https://github.com/WiringPi/WiringPi-Python.git -cd WiringPi-Python -git submodule update --init -``` - -## Prerequisites -To rebuild the bindings -you **must** first have python-dev, python-setuptools and swig installed. Wiring Pi should also be installed system-wide -for access to the `gpio` tool. -```bash -sudo apt-get install python-dev python-setuptools swig wiringpi -``` - -## Build WiringPi -```bash -cd WiringPi -sudo ./build -``` - -## Generate Bindings - -Return to the root directory of the repository and: - -`swig2.0 -python wiringpi.i` - -or - -`swig3.0 -thread -python wiringpi.i` - -## Build & install with - -`sudo python setup.py install` - -Or Python 3: - -`sudo python3 setup.py install` - -## Usage +# Usage import wiringpi @@ -112,3 +64,27 @@ Hook a speaker up to your Pi and generate music with softTone. Also useful for g **Full details at:** http://www.wiringpi.com + +# Manual Build + +## Get/setup repo +```bash +git clone --recursive https://github.com/WiringPi/WiringPi-Python.git +cd WiringPi-Python +``` + +## Prerequisites +To rebuild the bindings +you **must** first have python-dev, python-setuptools and swig installed. Wiring Pi should also be installed system-wide +for access to the `gpio` tool. +```bash +sudo apt-get install python-dev python-setuptools swig wiringpi +``` + +## Build & install with + +`sudo python setup.py install` + +Or Python 3: + +`sudo python3 setup.py install` diff --git a/build.sh b/build.sh deleted file mode 100755 index e57689f..0000000 --- a/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -swig2.0 -python -threads wiringpi.i -sudo python setup.py build install -sudo python test.py diff --git a/setup.cfg b/setup.cfg index b88034e..c68c02d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,7 @@ [metadata] -description-file = README.md +author = Philip Howard +author_email = phil@gadgetoid.com +url = https://github.com/WiringPi/WiringPi-Python/ +description = A python interface to WiringPi 2.0 library which allows for easily interfacing with the GPIO pins of the Raspberry Pi. Also supports i2c and SPI. +long_description = file:README.md +license = LGPL diff --git a/setup.py b/setup.py index 9e40f3e..542a08c 100755 --- a/setup.py +++ b/setup.py @@ -1,13 +1,17 @@ #!/usr/bin/env python -from setuptools import setup, find_packages, Extension +from setuptools import setup, Extension from glob import glob sources = glob('WiringPi/devLib/*.c') sources += glob('WiringPi/wiringPi/*.c') -sources += ['wiringpi_wrap.c'] +sources += ['wiringpi.i'] -sources.remove('WiringPi/devLib/piFaceOld.c') +try: + sources.remove('WiringPi/devLib/piFaceOld.c') +except ValueError: + # the file is already excluded in the source distribution + pass _wiringpi = Extension( '_wiringpi', @@ -18,16 +22,8 @@ setup( name = 'wiringpi', - version = '2.44', - author = "Philip Howard", - author_email = "phil@gadgetoid.com", - url = 'https://github.com/WiringPi/WiringPi-Python/', - description = """A python interface to WiringPi 2.0 library which allows for - easily interfacing with the GPIO pins of the Raspberry Pi. Also supports - i2c and SPI""", - long_description=open('README.md').read(), + version = '2.44.2', ext_modules = [ _wiringpi ], py_modules = ["wiringpi"], install_requires=[], - headers=glob('WiringPi/wiringPi/*.h')+glob('WiringPi/devLib/*.h') ) From f43bfceb5f1551f35d0a882a2ba0a7879c34a524 Mon Sep 17 00:00:00 2001 From: Mark Liffiton Date: Sat, 12 Aug 2017 23:34:01 -0500 Subject: [PATCH 07/21] Fix for build missing wiringpi.py. --- setup.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 542a08c..7d05e0e 100755 --- a/setup.py +++ b/setup.py @@ -1,6 +1,7 @@ #!/usr/bin/env python from setuptools import setup, Extension +from setuptools.command.build_py import build_py from glob import glob sources = glob('WiringPi/devLib/*.c') @@ -13,6 +14,20 @@ # the file is already excluded in the source distribution pass + +# Fix so that build_ext runs before build_py +# Without this, wiringpi.py is generated too late and doesn't +# end up in the distribution when running setup.py bdist or bdist_wheel. +# Based on: +# https://stackoverflow.com/a/29551581/7938656 +# and +# https://blog.niteoweb.com/setuptools-run-custom-code-in-setup-py/ +class Build_ext_first(build_py): + def run(self): + self.run_command("build_ext") + return build_py.run(self) + + _wiringpi = Extension( '_wiringpi', include_dirs=['WiringPi/wiringPi','WiringPi/devLib'], @@ -22,8 +37,9 @@ setup( name = 'wiringpi', - version = '2.44.2', + version = '2.44.3', ext_modules = [ _wiringpi ], py_modules = ["wiringpi"], install_requires=[], + cmdclass = {'build_py' : Build_ext_first}, ) From 37ca9707f6842d05350e51ad20922b1ba19cfe38 Mon Sep 17 00:00:00 2001 From: Mark Liffiton Date: Sun, 13 Aug 2017 12:52:10 -0500 Subject: [PATCH 08/21] Use swig if available, but package wiringpi_wrap.c in the source dist. --- MANIFEST.in | 2 ++ setup.py | 30 ++++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index b146ec8..0c28801 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,3 +4,5 @@ include LICENSE.txt include bindings.i include constants.py include wiringpi-class.py +include wiringpi.i +include wiringpi_wrap.c diff --git a/setup.py b/setup.py index 7d05e0e..e7919dd 100755 --- a/setup.py +++ b/setup.py @@ -1,12 +1,27 @@ #!/usr/bin/env python +import os +import sys + from setuptools import setup, Extension from setuptools.command.build_py import build_py +from setuptools.command.sdist import sdist +from distutils.spawn import find_executable from glob import glob sources = glob('WiringPi/devLib/*.c') sources += glob('WiringPi/wiringPi/*.c') -sources += ['wiringpi.i'] +# If we have swig, use it. Otherwise, use the pre-generated +# wrapper from the source distribution. +if find_executable('swig'): + sources += ['wiringpi.i'] +elif os.path.exists('wiringpi_wrap.c'): + sources += ['wiringpi_wrap.c'] +else: + print("Error: Building this module requires either that swig is installed\n" + " (e.g., 'sudo apt install swig') or that wiringpi_wrap.c from the\n" + " source distribution (on pypi) is available.") + sys.exit(1) try: sources.remove('WiringPi/devLib/piFaceOld.c') @@ -22,12 +37,19 @@ # https://stackoverflow.com/a/29551581/7938656 # and # https://blog.niteoweb.com/setuptools-run-custom-code-in-setup-py/ -class Build_ext_first(build_py): +class build_py_ext_first(build_py): def run(self): self.run_command("build_ext") return build_py.run(self) +# Make sure wiringpi_wrap.c is available for the source dist, also. +class sdist_ext_first(sdist): + def run(self): + self.run_command("build_ext") + return sdist.run(self) + + _wiringpi = Extension( '_wiringpi', include_dirs=['WiringPi/wiringPi','WiringPi/devLib'], @@ -37,9 +59,9 @@ def run(self): setup( name = 'wiringpi', - version = '2.44.3', + version = '2.44.4', ext_modules = [ _wiringpi ], py_modules = ["wiringpi"], install_requires=[], - cmdclass = {'build_py' : Build_ext_first}, + cmdclass = {'build_py' : build_py_ext_first, 'sdist' : sdist_ext_first}, ) From dfa3c420f221aefb2b56e1a7e3172bd9fb64908f Mon Sep 17 00:00:00 2001 From: neuralassembly Date: Fri, 18 Aug 2017 07:35:29 +0900 Subject: [PATCH 09/21] Changing the protcol of submodule from HTTP to HTTPS --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 0016469..1dbeda0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "WiringPi"] path = WiringPi - url = http://github.com/wiringPi/WiringPi + url = https://github.com/wiringPi/WiringPi From ed4f8cb882a79c0c28a3b154b5583706319180f2 Mon Sep 17 00:00:00 2001 From: Mark Liffiton Date: Sat, 21 Oct 2017 16:25:06 -0500 Subject: [PATCH 10/21] Update README.md Cleaned up and clarified, mostly in the Usage section, and added a section on using SPI (closes #62). --- README.md | 90 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 516b8d2..9431a92 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,7 @@ For support, comments, questions, etc please join the WiringPi Discord channel: # WiringPi for Python -WiringPi: An implementation of most of the Arduino Wiring - functions for the Raspberry Pi +WiringPi: An implementation of most of the Arduino Wiring functions for the Raspberry Pi. WiringPi implements new functions for managing IO expanders. @@ -17,66 +16,93 @@ WiringPi implements new functions for managing IO expanders. # Usage - import wiringpi - - wiringpi.wiringPiSetup() # For sequential pin numbering, one of these MUST be called before using IO functions - # OR - wiringpi.wiringPiSetupSys() # For /sys/class/gpio with GPIO pin numbering - # OR - wiringpi.wiringPiSetupGpio() # For GPIO pin numbering +```python +import wiringpi - -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) - wiringpi.pinMode(65,1) - wiringpi.digitalWrite(65,1) +# One of the following MUST be called before using IO functions: +wiringpi.wiringPiSetup() # For sequential pin numbering +# OR +wiringpi.wiringPiSetupSys() # For /sys/class/gpio with GPIO pin numbering +# OR +wiringpi.wiringPiSetupGpio() # For GPIO pin numbering +``` **General IO:** - wiringpi.pinMode(6,1) # Set pin 6 to 1 ( OUTPUT ) - wiringpi.digitalWrite(6,1) # Write 1 ( HIGH ) to pin 6 - wiringpi.digitalRead(6) # Read pin 6 +```python +wiringpi.pinMode(6, 1) # Set pin 6 to 1 ( OUTPUT ) +wiringpi.digitalWrite(6, 1) # Write 1 ( HIGH ) to pin 6 +wiringpi.digitalRead(6) # Read pin 6 +``` **Setting up a peripheral:** -WiringPi2 supports expanding your range of available "pins" by setting up a port expander. The implementation details of -your port expander will be handled transparently, and you can write to the additional pins ( starting from PIN_OFFSET >= 64 ) + +WiringPi supports expanding your range of available "pins" by setting up a port expander. The implementation details of +your port expander will be handled transparently, and you can write to the additional pins (starting from PIN_OFFSET >= 64) as if they were normal pins on the Pi. - wiringpi.mcp23017Setup(PIN_OFFSET,I2C_ADDR) +```python +wiringpi.mcp23017Setup(PIN_OFFSET, I2C_ADDR) +``` + +This example was tested on a quick2wire board with one digital IO expansion board connected via I2C: + +```python +wiringpi.mcp23017Setup(65, 0x20) +wiringpi.pinMode(65, 1) +wiringpi.digitalWrite(65, 1) +``` -**Soft Tone** +**Soft Tone:** Hook a speaker up to your Pi and generate music with softTone. Also useful for generating frequencies for other uses such as modulating A/C. - wiringpi.softToneCreate(PIN) - wiringpi.softToneWrite(PIN,FREQUENCY) +```python +wiringpi.softToneCreate(PIN) +wiringpi.softToneWrite(PIN, FREQUENCY) +``` **Bit shifting:** - wiringpi.shiftOut(1,2,0,123) # Shift out 123 (b1110110, byte 0-255) to data pin 1, clock pin 2 +```python +wiringpi.shiftOut(1, 2, 0, 123) # Shift out 123 (b1110110, byte 0-255) to data pin 1, clock pin 2 +``` **Serial:** - serial = wiringpi.serialOpen('/dev/ttyAMA0',9600) # Requires device/baud and returns an ID - wiringpi.serialPuts(serial,"hello") - wiringpi.serialClose(serial) # Pass in ID +```python +serial = wiringpi.serialOpen('/dev/ttyAMA0', 9600) # Requires device/baud and returns an ID +wiringpi.serialPuts(serial, "hello") +wiringpi.serialClose(serial) # Pass in ID +``` + +**SPI:** -**Full details at:** +The `wiringPiSPIDataRW()` function needs to be passed a `bytes` object in Python 3. In Python 2, it takes a string. The following should work in either Python 2 or 3: +```python +wiringpi.wiringPiSPISetup(channel, speed) +buf = bytes([your data here]) +retlen, retdata = wiringpi.wiringPiSPIDataRW(0, buf) +``` +Now, `retlen` will contain the number of bytes received/read by the call. `retdata` will contain the data itself, and in Python 3, `buf` will have been modified to contain it as well (that won't happen in Python 2, because then `buf` is a string, and strings are immutable). + +**Full details of the API at:** http://www.wiringpi.com # Manual Build ## Get/setup repo + ```bash git clone --recursive https://github.com/WiringPi/WiringPi-Python.git cd WiringPi-Python ``` +Don't forget the `--recursive`; it is required to also pull in the WiringPi C code from its own repository. ## Prerequisites -To rebuild the bindings -you **must** first have python-dev, python-setuptools and swig installed. Wiring Pi should also be installed system-wide -for access to the `gpio` tool. + +To rebuild the bindings you **must** first have installed `swig`, `python-dev`, and `python-setuptools` (or their `python3-` equivalents). +WiringPi should also be installed system-wide for access to the `gpio` tool. ```bash sudo apt-get install python-dev python-setuptools swig wiringpi ``` From db5caf3ccb7ca80ea2b2a261c0bf72c22b316600 Mon Sep 17 00:00:00 2001 From: Mark Liffiton Date: Fri, 27 Apr 2018 15:24:00 -0500 Subject: [PATCH 11/21] Add constants from wiringShift.h (closes #64) --- constants.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/constants.py b/constants.py index 75ce015..f501698 100644 --- a/constants.py +++ b/constants.py @@ -38,4 +38,10 @@ INT_EDGE_FALLING = 1; INT_EDGE_RISING = 2; INT_EDGE_BOTH = 3; + +# Shifting (from wiringShift.h) + +LSBFIRST = 0; +MSBFIRST = 1; + %} From 747527fda65693647a07028a64e29fc9f482d3e2 Mon Sep 17 00:00:00 2001 From: Mark Liffiton Date: Sat, 28 Apr 2018 18:21:16 -0500 Subject: [PATCH 12/21] Convert README to .rst for PyPI. --- MANIFEST.in | 2 +- README.md | 116 ------------------------------------------ README.rst | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++ setup.cfg | 2 +- 4 files changed, 144 insertions(+), 118 deletions(-) delete mode 100644 README.md create mode 100644 README.rst diff --git a/MANIFEST.in b/MANIFEST.in index 0c28801..5bec85d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,5 @@ recursive-include WiringPi *.h -include README.md +include README.rst include LICENSE.txt include bindings.i include constants.py diff --git a/README.md b/README.md deleted file mode 100644 index 9431a92..0000000 --- a/README.md +++ /dev/null @@ -1,116 +0,0 @@ -### Note - -This is an unofficial port of Gordon's WiringPi library. Please do not email Gordon if you have issues, he will not be able to help. - -For support, comments, questions, etc please join the WiringPi Discord channel: https://discord.gg/SM4WUVG - -# WiringPi for Python - -WiringPi: An implementation of most of the Arduino Wiring functions for the Raspberry Pi. - -WiringPi implements new functions for managing IO expanders. - -# Quick Install - -`pip install wiringpi` - -# Usage - -```python -import wiringpi - -# One of the following MUST be called before using IO functions: -wiringpi.wiringPiSetup() # For sequential pin numbering -# OR -wiringpi.wiringPiSetupSys() # For /sys/class/gpio with GPIO pin numbering -# OR -wiringpi.wiringPiSetupGpio() # For GPIO pin numbering -``` - -**General IO:** - -```python -wiringpi.pinMode(6, 1) # Set pin 6 to 1 ( OUTPUT ) -wiringpi.digitalWrite(6, 1) # Write 1 ( HIGH ) to pin 6 -wiringpi.digitalRead(6) # Read pin 6 -``` - -**Setting up a peripheral:** - -WiringPi supports expanding your range of available "pins" by setting up a port expander. The implementation details of -your port expander will be handled transparently, and you can write to the additional pins (starting from PIN_OFFSET >= 64) -as if they were normal pins on the Pi. - -```python -wiringpi.mcp23017Setup(PIN_OFFSET, I2C_ADDR) -``` - -This example was tested on a quick2wire board with one digital IO expansion board connected via I2C: - -```python -wiringpi.mcp23017Setup(65, 0x20) -wiringpi.pinMode(65, 1) -wiringpi.digitalWrite(65, 1) -``` - -**Soft Tone:** - -Hook a speaker up to your Pi and generate music with softTone. Also useful for generating frequencies for other uses such as modulating A/C. - -```python -wiringpi.softToneCreate(PIN) -wiringpi.softToneWrite(PIN, FREQUENCY) -``` - -**Bit shifting:** - -```python -wiringpi.shiftOut(1, 2, 0, 123) # Shift out 123 (b1110110, byte 0-255) to data pin 1, clock pin 2 -``` - -**Serial:** - -```python -serial = wiringpi.serialOpen('/dev/ttyAMA0', 9600) # Requires device/baud and returns an ID -wiringpi.serialPuts(serial, "hello") -wiringpi.serialClose(serial) # Pass in ID -``` - -**SPI:** - -The `wiringPiSPIDataRW()` function needs to be passed a `bytes` object in Python 3. In Python 2, it takes a string. The following should work in either Python 2 or 3: -```python -wiringpi.wiringPiSPISetup(channel, speed) -buf = bytes([your data here]) -retlen, retdata = wiringpi.wiringPiSPIDataRW(0, buf) -``` -Now, `retlen` will contain the number of bytes received/read by the call. `retdata` will contain the data itself, and in Python 3, `buf` will have been modified to contain it as well (that won't happen in Python 2, because then `buf` is a string, and strings are immutable). - -**Full details of the API at:** -http://www.wiringpi.com - -# Manual Build - -## Get/setup repo - -```bash -git clone --recursive https://github.com/WiringPi/WiringPi-Python.git -cd WiringPi-Python -``` -Don't forget the `--recursive`; it is required to also pull in the WiringPi C code from its own repository. - -## Prerequisites - -To rebuild the bindings you **must** first have installed `swig`, `python-dev`, and `python-setuptools` (or their `python3-` equivalents). -WiringPi should also be installed system-wide for access to the `gpio` tool. -```bash -sudo apt-get install python-dev python-setuptools swig wiringpi -``` - -## Build & install with - -`sudo python setup.py install` - -Or Python 3: - -`sudo python3 setup.py install` diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..ef61583 --- /dev/null +++ b/README.rst @@ -0,0 +1,142 @@ +Note +~~~~ + +This is an unofficial port of Gordon's WiringPi library. Please do not +email Gordon if you have issues, he will not be able to help. + +For support, comments, questions, etc please join the WiringPi Discord +channel: https://discord.gg/SM4WUVG + +WiringPi for Python +=================== + +WiringPi: An implementation of most of the Arduino Wiring functions for +the Raspberry Pi. + +WiringPi implements new functions for managing IO expanders. + +Quick Install +============= + +``pip install wiringpi`` + +Usage +===== + +.. code:: python + + import wiringpi + + # One of the following MUST be called before using IO functions: + wiringpi.wiringPiSetup() # For sequential pin numbering + # OR + wiringpi.wiringPiSetupSys() # For /sys/class/gpio with GPIO pin numbering + # OR + wiringpi.wiringPiSetupGpio() # For GPIO pin numbering + +**General IO:** + +.. code:: python + + wiringpi.pinMode(6, 1) # Set pin 6 to 1 ( OUTPUT ) + wiringpi.digitalWrite(6, 1) # Write 1 ( HIGH ) to pin 6 + wiringpi.digitalRead(6) # Read pin 6 + +**Setting up a peripheral:** + +WiringPi supports expanding your range of available "pins" by setting up +a port expander. The implementation details of your port expander will +be handled transparently, and you can write to the additional pins +(starting from PIN\_OFFSET >= 64) as if they were normal pins on the Pi. + +.. code:: python + + wiringpi.mcp23017Setup(PIN_OFFSET, I2C_ADDR) + +This example was tested on a quick2wire board with one digital IO +expansion board connected via I2C: + +.. code:: python + + wiringpi.mcp23017Setup(65, 0x20) + wiringpi.pinMode(65, 1) + wiringpi.digitalWrite(65, 1) + +**Soft Tone:** + +Hook a speaker up to your Pi and generate music with softTone. Also +useful for generating frequencies for other uses such as modulating A/C. + +.. code:: python + + wiringpi.softToneCreate(PIN) + wiringpi.softToneWrite(PIN, FREQUENCY) + +**Bit shifting:** + +.. code:: python + + wiringpi.shiftOut(1, 2, 0, 123) # Shift out 123 (b1110110, byte 0-255) to data pin 1, clock pin 2 + +**Serial:** + +.. code:: python + + serial = wiringpi.serialOpen('/dev/ttyAMA0', 9600) # Requires device/baud and returns an ID + wiringpi.serialPuts(serial, "hello") + wiringpi.serialClose(serial) # Pass in ID + +**SPI:** + +The ``wiringPiSPIDataRW()`` function needs to be passed a ``bytes`` +object in Python 3. In Python 2, it takes a string. The following should +work in either Python 2 or 3: + +.. code:: python + + wiringpi.wiringPiSPISetup(channel, speed) + buf = bytes([your data here]) + retlen, retdata = wiringpi.wiringPiSPIDataRW(0, buf) + +Now, ``retlen`` will contain the number of bytes received/read by the +call. ``retdata`` will contain the data itself, and in Python 3, ``buf`` +will have been modified to contain it as well (that won't happen in +Python 2, because then ``buf`` is a string, and strings are immutable). + +**Full details of the API at:** http://www.wiringpi.com + +Manual Build +============ + +Get/setup repo +-------------- + +.. code:: bash + + git clone --recursive https://github.com/WiringPi/WiringPi-Python.git + cd WiringPi-Python + +Don't forget the ``--recursive``; it is required to also pull in the +WiringPi C code from its own repository. + +Prerequisites +------------- + +To rebuild the bindings you **must** first have installed ``swig``, +``python-dev``, and ``python-setuptools`` (or their ``python3-`` +equivalents). WiringPi should also be installed system-wide for access +to the ``gpio`` tool. + +.. code:: bash + + sudo apt-get install python-dev python-setuptools swig wiringpi + +Build & install with +-------------------- + +``sudo python setup.py install`` + +Or Python 3: + +``sudo python3 setup.py install`` + diff --git a/setup.cfg b/setup.cfg index c68c02d..360d7aa 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,5 +3,5 @@ author = Philip Howard author_email = phil@gadgetoid.com url = https://github.com/WiringPi/WiringPi-Python/ description = A python interface to WiringPi 2.0 library which allows for easily interfacing with the GPIO pins of the Raspberry Pi. Also supports i2c and SPI. -long_description = file:README.md +long_description = file:README.rst license = LGPL From bd6b1c6a47007aa1c041390819860f6242e7ecba Mon Sep 17 00:00:00 2001 From: Mark Liffiton Date: Sun, 29 Apr 2018 09:10:02 -0500 Subject: [PATCH 13/21] Fix PyFunc typemap. --- wiringpi.i | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wiringpi.i b/wiringpi.i index e34fe3a..fc62075 100644 --- a/wiringpi.i +++ b/wiringpi.i @@ -60,12 +60,12 @@ }; // Grab a Python function object as a Python object. -%typemap(in) PyObject *pyfunc { - if (!PyCallable_Check($1)) { +%typemap(in) PyObject *PyFunc { + if (!PyCallable_Check($input)) { PyErr_SetString(PyExc_TypeError, "Need a callable object!"); return NULL; } - $1 = $2; + $1 = $input; } %{ From e525fc5e5e92cd1659cd21273567017208e59769 Mon Sep 17 00:00:00 2001 From: Mark Liffiton Date: Sun, 29 Apr 2018 09:12:55 -0500 Subject: [PATCH 14/21] Fix swig build (missing arg broke ISR callbacks), clean up unneeded makefile, bump version for release. --- Makefile | 12 ------------ setup.py | 3 ++- 2 files changed, 2 insertions(+), 13 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index 08c1d7b..0000000 --- a/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -all: bindings - python setup.py build - -bindings: - swig3.0 -python -threads wiringpi.i - -clean: - rm -rf build/ - rm -rf dist/ - -install: - sudo python setup.py install diff --git a/setup.py b/setup.py index e7919dd..2efc81d 100755 --- a/setup.py +++ b/setup.py @@ -54,12 +54,13 @@ def run(self): '_wiringpi', include_dirs=['WiringPi/wiringPi','WiringPi/devLib'], sources=sources, + swig_opts=['-threads'], extra_link_args=['-lcrypt', '-lrt'] ) setup( name = 'wiringpi', - version = '2.44.4', + version = '2.44.5', ext_modules = [ _wiringpi ], py_modules = ["wiringpi"], install_requires=[], From f91da63947871b35165c2d22f118260460d05abd Mon Sep 17 00:00:00 2001 From: Mark Liffiton Date: Mon, 2 Jul 2018 16:02:24 -0500 Subject: [PATCH 15/21] Add PyPI badge to README --- README.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.rst b/README.rst index ef61583..788ead7 100644 --- a/README.rst +++ b/README.rst @@ -18,6 +18,12 @@ WiringPi implements new functions for managing IO expanders. Quick Install ============= +.. image:: https://badge.fury.io/py/wiringpi.svg + :alt: PyPI version badge + :target: https://pypi.org/project/wiringpi/ + +The library is packaged on PyPI and can be installed with pip: + ``pip install wiringpi`` Usage From 08cf3e43c12ea1f38ffcb01daccfa5d20b8354b0 Mon Sep 17 00:00:00 2001 From: Mark Liffiton Date: Mon, 2 Jul 2018 18:06:02 -0500 Subject: [PATCH 16/21] Version bump to latest upstream WiringPi (2.46). --- WiringPi | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/WiringPi b/WiringPi index c947643..093e0a1 160000 --- a/WiringPi +++ b/WiringPi @@ -1 +1 @@ -Subproject commit c9476436016c995d3327e4765a73de7848d4af56 +Subproject commit 093e0a17a40e064260c1f3233b1ccdf7e4c66690 diff --git a/setup.py b/setup.py index 2efc81d..c908da6 100755 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ def run(self): setup( name = 'wiringpi', - version = '2.44.5', + version = '2.46.0', ext_modules = [ _wiringpi ], py_modules = ["wiringpi"], install_requires=[], From 3315e8ec750ee8535b3f4ab31c7007b5863b7e97 Mon Sep 17 00:00:00 2001 From: Martin Unzner Date: Fri, 20 Sep 2019 01:14:08 +0200 Subject: [PATCH 17/21] port soft tone example from WiringPi --- examples/softtone.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 examples/softtone.py diff --git a/examples/softtone.py b/examples/softtone.py new file mode 100644 index 0000000..4a90ce7 --- /dev/null +++ b/examples/softtone.py @@ -0,0 +1,16 @@ +# Test of the softTone module in wiringPi +# Plays a scale out on pin 3 - connect pizeo disc to pin 3 & 0v +import wiringpi + +PIN = 3 + +SCALE = [262, 294, 330, 349, 392, 440, 494, 525] + +wiringpi.wiringPiSetup() +wiringpi.softToneCreate(PIN) + +while True: + for idx in range(8): + print(idx) + wiringpi.softToneWrite(PIN, SCALE[idx]) + wiringpi.delay(500) From 3db354710a9e64b959037944b4beee97e5198259 Mon Sep 17 00:00:00 2001 From: Mark Liffiton Date: Wed, 1 Jan 2020 11:20:01 -0600 Subject: [PATCH 18/21] Bump WiringPi version to 2.60 with RPi 4 support. --- WiringPi | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/WiringPi b/WiringPi index 093e0a1..5bbb6e3 160000 --- a/WiringPi +++ b/WiringPi @@ -1 +1 @@ -Subproject commit 093e0a17a40e064260c1f3233b1ccdf7e4c66690 +Subproject commit 5bbb6e34b854a1a911e85145741681b875aec1a4 diff --git a/setup.py b/setup.py index c908da6..2d83e0e 100755 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ def run(self): setup( name = 'wiringpi', - version = '2.46.0', + version = '2.60.0', ext_modules = [ _wiringpi ], py_modules = ["wiringpi"], install_requires=[], From 93a6e40cd79e05e29dd1a203ee2b8d097fa07fd3 Mon Sep 17 00:00:00 2001 From: Mark Liffiton Date: Fri, 19 Feb 2021 23:57:21 -0600 Subject: [PATCH 19/21] Bring in latest WiringPi for more hardware compatibility, Arch compile fix. Bump to 2.60.1. --- WiringPi | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/WiringPi b/WiringPi index 5bbb6e3..e9821ab 160000 --- a/WiringPi +++ b/WiringPi @@ -1 +1 @@ -Subproject commit 5bbb6e34b854a1a911e85145741681b875aec1a4 +Subproject commit e9821abdb4b4fe46a2ea9243471d339435fa7bde diff --git a/setup.py b/setup.py index 2d83e0e..4d2e3f1 100755 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ def run(self): setup( name = 'wiringpi', - version = '2.60.0', + version = '2.60.1', ext_modules = [ _wiringpi ], py_modules = ["wiringpi"], install_requires=[], From edc377261dc6f6ae1eebdb362c3c56fc44a352e0 Mon Sep 17 00:00:00 2001 From: Mark Liffiton Date: Mon, 2 Aug 2021 09:02:15 -0400 Subject: [PATCH 20/21] Add link to an alternative Python library --- README.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 788ead7..5ff46b2 100644 --- a/README.rst +++ b/README.rst @@ -8,13 +8,17 @@ For support, comments, questions, etc please join the WiringPi Discord channel: https://discord.gg/SM4WUVG WiringPi for Python -=================== +~~~~~~~~~~~~~~~~~~~ WiringPi: An implementation of most of the Arduino Wiring functions for the Raspberry Pi. WiringPi implements new functions for managing IO expanders. +**Alternative** + +* `GPIO Zero `_ is another Python library for controlling GPIO. It is installed by default in Raspberry Pi OS and is used in the `Raspberry Pi GPIO documentation `_. + Quick Install ============= From 6d3c9e704e60bac837aecec2c8db95b0cd0f57d0 Mon Sep 17 00:00:00 2001 From: Philip Howard Date: Tue, 31 Oct 2023 12:50:49 +0000 Subject: [PATCH 21/21] Update README.rst --- README.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.rst b/README.rst index 5ff46b2..855e84a 100644 --- a/README.rst +++ b/README.rst @@ -1,3 +1,5 @@ +:Warning: WiringPi was deprecated by its author in August 2019. As of 31st October 2023 nobody has shown an interest in properly maintaining it. Between this, and changes to GPIO in Rasberry Pi OS Bookworm and on the Raspberry Pi 5, this project is going nowhere. It has been archived to more clearly indicate this status. + Note ~~~~