From db5caf3ccb7ca80ea2b2a261c0bf72c22b316600 Mon Sep 17 00:00:00 2001 From: Mark Liffiton Date: Fri, 27 Apr 2018 15:24:00 -0500 Subject: [PATCH 01/11] 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 02/11] 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 03/11] 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 04/11] 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 05/11] 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 06/11] 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 07/11] 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 08/11] 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 09/11] 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 10/11] 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 11/11] 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 ~~~~