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/.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 diff --git a/MANIFEST.in b/MANIFEST.in index bb5e72f..5bec85d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,7 +1,8 @@ -graft WiringPi/wiringPi -graft WiringPi/devLib -include README.md +recursive-include WiringPi *.h +include README.rst include LICENSE.txt -include setup.cfg -include wiringpi2.py +include bindings.i +include constants.py +include wiringpi-class.py +include wiringpi.i include wiringpi_wrap.c diff --git a/Makefile b/Makefile deleted file mode 100644 index 6b1080b..0000000 --- a/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -all: bindings - python setup.py build - -bindings: - swig3.0 -python -threads wiringpi.i - -install: - sudo python setup.py install diff --git a/README.md b/README.md deleted file mode 100644 index 2b61ccf..0000000 --- a/README.md +++ /dev/null @@ -1,93 +0,0 @@ -#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. - -##Testing -Build with gcc version 4.6.3 (Debian 4.6.3-14+rpi1) -Built against Python 2.7.2, Python 3.2.3 - -##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. -```bash -sudo apt-get install python-dev python-setuptools swig -``` - -##Build WiringPi -```bash -cd WiringPi -sudo ./build -``` - -##Generate Bindings -`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! - -##Usage - - import wiringpi2 - - wiringpi2.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 - # OR - wiringpi2.wiringPiSetupGpio() # For GPIO pin numbering - - -Setting up IO expanders (This example was tested on a quick2wire board with one digital IO expansion board connected via I2C): - - wiringpi2.mcp23017Setup(65,0x20) - wiringpi2.pinMode(65,1) - wiringpi2.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 - -**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) - -**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) - -**Bit shifting:** - - wiringpi2.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 - -**Full details at:** -http://www.wiringpi.com diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..855e84a --- /dev/null +++ b/README.rst @@ -0,0 +1,154 @@ +: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 +~~~~ + +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. + +**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 +============= + +.. 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 +===== + +.. 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/WiringPi b/WiringPi index 9a8f8be..e9821ab 160000 --- a/WiringPi +++ b/WiringPi @@ -1 +1 @@ -Subproject commit 9a8f8bee5df60061645918231110a7c2e4d3fa6b +Subproject commit e9821abdb4b4fe46a2ea9243471d339435fa7bde 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'], +) 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/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/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; + %} 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/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) 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/setup.cfg b/setup.cfg index b88034e..360d7aa 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.rst +license = LGPL diff --git a/setup.py b/setup.py index 57dccac..4d2e3f1 100755 --- a/setup.py +++ b/setup.py @@ -1,32 +1,68 @@ #!/usr/bin/env python -from setuptools import setup, find_packages, Extension +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_wrap.c'] +# 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') +except ValueError: + # 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_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) -sources.remove('WiringPi/devLib/piFaceOld.c') -_wiringpi2 = Extension( - '_wiringpi2', +_wiringpi = Extension( + '_wiringpi', include_dirs=['WiringPi/wiringPi','WiringPi/devLib'], - sources=sources + sources=sources, + swig_opts=['-threads'], + extra_link_args=['-lcrypt', '-lrt'] ) setup( - name = 'wiringpi2', - version = '2.32.0', - 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(), - ext_modules = [ _wiringpi2 ], - py_modules = ["wiringpi2"], + name = 'wiringpi', + version = '2.60.1', + ext_modules = [ _wiringpi ], + py_modules = ["wiringpi"], install_requires=[], - headers=glob('WiringPi/wiringPi/*.h')+glob('WiringPi/devLib/*.h') + cmdclass = {'build_py' : build_py_ext_first, 'sdist' : sdist_ext_first}, ) 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) diff --git a/wiringpi2-class.py b/wiringpi-class.py similarity index 99% rename from wiringpi2-class.py rename to wiringpi-class.py index 74ca602..a14df56 100644 --- a/wiringpi2-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) diff --git a/wiringpi.i b/wiringpi.i index a0d90b1..fc62075 100644 --- a/wiringpi.i +++ b/wiringpi.i @@ -1,4 +1,4 @@ -%module wiringpi2 +%module wiringpi %{ #if PY_MAJOR_VERSION >= 3 @@ -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 }; @@ -52,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; } %{ @@ -283,4 +291,4 @@ static void wiringPiISRWrapper(int pin, int mode, PyObject *PyFunc); %include "bindings.i" %include "constants.py" -%include "wiringpi2-class.py" +%include "wiringpi-class.py"