From 77ce6cd9eb124496494c5f3e6d3a0a1d6fbe2a23 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Wed, 9 Mar 2016 11:49:38 +0000 Subject: [PATCH 01/27] Renamed from wiringpi2 to wiringpi --- .gitignore | 4 ++-- Makefile | 4 ++++ setup.py | 12 ++++++------ wiringpi2-class.py => wiringpi-class.py | 0 wiringpi.i | 4 ++-- 5 files changed, 14 insertions(+), 10 deletions(-) rename wiringpi2-class.py => wiringpi-class.py (100%) diff --git a/.gitignore b/.gitignore index a391e08..28244e0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ build/ -wiringpi2.egg-info/ +*.egg-info/ dist/ __pycache__ *.pyc wiringpi_wrap.c -wiringpi2.py +wiringpi.py diff --git a/Makefile b/Makefile index 6b1080b..08c1d7b 100644 --- a/Makefile +++ b/Makefile @@ -4,5 +4,9 @@ all: bindings 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 57dccac..0189589 100755 --- a/setup.py +++ b/setup.py @@ -9,15 +9,15 @@ sources.remove('WiringPi/devLib/piFaceOld.c') -_wiringpi2 = Extension( - '_wiringpi2', +_wiringpi = Extension( + '_wiringpi', include_dirs=['WiringPi/wiringPi','WiringPi/devLib'], sources=sources ) setup( - name = 'wiringpi2', - version = '2.32.0', + name = 'wiringpi', + version = '2.32.1', author = "Philip Howard", author_email = "phil@gadgetoid.com", url = 'https://github.com/WiringPi/WiringPi-Python/', @@ -25,8 +25,8 @@ easily interfacing with the GPIO pins of the Raspberry Pi. Also supports i2c and SPI""", long_description=open('README.md').read(), - ext_modules = [ _wiringpi2 ], - py_modules = ["wiringpi2"], + ext_modules = [ _wiringpi ], + py_modules = ["wiringpi"], install_requires=[], headers=glob('WiringPi/wiringPi/*.h')+glob('WiringPi/devLib/*.h') ) diff --git a/wiringpi2-class.py b/wiringpi-class.py similarity index 100% rename from wiringpi2-class.py rename to wiringpi-class.py diff --git a/wiringpi.i b/wiringpi.i index a0d90b1..847ac76 100644 --- a/wiringpi.i +++ b/wiringpi.i @@ -1,4 +1,4 @@ -%module wiringpi2 +%module wiringpi %{ #if PY_MAJOR_VERSION >= 3 @@ -283,4 +283,4 @@ static void wiringPiISRWrapper(int pin, int mode, PyObject *PyFunc); %include "bindings.i" %include "constants.py" -%include "wiringpi2-class.py" +%include "wiringpi-class.py" From 6577b7e592fb933c39b2b97aa717d95ae4ae2329 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Wed, 9 Mar 2016 12:19:22 +0000 Subject: [PATCH 02/27] Updated to reflect wiringpi2 to wiringpi rename --- MANIFEST.in | 2 +- README.md | 34 +++++++++++++++++----------------- examples/callback.py | 12 ++++++------ examples/delay.py | 4 ++-- examples/ladder-board.py | 2 +- examples/n5510-mcp23017.py | 4 ++-- examples/quick2wire-io.py | 14 +++++++------- examples/softpwm.py | 16 ++++++++-------- examples/two-mcp23017.py | 16 ++++++++-------- tests/piglow.py | 2 +- tests/test.py | 2 +- 11 files changed, 54 insertions(+), 54 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index bb5e72f..d252ee2 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,5 +3,5 @@ graft WiringPi/devLib include README.md include LICENSE.txt include setup.cfg -include wiringpi2.py +include wiringpi.py include wiringpi_wrap.c diff --git a/README.md b/README.md index 2b61ccf..662b0e0 100644 --- a/README.md +++ b/README.md @@ -44,50 +44,50 @@ Description incoming! ##Usage - import wiringpi2 + import wiringpi - wiringpi2.wiringPiSetup() # For sequential pin numbering, one of these MUST be called before using IO functions + wiringpi.wiringPiSetup() # For sequential pin numbering, one of these MUST be called before using IO functions # OR - wiringpi2.wiringPiSetupSys() # For /sys/class/gpio with GPIO pin numbering + wiringpi.wiringPiSetupSys() # For /sys/class/gpio with GPIO pin numbering # OR - wiringpi2.wiringPiSetupGpio() # For GPIO pin numbering + wiringpi.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): - wiringpi2.mcp23017Setup(65,0x20) - wiringpi2.pinMode(65,1) - wiringpi2.digitalWrite(65,1) + wiringpi.mcp23017Setup(65,0x20) + wiringpi.pinMode(65,1) + wiringpi.digitalWrite(65,1) **General IO:** - wiringpi2.pinMode(6,1) # Set pin 6 to 1 ( OUTPUT ) - wiringpi2.digitalWrite(6,1) # Write 1 ( HIGH ) to pin 6 - wiringpi2.digitalRead(6) # Read pin 6 + 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 ) as if they were normal pins on the Pi. - wiringpi2.mcp23017Setup(PIN_OFFSET,I2C_ADDR) + wiringpi.mcp23017Setup(PIN_OFFSET,I2C_ADDR) **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. - wiringpi2.softToneCreate(PIN) - wiringpi2.softToneWrite(PIN,FREQUENCY) + wiringpi.softToneCreate(PIN) + wiringpi.softToneWrite(PIN,FREQUENCY) **Bit shifting:** - wiringpi2.shiftOut(1,2,0,123) # Shift out 123 (b1110110, byte 0-255) to data pin 1, clock pin 2 + wiringpi.shiftOut(1,2,0,123) # Shift out 123 (b1110110, byte 0-255) to data pin 1, clock pin 2 **Serial:** - serial = wiringpi2.serialOpen('/dev/ttyAMA0',9600) # Requires device/baud and returns an ID - wiringpi2.serialPuts(serial,"hello") - wiringpi2.serialClose(serial) # Pass in ID + serial = wiringpi.serialOpen('/dev/ttyAMA0',9600) # Requires device/baud and returns an ID + wiringpi.serialPuts(serial,"hello") + wiringpi.serialClose(serial) # Pass in ID **Full details at:** http://www.wiringpi.com diff --git a/examples/callback.py b/examples/callback.py index 72f54f0..175482a 100644 --- a/examples/callback.py +++ b/examples/callback.py @@ -1,14 +1,14 @@ -import wiringpi2 +import wiringpi PIN_TO_SENSE = 23 def gpio_callback(): print "GPIO_CALLBACK!" -wiringpi2.wiringPiSetupGpio() -wiringpi2.pinMode(PIN_TO_SENSE, wiringpi2.GPIO.INPUT) -wiringpi2.pullUpDnControl(PIN_TO_SENSE, wiringpi2.GPIO.PUD_UP) +wiringpi.wiringPiSetupGpio() +wiringpi.pinMode(PIN_TO_SENSE, wiringpi.GPIO.INPUT) +wiringpi.pullUpDnControl(PIN_TO_SENSE, wiringpi.GPIO.PUD_UP) -wiringpi2.wiringPiISR(PIN_TO_SENSE, wiringpi2.GPIO.INT_EDGE_BOTH, gpio_callback) +wiringpi.wiringPiISR(PIN_TO_SENSE, wiringpi.GPIO.INT_EDGE_BOTH, gpio_callback) while True: - wiringpi2.delay(2000) + wiringpi.delay(2000) diff --git a/examples/delay.py b/examples/delay.py index 66107ac..be899bf 100644 --- a/examples/delay.py +++ b/examples/delay.py @@ -1,5 +1,5 @@ # Demonstrates use of Arduino-like delay function -import wiringpi2 +import wiringpi print 'Hello World' -wiringpi2.delay(1500) # Delay for 1.5 seconds +wiringpi.delay(1500) # Delay for 1.5 seconds print 'Hi again!' diff --git a/examples/ladder-board.py b/examples/ladder-board.py index de4542f..35b5df6 100644 --- a/examples/ladder-board.py +++ b/examples/ladder-board.py @@ -1,4 +1,4 @@ -import wiringpi2 as wiringpi +import wiringpi INPUT = 0 OUTPUT = 1 LOW = 0 diff --git a/examples/n5510-mcp23017.py b/examples/n5510-mcp23017.py index fb12f77..4251a80 100644 --- a/examples/n5510-mcp23017.py +++ b/examples/n5510-mcp23017.py @@ -1,5 +1,5 @@ # Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander ) -import wiringpi2 as wiringpi +import wiringpi PIN_BACKLIGHT = 67 # LED PIN_SCLK = 68 # Clock SCLK @@ -92,4 +92,4 @@ def lcd_fill(): lcd_clear() wiringpi.delay(1000) lcd_fill() - wiringpi.delay(1000) \ No newline at end of file + wiringpi.delay(1000) diff --git a/examples/quick2wire-io.py b/examples/quick2wire-io.py index 68efa8c..3bb816b 100644 --- a/examples/quick2wire-io.py +++ b/examples/quick2wire-io.py @@ -1,15 +1,15 @@ # Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander ) -import wiringpi2 +import wiringpi 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) +wiringpi.wiringPiSetup() +wiringpi.mcp23017Setup(pin_base,i2c_addr) for pin in pins: - wiringpi2.pinMode(pin,1) - wiringpi2.digitalWrite(pin,1) -# wiringpi2.delay(1000) -# wiringpi2.digitalWrite(pin,0) + wiringpi.pinMode(pin,1) + wiringpi.digitalWrite(pin,1) +# wiringpi.delay(1000) +# wiringpi.digitalWrite(pin,0) diff --git a/examples/softpwm.py b/examples/softpwm.py index f7c72fd..e4bf0b3 100644 --- a/examples/softpwm.py +++ b/examples/softpwm.py @@ -1,19 +1,19 @@ # Pulsates an LED connected to GPIO pin 1 with a suitable resistor 4 times using softPwm # softPwm uses a fixed frequency -import wiringpi2 +import wiringpi OUTPUT = 1 PIN_TO_PWM = 1 -wiringpi2.wiringPiSetup() -wiringpi2.pinMode(PIN_TO_PWM,OUTPUT) -wiringpi2.softPwmCreate(PIN_TO_PWM,0,100) # Setup PWM using Pin, Initial Value and Range parameters +wiringpi.wiringPiSetup() +wiringpi.pinMode(PIN_TO_PWM,OUTPUT) +wiringpi.softPwmCreate(PIN_TO_PWM,0,100) # Setup PWM using Pin, Initial Value and Range parameters for time in range(0,4): for brightness in range(0,100): # Going from 0 to 100 will give us full off to full on - wiringpi2.softPwmWrite(PIN_TO_PWM,brightness) # Change PWM duty cycle - wiringpi2.delay(10) # Delay for 0.2 seconds + wiringpi.softPwmWrite(PIN_TO_PWM,brightness) # Change PWM duty cycle + wiringpi.delay(10) # Delay for 0.2 seconds for brightness in reversed(range(0,100)): - wiringpi2.softPwmWrite(PIN_TO_PWM,brightness) - wiringpi2.delay(10) + wiringpi.softPwmWrite(PIN_TO_PWM,brightness) + wiringpi.delay(10) diff --git a/examples/two-mcp23017.py b/examples/two-mcp23017.py index a6a38a0..c7318d8 100644 --- a/examples/two-mcp23017.py +++ b/examples/two-mcp23017.py @@ -1,18 +1,18 @@ # Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander ) -import wiringpi2 +import wiringpi pin_base = 65 i2c_addr = 0x20 i2c_addr_2 = 0x21 #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) -wiringpi2.mcp23017Setup(pin_base+16,i2c_addr_2) +wiringpi.wiringPiSetup() +wiringpi.mcp23017Setup(pin_base,i2c_addr) +wiringpi.mcp23017Setup(pin_base+16,i2c_addr_2) #for pin in pins: for pin in range(65,96): - wiringpi2.pinMode(pin,1) - wiringpi2.digitalWrite(pin,1) -# wiringpi2.delay(1000) -# wiringpi2.digitalWrite(pin,0) + wiringpi.pinMode(pin,1) + wiringpi.digitalWrite(pin,1) +# wiringpi.delay(1000) +# wiringpi.digitalWrite(pin,0) diff --git a/tests/piglow.py b/tests/piglow.py index a35cd35..3902893 100644 --- a/tests/piglow.py +++ b/tests/piglow.py @@ -1,4 +1,4 @@ -import wiringpi2 as wiringpi +import wiringpi io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS) io.piGlowSetup() io.piGlowLeg(1,100) diff --git a/tests/test.py b/tests/test.py index 95f497e..0b25c73 100644 --- a/tests/test.py +++ b/tests/test.py @@ -1,4 +1,4 @@ -import wiringpi2 as wiringpi +import wiringpi io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS) print io.digitalRead(1) print io.analogRead(1) From 4ca39a67619641b9599a71c396f83d48544c7e57 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Wed, 9 Mar 2016 12:31:47 +0000 Subject: [PATCH 03/27] Added stub package for wiringpi2 --- _wiringpi2/LICENSE.txt | 165 +++++++++++++++++++++++++++++++++++++++++ _wiringpi2/MANIFEST.in | 2 + _wiringpi2/README.txt | 3 + _wiringpi2/setup.py | 16 ++++ 4 files changed, 186 insertions(+) create mode 100644 _wiringpi2/LICENSE.txt create mode 100644 _wiringpi2/MANIFEST.in create mode 100644 _wiringpi2/README.txt create mode 100755 _wiringpi2/setup.py diff --git a/_wiringpi2/LICENSE.txt b/_wiringpi2/LICENSE.txt new file mode 100644 index 0000000..65c5ca8 --- /dev/null +++ b/_wiringpi2/LICENSE.txt @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/_wiringpi2/MANIFEST.in b/_wiringpi2/MANIFEST.in new file mode 100644 index 0000000..7015d2c --- /dev/null +++ b/_wiringpi2/MANIFEST.in @@ -0,0 +1,2 @@ +include README.txt +include LICENSE.txt diff --git a/_wiringpi2/README.txt b/_wiringpi2/README.txt new file mode 100644 index 0000000..5277958 --- /dev/null +++ b/_wiringpi2/README.txt @@ -0,0 +1,3 @@ +# Wiring Pi 2 + +This package has been deprecated in favour of using the name "WiringPi" which provides the same exact functionality. diff --git a/_wiringpi2/setup.py b/_wiringpi2/setup.py new file mode 100755 index 0000000..80b60b4 --- /dev/null +++ b/_wiringpi2/setup.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +from setuptools import setup, find_packages, Extension + +setup( + name = 'wiringpi2', + version = '2.32.1', + 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.txt').read(), + install_requires=['wiringpi>=2.23.1'], +) From f0f50daf915109dc498eae5dea848181f6c2f598 Mon Sep 17 00:00:00 2001 From: Philip Howard Date: Wed, 20 Jul 2016 11:14:24 +0100 Subject: [PATCH 04/27] Updated README.md with note about submodules --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 662b0e0..127b9bc 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ Built against Python 2.7.2, Python 3.2.3 ```bash git clone --recursive https://github.com/WiringPi/WiringPi-Python.git cd WiringPi-Python +git submodule update --init ``` ##Prerequisites From 321ca837fd62fb2feff87cefebc2b37acf41810c Mon Sep 17 00:00:00 2001 From: Philip Howard Date: Wed, 20 Jul 2016 11:22:31 +0100 Subject: [PATCH 05/27] Update to address #38 #36 --- README.md | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 127b9bc..a2034ff 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,17 @@ WiringPi: An implementation of most of the Arduino Wiring WiringPi 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 +#Quick Build + +A quick and dirty build script is supplied to install WiringPi-Python for Python 2 and 3. Just: + +``` +git clone --recursive https://github.com/WiringPi/WiringPi-Python.git +cd WiringPi-Python +./build.sh +``` + +#Manual Build ##Get/setup repo ```bash @@ -30,18 +38,22 @@ 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` -#Class-based Usage -Description incoming! +`sudo python3 setup.py install` ##Usage From 1b9c63aa440c7d975c14c75e898d35f545fc61aa Mon Sep 17 00:00:00 2001 From: Joe Rickerby Date: Wed, 20 Jul 2016 11:39:04 +0100 Subject: [PATCH 06/27] 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 07/27] 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 08/27] 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 0ccd8204b12e498ef90c75ebd073c11537ec1ced Mon Sep 17 00:00:00 2001 From: MakeHaven shared account Date: Fri, 14 Apr 2017 08:34:40 -0400 Subject: [PATCH 09/27] Fix markdown for headings in README.md --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a2034ff..2ca8dc4 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -#WiringPi for Python +# 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 Build +# Quick Build A quick and dirty build script is supplied to install WiringPi-Python for Python 2 and 3. Just: @@ -15,29 +15,29 @@ cd WiringPi-Python ./build.sh ``` -#Manual Build +# Manual Build -##Get/setup repo +## Get/setup repo ```bash git clone --recursive https://github.com/WiringPi/WiringPi-Python.git cd WiringPi-Python git submodule update --init ``` -##Prerequisites +## Prerequisites To rebuild the bindings you **must** first have python-dev, python-setuptools and swig installed. ```bash sudo apt-get install python-dev python-setuptools swig ``` -##Build WiringPi +## Build WiringPi ```bash cd WiringPi sudo ./build ``` -##Generate Bindings +## Generate Bindings Return to the root directory of the repository and: @@ -47,7 +47,7 @@ or `swig3.0 -thread -python wiringpi.i` -##Build & install with +## Build & install with `sudo python setup.py install` @@ -55,7 +55,7 @@ Or Python 3: `sudo python3 setup.py install` -##Usage +## Usage import wiringpi From 04a3e26b49cc0c4d8cca1f2135bb5d3453bf0d4a Mon Sep 17 00:00:00 2001 From: Philip Howard Date: Sat, 12 Aug 2017 10:07:12 +0100 Subject: [PATCH 10/27] 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 11/27] 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 12/27] 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 13/27] 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 14/27] 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 15/27] 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 16/27] 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 17/27] 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 18/27] 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 19/27] 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 20/27] 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 21/27] 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 22/27] 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 23/27] 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 24/27] 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 25/27] 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 26/27] 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 27/27] 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 ~~~~