├── .github └── workflows │ └── pypi.yaml ├── .gitignore ├── .gitmodules ├── CHANGES.txt ├── LICENSE.txt ├── MANIFEST.in ├── README.rst ├── bindings.i ├── constants.py ├── examples ├── RUN_THESE_WITH_SUDO ├── callback.py ├── delay.py ├── ladder-board.py ├── n5510-mcp23017.py ├── quick2wire-io.py ├── softpwm.py └── two-mcp23017.py ├── generate-bindings.py ├── setup.cfg ├── setup.py ├── tests ├── piglow.py └── test.py ├── wiringpi-class.py └── wiringpi.i /.github/workflows/pypi.yaml: -------------------------------------------------------------------------------- 1 | name: 'PyPI upload' 2 | 3 | on: 4 | # push: 5 | # paths: 6 | # - 'setup.py' 7 | workflow_dispatch: 8 | inputs: 9 | logLevel: 10 | description: 'Log level' 11 | required: true 12 | default: 'warning' 13 | tags: 14 | description: 'release' 15 | 16 | jobs: 17 | upload: 18 | runs-on: ubuntu-latest 19 | steps: 20 | - name: 'Checkout' 21 | uses: actions/Checkout@v3 22 | 23 | - name: 'Checkout submodules' 24 | run: | 25 | git submodule sync 26 | git submodule update --init --recursive 27 | 28 | - name: 'Set up Python' 29 | uses: actions/setup-python@v2 30 | with: 31 | python-version: '3.8' 32 | 33 | - name: 'Install dependencies' 34 | run: | 35 | python3 -m pip install --upgrade pip 36 | python3 -m pip install build 37 | pip install setuptools wheel twine 38 | 39 | - name: 'Build package' 40 | run: | 41 | python3 -m build 42 | rm dist/*.whl 43 | 44 | - name: 'Upload' 45 | uses: pypa/gh-action-pypi-publish@release/v1 46 | with: 47 | user: ${{ secrets.PYPI_USER }} 48 | password: ${{ secrets.PYPI_API_TOKEN }} 49 | # repository-url: 'https://github.com/hardkernel/WiringPi2-Python' 50 | verbose: true 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | *.egg-info/ 3 | dist/ 4 | __pycache__ 5 | *.pyc 6 | wiringpi_wrap.c 7 | odroid_wiringpi.py 8 | .DS_Store 9 | .vscode 10 | pypi_distribute.sh 11 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "WiringPi"] 2 | path = WiringPi 3 | url = https://github.com/hardkernel/wiringPi.git 4 | -------------------------------------------------------------------------------- /CHANGES.txt: -------------------------------------------------------------------------------- 1 | v1.0.0 -- Branched from original WiringPi to deliver new WiringPi 2 functionality 2 | v1.0.1 -- Fixed build problems involving missing header files 3 | v1.0.2 -- Fixed build issue with piNes.c 4 | v1.0.3 -- Fixed bug in physical pin assignment mode 5 | v1.0.4 -- Added class wrapper, plus analogRead/Write functions 6 | v1.0.5 -- Second attempt at pretty Pypi page 7 | v1.0.6 -- Fixed spelling error in softToneCreate - Thanks oevsegneev 8 | v1.0.7 -- Added LCD functionality 9 | v1.0.8 -- Updated manifest to include .rst and fix build error 10 | v1.0.9 -- Erroneous non-fix due to stupidity 11 | v1.0.10 -- Added I2CSetup and new I2C class 12 | v1.1.0 -- Synced to WiringPi as of 8th March 2015 13 | v1.1.1 -- Included devLib folder for headers 14 | v1.2.1 -- Synced to WIringPi as of 27th February 2016 15 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | recursive-include WiringPi *.h 2 | include README.rst 3 | include LICENSE.txt 4 | include bindings.i 5 | include constants.py 6 | include wiringpi-class.py 7 | include wiringpi.i 8 | include wiringpi_wrap.c 9 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Note 2 | ~~~~ 3 | 4 | This is an unofficial port of Gordon's WiringPi library. Please do not 5 | email Gordon if you have issues, he will not be able to help. 6 | 7 | For support, comments, questions, etc please join the WiringPi Discord 8 | channel: https://discord.gg/SM4WUVG 9 | 10 | WiringPi for Python 11 | =================== 12 | 13 | WiringPi: An implementation of most of the Arduino Wiring functions for 14 | the Raspberry Pi. 15 | 16 | WiringPi implements new functions for managing IO expanders. 17 | 18 | Quick Install 19 | ============= 20 | 21 | .. image:: https://badge.fury.io/py/odroid-wiringpi.svg 22 | :alt: PyPI version badge 23 | :target: https://badge.fury.io/py/odroid-wiringpi 24 | 25 | The library is packaged on PyPI and can be installed with pip: 26 | 27 | ``pip install odroid-wiringpi`` 28 | 29 | Usage 30 | ===== 31 | 32 | .. code:: python 33 | 34 | import odroid_wiringpi as wiringpi 35 | 36 | # One of the following MUST be called before using IO functions: 37 | wiringpi.wiringPiSetup() # For sequential pin numbering 38 | # OR 39 | wiringpi.wiringPiSetupSys() # For /sys/class/gpio with GPIO pin numbering 40 | # OR 41 | wiringpi.wiringPiSetupGpio() # For GPIO pin numbering 42 | 43 | **General IO:** 44 | 45 | .. code:: python 46 | 47 | wiringpi.pinMode(6, 1) # Set pin 6 to 1 ( OUTPUT ) 48 | wiringpi.digitalWrite(6, 1) # Write 1 ( HIGH ) to pin 6 49 | wiringpi.digitalRead(6) # Read pin 6 50 | 51 | **Setting up a peripheral:** 52 | 53 | WiringPi supports expanding your range of available "pins" by setting up 54 | a port expander. The implementation details of your port expander will 55 | be handled transparently, and you can write to the additional pins 56 | (starting from PIN\_OFFSET >= 64) as if they were normal pins on the Pi. 57 | 58 | .. code:: python 59 | 60 | wiringpi.mcp23017Setup(PIN_OFFSET, I2C_ADDR) 61 | 62 | This example was tested on a quick2wire board with one digital IO 63 | expansion board connected via I2C: 64 | 65 | .. code:: python 66 | 67 | wiringpi.mcp23017Setup(65, 0x20) 68 | wiringpi.pinMode(65, 1) 69 | wiringpi.digitalWrite(65, 1) 70 | 71 | **Soft Tone:** 72 | 73 | Hook a speaker up to your Pi and generate music with softTone. Also 74 | useful for generating frequencies for other uses such as modulating A/C. 75 | 76 | .. code:: python 77 | 78 | wiringpi.softToneCreate(PIN) 79 | wiringpi.softToneWrite(PIN, FREQUENCY) 80 | 81 | **Bit shifting:** 82 | 83 | .. code:: python 84 | 85 | wiringpi.shiftOut(1, 2, 0, 123) # Shift out 123 (b1110110, byte 0-255) to data pin 1, clock pin 2 86 | 87 | **Serial:** 88 | 89 | .. code:: python 90 | 91 | serial = wiringpi.serialOpen('/dev/ttyAMA0', 9600) # Requires device/baud and returns an ID 92 | wiringpi.serialPuts(serial, "hello") 93 | wiringpi.serialClose(serial) # Pass in ID 94 | 95 | **SPI:** 96 | 97 | The ``wiringPiSPIDataRW()`` function needs to be passed a ``bytes`` 98 | object in Python 3. In Python 2, it takes a string. The following should 99 | work in either Python 2 or 3: 100 | 101 | .. code:: python 102 | 103 | wiringpi.wiringPiSPISetup(channel, speed) 104 | buf = bytes([your data here]) 105 | retlen, retdata = wiringpi.wiringPiSPIDataRW(0, buf) 106 | 107 | Now, ``retlen`` will contain the number of bytes received/read by the 108 | call. ``retdata`` will contain the data itself, and in Python 3, ``buf`` 109 | will have been modified to contain it as well (that won't happen in 110 | Python 2, because then ``buf`` is a string, and strings are immutable). 111 | 112 | **Full details of the API at:** http://www.wiringpi.com 113 | 114 | Manual Build 115 | ============ 116 | 117 | Get/setup repo 118 | -------------- 119 | 120 | .. code:: bash 121 | 122 | git clone --recursive https://github.com/WiringPi/WiringPi-Python.git 123 | cd WiringPi-Python 124 | 125 | Don't forget the ``--recursive``; it is required to also pull in the 126 | WiringPi C code from its own repository. 127 | 128 | Prerequisites 129 | ------------- 130 | 131 | To rebuild the bindings you **must** first have installed ``swig``, 132 | ``python-dev``, and ``python-setuptools`` (or their ``python3-`` 133 | equivalents). WiringPi should also be installed system-wide for access 134 | to the ``gpio`` tool. 135 | 136 | .. code:: bash 137 | 138 | sudo apt-get install python-dev python-setuptools swig wiringpi 139 | 140 | Build & install with 141 | -------------------- 142 | 143 | ``sudo python setup.py install`` 144 | 145 | Or Python 3: 146 | 147 | ``sudo python3 setup.py install`` 148 | 149 | -------------------------------------------------------------------------------- /bindings.i: -------------------------------------------------------------------------------- 1 | // Generated by generate-bindings.py - do not edit manually! 2 | 3 | // Header file WiringPi/wiringPi/wiringPi.h 4 | extern struct wiringPiNodeStruct *wiringPiFindNode (int pin); 5 | extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins); 6 | extern int wiringPiFailure (int fatal, const char *message, ...); 7 | extern int msg (int type, const char *message, ...); 8 | extern int moduleLoaded (char *); 9 | extern void setupCheck (const char *fName); 10 | extern void usingGpiomemCheck (const char *what); 11 | extern void setUsingGpiomem (const unsigned int value); 12 | extern void setKernelVersion (void); 13 | extern char cmpKernelVersion (int num, ...); 14 | extern void wiringPiVersion (int *major, char **minor); 15 | extern int wiringPiSetup (void); 16 | extern int wiringPiSetupSys (void); 17 | extern int wiringPiSetupGpio (void); 18 | extern int wiringPiSetupPhys (void); 19 | extern void setDrive (int pin, int value); 20 | extern int getDrive (int pin); 21 | extern int getAlt (int pin); 22 | extern int getPUPD (int pin); 23 | extern void pinMode (int pin, int mode); 24 | extern void pullUpDnControl (int pin, int pud); 25 | extern int digitalRead (int pin); 26 | extern void digitalWrite (int pin, int value); 27 | extern unsigned int digitalReadByte (void); 28 | extern void digitalWriteByte (const int value); 29 | extern void pwmWrite (int pin, int value); 30 | extern int analogRead (int pin); 31 | extern int piGpioLayout (void); 32 | extern void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty); 33 | extern int wpiPinToGpio (int wpiPin); 34 | extern int physPinToGpio (int physPin); 35 | extern void pwmSetRange (unsigned int range); 36 | extern void pwmSetClock (int divisor); 37 | extern int waitForInterrupt (int pin, int mS); 38 | extern int wiringPiISRCancel (int pin); 39 | extern int piThreadCreate (void *(*fn)(void *)); 40 | extern void piLock (int key); 41 | extern void piUnlock (int key); 42 | extern int piHiPri (const int pri); 43 | extern void delay (unsigned int howLong); 44 | extern void delayMicroseconds (unsigned int howLong); 45 | extern unsigned int millis (void); 46 | extern unsigned int micros (void); 47 | extern void pinModeAlt (int pin, int mode); 48 | extern void analogWrite (int pin, int value); 49 | extern void pwmToneWrite (int pin, int freq); 50 | extern void gpioClockSet (int pin, int freq); 51 | extern unsigned int digitalReadByte (void); 52 | extern unsigned int digitalReadByte2 (void); 53 | extern void digitalWriteByte (int value); 54 | extern void digitalWriteByte2 (int value); 55 | 56 | // Header file WiringPi/wiringPi/wiringPiI2C.h 57 | extern int wiringPiI2CRead (int fd); 58 | extern int wiringPiI2CReadReg8 (int fd, int reg); 59 | extern int wiringPiI2CReadReg16 (int fd, int reg); 60 | extern int wiringPiI2CReadBlock (int fd, int reg, uint8_t *buff, int size); 61 | extern int wiringPiI2CWrite (int fd, int data); 62 | extern int wiringPiI2CWriteReg8 (int fd, int reg, int data); 63 | extern int wiringPiI2CWriteReg16 (int fd, int reg, int data); 64 | extern int wiringPiI2CWriteBlock (int fd, int reg, uint8_t *buff, int size); 65 | extern int wiringPiI2CSetupInterface (const char *device, int devId); 66 | extern int wiringPiI2CSetup (const int devId); 67 | 68 | // Header file WiringPi/wiringPi/wiringPiSPI.h 69 | int wiringPiSPIGetFd (int channel) ; 70 | int wiringPiSPIDataRW (int channel, unsigned char *data, int len) ; 71 | int wiringPiSPISetupInterface (const char *device, int channel, int speed, int mode) ; 72 | int wiringPiSPISetupMode (int channel, int speed, int mode) ; 73 | int wiringPiSPISetup (int channel, int speed) ; 74 | 75 | // Header file WiringPi/wiringPi/wiringSerial.h 76 | extern int serialOpen (const char *device, const int baud) ; 77 | extern void serialClose (const int fd) ; 78 | extern void serialFlush (const int fd) ; 79 | extern void serialPutchar (const int fd, const unsigned char c) ; 80 | extern void serialPuts (const int fd, const char *s) ; 81 | extern void serialPrintf (const int fd, const char *message, ...) ; 82 | extern int serialDataAvail (const int fd) ; 83 | extern int serialGetchar (const int fd) ; 84 | 85 | // Header file WiringPi/wiringPi/wiringShift.h 86 | extern uint8_t shiftIn (uint8_t dPin, uint8_t cPin, uint8_t order) ; 87 | extern void shiftOut (uint8_t dPin, uint8_t cPin, uint8_t order, uint8_t val) ; 88 | 89 | // Header file WiringPi/wiringPi/softPwm.h 90 | extern int softPwmCreate (int pin, int value, int range) ; 91 | extern void softPwmWrite (int pin, int value) ; 92 | extern void softPwmStop (int pin) ; 93 | 94 | // Header file WiringPi/wiringPi/softServo.h 95 | extern void softServoWrite (int pin, int value) ; 96 | extern int softServoSetup (int p0, int p1, int p2, int p3, int p4, int p5, int p6, int p7) ; 97 | 98 | // Header file WiringPi/wiringPi/softTone.h 99 | extern int softToneCreate (int pin) ; 100 | extern void softToneStop (int pin) ; 101 | extern void softToneWrite (int pin, int freq) ; 102 | 103 | // Header file WiringPi/wiringPi/drcSerial.h 104 | extern int drcSetupSerial (const int pinBase, const int numPins, const char *device, const int baud) ; 105 | 106 | // Header file WiringPi/wiringPi/ads1115.h 107 | extern int ads1115Setup (int pinBase, int i2cAddress) ; 108 | 109 | // Header file WiringPi/wiringPi/max31855.h 110 | extern int max31855Setup (int pinBase, int spiChannel) ; 111 | 112 | // Header file WiringPi/wiringPi/max5322.h 113 | extern int max5322Setup (int pinBase, int spiChannel) ; 114 | 115 | // Header file WiringPi/wiringPi/mcp23008.h 116 | extern int mcp23008Setup (const int pinBase, const int i2cAddress) ; 117 | 118 | // Header file WiringPi/wiringPi/mcp23016.h 119 | extern int mcp23016Setup (const int pinBase, const int i2cAddress) ; 120 | 121 | // Header file WiringPi/wiringPi/mcp23016reg.h 122 | 123 | // Header file WiringPi/wiringPi/mcp23017.h 124 | extern int mcp23017Setup (const int pinBase, const int i2cAddress) ; 125 | 126 | // Header file WiringPi/wiringPi/mcp23s08.h 127 | extern int mcp23s08Setup (const int pinBase, const int spiPort, const int devId) ; 128 | 129 | // Header file WiringPi/wiringPi/mcp23s17.h 130 | extern int mcp23s17Setup (int pinBase, int spiPort, int devId) ; 131 | 132 | // Header file WiringPi/wiringPi/mcp23x0817.h 133 | 134 | // Header file WiringPi/wiringPi/mcp23x08.h 135 | 136 | // Header file WiringPi/wiringPi/mcp3002.h 137 | extern int mcp3002Setup (int pinBase, int spiChannel) ; 138 | 139 | // Header file WiringPi/wiringPi/mcp3004.h 140 | extern int mcp3004Setup (int pinBase, int spiChannel) ; 141 | 142 | // Header file WiringPi/wiringPi/mcp3422.h 143 | extern int mcp3422Setup (int pinBase, int i2cAddress, int sampleRate, int gain) ; 144 | 145 | // Header file WiringPi/wiringPi/mcp4802.h 146 | extern int mcp4802Setup (int pinBase, int spiChannel) ; 147 | 148 | // Header file WiringPi/wiringPi/pcf8574.h 149 | extern int pcf8574Setup (const int pinBase, const int i2cAddress) ; 150 | 151 | // Header file WiringPi/wiringPi/pcf8591.h 152 | extern int pcf8591Setup (const int pinBase, const int i2cAddress) ; 153 | 154 | // Header file WiringPi/wiringPi/sn3218.h 155 | extern int sn3218Setup (int pinBase) ; 156 | 157 | // Header file WiringPi/wiringPi/sr595.h 158 | extern int sr595Setup (const int pinBase, const int numPins, 159 | const int dataPin, const int clockPin, const int latchPin) ; 160 | 161 | // Header file WiringPi/wiringPi/bmp180.h 162 | extern int bmp180Setup (const int pinBase) ; 163 | 164 | // Header file WiringPi/wiringPi/drcNet.h 165 | extern int drcSetupNet (const int pinBase, const int numPins, const char *ipAddress, const char *port, const char *password) ; 166 | 167 | // Header file WiringPi/wiringPi/ds18b20.h 168 | extern int ds18b20Setup (const int pinBase, const char *serialNum) ; 169 | 170 | // Header file WiringPi/wiringPi/htu21d.h 171 | extern int htu21dSetup (const int pinBase) ; 172 | 173 | // Header file WiringPi/wiringPi/pseudoPins.h 174 | extern int pseudoPinsSetup (const int pinBase) ; 175 | 176 | // Header file WiringPi/wiringPi/rht03.h 177 | extern int rht03Setup (const int pinBase, const int devicePin) ; 178 | 179 | // Header file WiringPi/wiringPi/wpiExtensions.h 180 | extern int loadWPiExtension (char *progName, char *extensionData, int verbose) ; 181 | 182 | // Header file WiringPi/devLib/ds1302.h 183 | extern unsigned int ds1302rtcRead (const int reg) ; 184 | extern void ds1302rtcWrite (const int reg, const unsigned int data) ; 185 | extern unsigned int ds1302ramRead (const int addr) ; 186 | extern void ds1302ramWrite (const int addr, const unsigned int data) ; 187 | extern void ds1302clockRead (int clockData [8]) ; 188 | extern void ds1302clockWrite (const int clockData [8]) ; 189 | extern void ds1302trickleCharge (const int diodes, const int resistors) ; 190 | extern void ds1302setup (const int clockPin, const int dataPin, const int csPin) ; 191 | 192 | // Header file WiringPi/devLib/font.h 193 | 194 | // Header file WiringPi/devLib/gertboard.h 195 | extern void gertboardAnalogWrite (const int chan, const int value) ; 196 | extern int gertboardAnalogRead (const int chan) ; 197 | extern int gertboardSPISetup (void) ; 198 | extern int gertboardAnalogSetup (const int pinBase) ; 199 | 200 | // Header file WiringPi/devLib/lcd128x64.h 201 | extern void lcd128x64setOrigin (int x, int y) ; 202 | extern void lcd128x64setOrientation (int orientation) ; 203 | extern void lcd128x64orientCoordinates (int *x, int *y) ; 204 | extern void lcd128x64getScreenSize (int *x, int *y) ; 205 | extern void lcd128x64point (int x, int y, int colour) ; 206 | extern void lcd128x64line (int x0, int y0, int x1, int y1, int colour) ; 207 | extern void lcd128x64lineTo (int x, int y, int colour) ; 208 | extern void lcd128x64rectangle (int x1, int y1, int x2, int y2, int colour, int filled) ; 209 | extern void lcd128x64circle (int x, int y, int r, int colour, int filled) ; 210 | extern void lcd128x64ellipse (int cx, int cy, int xRadius, int yRadius, int colour, int filled) ; 211 | extern void lcd128x64putchar (int x, int y, int c, int bgCol, int fgCol) ; 212 | extern void lcd128x64puts (int x, int y, const char *str, int bgCol, int fgCol) ; 213 | extern void lcd128x64update (void) ; 214 | extern void lcd128x64clear (int colour) ; 215 | extern int lcd128x64setup (void) ; 216 | 217 | // Header file WiringPi/devLib/lcd.h 218 | extern void lcdHome (const int fd) ; 219 | extern void lcdClear (const int fd) ; 220 | extern void lcdDisplay (const int fd, int state) ; 221 | extern void lcdCursor (const int fd, int state) ; 222 | extern void lcdCursorBlink (const int fd, int state) ; 223 | extern void lcdSendCommand (const int fd, unsigned char command) ; 224 | extern void lcdPosition (const int fd, int x, int y) ; 225 | extern void lcdCharDef (const int fd, int index, unsigned char data [8]) ; 226 | extern void lcdPutchar (const int fd, unsigned char data) ; 227 | extern void lcdPuts (const int fd, const char *string) ; 228 | extern void lcdPrintf (const int fd, const char *message, ...) ; 229 | extern int lcdInit (const int rows, const int cols, const int bits, 230 | const int rs, const int strb, 231 | const int d0, const int d1, const int d2, const int d3, const int d4, 232 | const int d5, const int d6, const int d7) ; 233 | 234 | // Header file WiringPi/devLib/maxdetect.h 235 | int maxDetectRead (const int pin, unsigned char buffer [4]) ; 236 | int readRHT03 (const int pin, int *temp, int *rh) ; 237 | 238 | // Header file WiringPi/devLib/piGlow.h 239 | extern void piGlow1 (const int leg, const int ring, const int intensity) ; 240 | extern void piGlowLeg (const int leg, const int intensity) ; 241 | extern void piGlowRing (const int ring, const int intensity) ; 242 | extern void piGlowSetup (int clear) ; 243 | 244 | // Header file WiringPi/devLib/piNes.h 245 | extern int setupNesJoystick (int dPin, int cPin, int lPin) ; 246 | extern unsigned int readNesJoystick (int joystick) ; 247 | 248 | // Header file WiringPi/devLib/scrollPhat.h 249 | extern void scrollPhatPoint (int x, int y, int colour) ; 250 | extern void scrollPhatLine (int x0, int y0, int x1, int y1, int colour) ; 251 | extern void scrollPhatLineTo (int x, int y, int colour) ; 252 | extern void scrollPhatRectangle (int x1, int y1, int x2, int y2, int colour, int filled) ; 253 | extern void scrollPhatUpdate (void) ; 254 | extern void scrollPhatClear (void) ; 255 | extern int scrollPhatPutchar (int c) ; 256 | extern void scrollPhatPuts (const char *str) ; 257 | extern void scrollPhatPrintf (const char *message, ...) ; 258 | extern void scrollPhatPrintSpeed (const int cps10) ; 259 | extern void scrollPhatIntensity (const int percent) ; 260 | extern int scrollPhatSetup (void) ; 261 | 262 | // Header file WiringPi/devLib/piFace.h 263 | extern int piFaceSetup (const int pinBase) ; 264 | -------------------------------------------------------------------------------- /constants.py: -------------------------------------------------------------------------------- 1 | %pythoncode %{ 2 | # wiringPi modes 3 | 4 | WPI_MODE_PINS = 0; 5 | WPI_MODE_GPIO = 1; 6 | WPI_MODE_GPIO_SYS = 2; 7 | WPI_MODE_PHYS = 3; 8 | WPI_MODE_PIFACE = 4; 9 | WPI_MODE_UNINITIALISED = -1; 10 | 11 | # Pin modes 12 | 13 | INPUT = 0; 14 | OUTPUT = 1; 15 | INPUT_PULLUP = 2; 16 | INPUT_PULLDOWN = 3; 17 | PWM_OUTPUT = 4; 18 | GPIO_CLOCK = 5; 19 | SOFT_PWM_OUTPUT = 6; 20 | SOFT_TONE_OUTPUT = 7; 21 | PWM_TONE_OUTPUT = 8; 22 | 23 | LOW = 0; 24 | HIGH = 1; 25 | 26 | # Pull up/down/none 27 | 28 | PUD_OFF = 0; 29 | PUD_DOWN = 1; 30 | PUD_UP = 2; 31 | 32 | # Interrupt levels 33 | 34 | INT_EDGE_SETUP = 0; 35 | INT_EDGE_FALLING = 1; 36 | INT_EDGE_RISING = 2; 37 | INT_EDGE_BOTH = 3; 38 | 39 | # Shifting (from wiringShift.h) 40 | 41 | LSBFIRST = 0; 42 | MSBFIRST = 1; 43 | 44 | %} 45 | -------------------------------------------------------------------------------- /examples/RUN_THESE_WITH_SUDO: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/WiringPi2-Python/1aaadcbca2c7e9fa45692ad71ca717eb2f975ba6/examples/RUN_THESE_WITH_SUDO -------------------------------------------------------------------------------- /examples/callback.py: -------------------------------------------------------------------------------- 1 | import wiringpi 2 | PIN_TO_SENSE = 23 3 | 4 | def gpio_callback(): 5 | print "GPIO_CALLBACK!" 6 | 7 | wiringpi.wiringPiSetupGpio() 8 | wiringpi.pinMode(PIN_TO_SENSE, wiringpi.GPIO.INPUT) 9 | wiringpi.pullUpDnControl(PIN_TO_SENSE, wiringpi.GPIO.PUD_UP) 10 | 11 | wiringpi.wiringPiISR(PIN_TO_SENSE, wiringpi.GPIO.INT_EDGE_BOTH, gpio_callback) 12 | 13 | while True: 14 | wiringpi.delay(2000) 15 | -------------------------------------------------------------------------------- /examples/delay.py: -------------------------------------------------------------------------------- 1 | # Demonstrates use of Arduino-like delay function 2 | import wiringpi 3 | print 'Hello World' 4 | wiringpi.delay(1500) # Delay for 1.5 seconds 5 | print 'Hi again!' 6 | -------------------------------------------------------------------------------- /examples/ladder-board.py: -------------------------------------------------------------------------------- 1 | import wiringpi 2 | INPUT = 0 3 | OUTPUT = 1 4 | LOW = 0 5 | HIGH = 1 6 | BUTTONS = [13,12,10,11] 7 | LEDS = [0,1,2,3,4,5,6,7,8,9] 8 | PUD_UP = 2 9 | 10 | wiringpi.wiringPiSetup() 11 | 12 | for button in BUTTONS: 13 | wiringpi.pinMode(button,INPUT) 14 | wiringpi.pullUpDnControl(button,PUD_UP) 15 | 16 | for led in LEDS: 17 | wiringpi.pinMode(led,OUTPUT) 18 | 19 | while 1: 20 | for index,button in enumerate(BUTTONS): 21 | button_state = wiringpi.digitalRead(button) 22 | first_led = LEDS[index*2] 23 | second_led = LEDS[(index*2)+1] 24 | #print str(button) + ' ' + str(button_state) 25 | wiringpi.digitalWrite(first_led,1-button_state) 26 | wiringpi.digitalWrite(second_led,1-button_state) 27 | wiringpi.delay(20) 28 | -------------------------------------------------------------------------------- /examples/n5510-mcp23017.py: -------------------------------------------------------------------------------- 1 | # Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander ) 2 | import wiringpi 3 | 4 | PIN_BACKLIGHT = 67 # LED 5 | PIN_SCLK = 68 # Clock SCLK 6 | PIN_SDIN = 69 # DN(MOSI) 7 | PIN_DC = 70 # D/C 8 | PIN_RESET = 71 # RST Reset 9 | PIN_SCE = 72 # SCE 10 | 11 | #PIN_BACKLIGHT = 5 12 | #PIN_SCLK = 4 13 | #PIN_SDIN = 3 14 | #PIN_DC = 2 15 | #PIN_RESET = 1 16 | #PIN_SCE = 0 17 | 18 | OUTPUT = 1 19 | INPUT = 0 20 | HIGH = 1 21 | LOW = 0 22 | 23 | LCD_C = 0 24 | LCD_D = 1 25 | 26 | LCD_X = 84 27 | LCD_Y = 48 28 | LCD_SEGS = 504 29 | 30 | MSBFIRST = 1 31 | LSBFIRST = 0 32 | 33 | SLOW_DOWN = 400 34 | 35 | pin_base = 65 36 | i2c_addr = 0x21 37 | 38 | wiringpi.wiringPiSetup() 39 | wiringpi.mcp23017Setup(pin_base,i2c_addr) 40 | 41 | def slow_shift_out(data_pin, clock_pin, data): 42 | for bit in bin(data).replace('0b','').rjust(8,'0'): 43 | wiringpi.digitalWrite(clock_pin,LOW) 44 | wiringpi.delay(SLOW_DOWN) 45 | wiringpi.digitalWrite(data_pin,int(bit)) 46 | wiringpi.delay(SLOW_DOWN) 47 | wiringpi.digitalWrite(clock_pin,HIGH) 48 | wiringpi.delay(SLOW_DOWN) 49 | 50 | def lcd_write(dc, data): 51 | wiringpi.digitalWrite(PIN_DC, dc) 52 | wiringpi.digitalWrite(PIN_SCE, LOW) 53 | wiringpi.delay(SLOW_DOWN) 54 | #wiringpi.shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data) 55 | slow_shift_out(PIN_SDIN, PIN_SCLK, data) 56 | wiringpi.digitalWrite(PIN_SCE, HIGH) 57 | wiringpi.delay(SLOW_DOWN) 58 | #wiringpi.delay(2) 59 | 60 | def lcd_initialise(): 61 | wiringpi.pinMode(PIN_BACKLIGHT,OUTPUT) 62 | wiringpi.digitalWrite(PIN_BACKLIGHT, HIGH) 63 | wiringpi.pinMode(PIN_SCE, OUTPUT) 64 | wiringpi.pinMode(PIN_RESET, OUTPUT) 65 | wiringpi.pinMode(PIN_DC, OUTPUT) 66 | wiringpi.pinMode(PIN_SDIN, OUTPUT) 67 | wiringpi.pinMode(PIN_SCLK, OUTPUT) 68 | wiringpi.digitalWrite(PIN_RESET, LOW) 69 | wiringpi.delay(SLOW_DOWN) 70 | wiringpi.digitalWrite(PIN_RESET, HIGH) 71 | wiringpi.delay(SLOW_DOWN) 72 | lcd_write(LCD_C, 0x21 ) # LCD Extended Commands. 73 | lcd_write(LCD_C, 0xCC ) # Set LCD Vop (Contrast). 74 | lcd_write(LCD_C, 0x04 ) # Set Temp coefficent. //0x04 75 | lcd_write(LCD_C, 0x14 ) # LCD bias mode 1:48. //0x13 76 | lcd_write(LCD_C, 0x0C ) # LCD in normal mode. 77 | lcd_write(LCD_C, 0x20 ) 78 | lcd_write(LCD_C, 0x0C ) 79 | 80 | def lcd_clear(): 81 | for time in range(0, LCD_SEGS): 82 | lcd_write(LCD_D, 0x00) 83 | 84 | def lcd_fill(): 85 | for time in range(0, LCD_SEGS): 86 | lcd_write(LCD_D, 0xFF) 87 | 88 | 89 | lcd_initialise() 90 | 91 | for time in range(0,4): 92 | lcd_clear() 93 | wiringpi.delay(1000) 94 | lcd_fill() 95 | wiringpi.delay(1000) 96 | -------------------------------------------------------------------------------- /examples/quick2wire-io.py: -------------------------------------------------------------------------------- 1 | # Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander ) 2 | import wiringpi 3 | 4 | pin_base = 65 5 | i2c_addr = 0x20 6 | pins = [65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80] 7 | 8 | wiringpi.wiringPiSetup() 9 | wiringpi.mcp23017Setup(pin_base,i2c_addr) 10 | 11 | for pin in pins: 12 | wiringpi.pinMode(pin,1) 13 | wiringpi.digitalWrite(pin,1) 14 | # wiringpi.delay(1000) 15 | # wiringpi.digitalWrite(pin,0) 16 | -------------------------------------------------------------------------------- /examples/softpwm.py: -------------------------------------------------------------------------------- 1 | # Pulsates an LED connected to GPIO pin 1 with a suitable resistor 4 times using softPwm 2 | # softPwm uses a fixed frequency 3 | import wiringpi 4 | 5 | OUTPUT = 1 6 | 7 | PIN_TO_PWM = 1 8 | 9 | wiringpi.wiringPiSetup() 10 | wiringpi.pinMode(PIN_TO_PWM,OUTPUT) 11 | wiringpi.softPwmCreate(PIN_TO_PWM,0,100) # Setup PWM using Pin, Initial Value and Range parameters 12 | 13 | for time in range(0,4): 14 | for brightness in range(0,100): # Going from 0 to 100 will give us full off to full on 15 | wiringpi.softPwmWrite(PIN_TO_PWM,brightness) # Change PWM duty cycle 16 | wiringpi.delay(10) # Delay for 0.2 seconds 17 | for brightness in reversed(range(0,100)): 18 | wiringpi.softPwmWrite(PIN_TO_PWM,brightness) 19 | wiringpi.delay(10) 20 | -------------------------------------------------------------------------------- /examples/two-mcp23017.py: -------------------------------------------------------------------------------- 1 | # Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander ) 2 | import wiringpi 3 | 4 | pin_base = 65 5 | i2c_addr = 0x20 6 | i2c_addr_2 = 0x21 7 | #pins = [65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80] 8 | 9 | wiringpi.wiringPiSetup() 10 | wiringpi.mcp23017Setup(pin_base,i2c_addr) 11 | wiringpi.mcp23017Setup(pin_base+16,i2c_addr_2) 12 | 13 | #for pin in pins: 14 | for pin in range(65,96): 15 | wiringpi.pinMode(pin,1) 16 | wiringpi.digitalWrite(pin,1) 17 | # wiringpi.delay(1000) 18 | # wiringpi.digitalWrite(pin,0) 19 | -------------------------------------------------------------------------------- /generate-bindings.py: -------------------------------------------------------------------------------- 1 | HEADERS = [] 2 | 3 | src = open("wiringpi.i").read().split('\n') 4 | 5 | for line in src: 6 | line = line.strip() 7 | if line.startswith('#include') and line.endswith('.h"'): 8 | HEADERS.append(line.replace('#include','').replace('"','').strip()) 9 | 10 | #print(HEADERS) 11 | 12 | def is_c_decl(line): 13 | for fn in ['wiringPiISR','wiringPiSetupPiFace','wiringPiSetupPiFaceForGpioProg']: 14 | if fn in line: 15 | if 'wiringPiISRCancel' in line: 16 | return True 17 | else: 18 | return False 19 | for prefix in ['extern','void','int','uint8_t']: 20 | if line.startswith(prefix): 21 | return True 22 | 23 | print("// Generated by generate-bindings.py - do not edit manually!") 24 | 25 | for file in HEADERS: 26 | print("\n// Header file {}".format(file)) 27 | h = open(file).read().split('\n') 28 | extern = False 29 | cont = False 30 | if 'extern "C" {' not in h: 31 | extern = True 32 | for line in h: 33 | line = line.strip() 34 | if 'UNU' in line[-5:]: 35 | line = line[:-5] + ';' 36 | if cont: 37 | print("\t{}".format(line)) 38 | cont = ";" not in line 39 | continue 40 | if line.startswith('extern "C"'): 41 | extern = True 42 | continue 43 | if is_c_decl(line) and extern: 44 | print(line) 45 | cont = ";" not in line 46 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | author= Deokgyu Yang 3 | author_email= secugyu@gmail.com 4 | url= https://github.com/hardkernel/WiringPi2-Python 5 | description= A Port of WiringPi Python project for ODROID boards 6 | long_description = file:README.rst 7 | license = LGPL 8 | 9 | [bdist_wheel] 10 | universal = 1 11 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | import sys 5 | 6 | from setuptools import setup, Extension 7 | from setuptools.command.build_py import build_py 8 | from setuptools.command.sdist import sdist 9 | from distutils.spawn import find_executable 10 | from glob import glob 11 | 12 | sources = glob('WiringPi/devLib/*.c') 13 | sources += glob('WiringPi/wiringPi/*.c') 14 | 15 | # Exclude template file. 16 | sources = list(set(sources) - set(glob('WiringPi/wiringPi/odroid_template.c'))) 17 | 18 | # If we have swig, use it. Otherwise, use the pre-generated 19 | # wrapper from the source distribution. 20 | if find_executable('swig'): 21 | sources += ['wiringpi.i'] 22 | elif os.path.exists('wiringpi_wrap.c'): 23 | sources += ['wiringpi_wrap.c'] 24 | else: 25 | print("Error: Building this module requires either that swig is installed\n" 26 | " (e.g., 'sudo apt install swig') or that wiringpi_wrap.c from the\n" 27 | " source distribution (on pypi) is available.") 28 | sys.exit(1) 29 | 30 | try: 31 | sources.remove('WiringPi/devLib/piFaceOld.c') 32 | except ValueError: 33 | # the file is already excluded in the source distribution 34 | pass 35 | 36 | 37 | # Fix so that build_ext runs before build_py 38 | # Without this, wiringpi.py is generated too late and doesn't 39 | # end up in the distribution when running setup.py bdist or bdist_wheel. 40 | # Based on: 41 | # https://stackoverflow.com/a/29551581/7938656 42 | # and 43 | # https://blog.niteoweb.com/setuptools-run-custom-code-in-setup-py/ 44 | class build_py_ext_first(build_py): 45 | def run(self): 46 | self.run_command("build_ext") 47 | return build_py.run(self) 48 | 49 | 50 | # Make sure wiringpi_wrap.c is available for the source dist, also. 51 | class sdist_ext_first(sdist): 52 | def run(self): 53 | self.run_command("build_ext") 54 | return sdist.run(self) 55 | 56 | 57 | _odroid_wiringpi = Extension( 58 | '_odroid_wiringpi', 59 | include_dirs=['WiringPi/wiringPi','WiringPi/devLib'], 60 | sources=sources, 61 | swig_opts=['-threads'], 62 | extra_link_args=['-lcrypt', '-lrt'], 63 | ) 64 | 65 | setup( 66 | name = 'odroid_wiringpi', 67 | version = '3.17.0', 68 | ext_modules = [ _odroid_wiringpi ], 69 | py_modules = ["odroid_wiringpi"], 70 | install_requires=[], 71 | cmdclass = {'build_py' : build_py_ext_first, 'sdist' : sdist_ext_first}, 72 | ) 73 | -------------------------------------------------------------------------------- /tests/piglow.py: -------------------------------------------------------------------------------- 1 | import wiringpi 2 | io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS) 3 | io.piGlowSetup() 4 | io.piGlowLeg(1,100) 5 | -------------------------------------------------------------------------------- /tests/test.py: -------------------------------------------------------------------------------- 1 | import wiringpi 2 | io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS) 3 | print io.digitalRead(1) 4 | print io.analogRead(1) 5 | -------------------------------------------------------------------------------- /wiringpi-class.py: -------------------------------------------------------------------------------- 1 | %pythoncode %{ 2 | class nes(object): 3 | def setupNesJoystick(self,*args): 4 | return setupNesJoystick(*args) 5 | def readNesJoystick(self,*args): 6 | return readNesJoystick(*args) 7 | 8 | class Serial(object): 9 | device = '/dev/ttyAMA0' 10 | baud = 9600 11 | serial_id = 0 12 | def printf(self,*args): 13 | return serialPrintf(self.serial_id,*args) 14 | def dataAvail(self,*args): 15 | return serialDataAvail(self.serial_id,*args) 16 | def getchar(self,*args): 17 | return serialGetchar(self.serial_id,*args) 18 | def putchar(self,*args): 19 | return serialPutchar(self.serial_id,*args) 20 | def puts(self,*args): 21 | return serialPuts(self.serial_id,*args) 22 | def __init__(self,device,baud): 23 | self.device = device 24 | self.baud = baud 25 | self.serial_id = serialOpen(self.device,self.baud) 26 | def __del__(self): 27 | serialClose(self.serial_id) 28 | 29 | class I2C(object): 30 | def setupInterface(self,*args): 31 | return wiringPiI2CSetupInterface(*args) 32 | def setup(self,*args): 33 | return wiringPiI2CSetup(*args) 34 | def read(self,*args): 35 | return wiringPiI2CRead(*args) 36 | def readReg8(self,*args): 37 | return wiringPiI2CReadReg8(*args) 38 | def readReg16(self,*args): 39 | return wiringPiI2CReadReg16(*args) 40 | def readBlock(self,*args): 41 | return wiringPiI2CReadBlock(*args) 42 | def write(self,*args): 43 | return wiringPiI2CWrite(*args) 44 | def writeReg8(self,*args): 45 | return wiringPiI2CWriteReg8(*args) 46 | def writeReg16(self,*args): 47 | return wiringPiI2CWriteReg16(*args) 48 | def writeBlock(self,*args): 49 | return wiringPiI2CWriteBlock(*args) 50 | 51 | class GPIO(object): 52 | WPI_MODE_PINS = 0 53 | WPI_MODE_GPIO = 1 54 | WPI_MODE_GPIO_SYS = 2 55 | WPI_MODE_PHYS = 3 56 | WPI_MODE_PIFACE = 4 57 | WPI_MODE_UNINITIALISED = -1 58 | 59 | INPUT = 0 60 | OUTPUT = 1 61 | PWM_OUTPUT = 2 62 | GPIO_CLOCK = 3 63 | 64 | LOW = 0 65 | HIGH = 1 66 | 67 | PUD_OFF = 0 68 | PUD_DOWN = 1 69 | PUD_UP = 2 70 | 71 | INT_EDGE_SETUP = 0 72 | INT_EDGE_FALLING = 1 73 | INT_EDGE_RISING = 2 74 | INT_EDGE_BOTH = 3 75 | 76 | LSBFIRST = 0 77 | MSBFIRST = 1 78 | 79 | MODE = 0 80 | def __init__(self,pinmode=0): 81 | self.MODE=pinmode 82 | if pinmode==self.WPI_MODE_PINS: 83 | wiringPiSetup() 84 | if pinmode==self.WPI_MODE_GPIO: 85 | wiringPiSetupGpio() 86 | if pinmode==self.WPI_MODE_GPIO_SYS: 87 | wiringPiSetupSys() 88 | if pinmode==self.WPI_MODE_PHYS: 89 | wiringPiSetupPhys() 90 | 91 | def delay(self,*args): 92 | delay(*args) 93 | def delayMicroseconds(self,*args): 94 | delayMicroseconds(*args) 95 | def millis(self): 96 | return millis() 97 | def micros(self): 98 | return micros() 99 | 100 | def piHiPri(self,*args): 101 | return piHiPri(*args) 102 | 103 | def wpiPinToGpio(self,*args): 104 | return wpiPinToGpio(*args) 105 | def getAlt(self,*args): 106 | return getAlt(*args) 107 | def digitalWriteByte(self,*args): 108 | return digitalWriteByte(*args) 109 | 110 | def setDrive(self,*args): 111 | setDrive(*args) 112 | def getDrive(self,*args): 113 | return getDrive(*args) 114 | def getPUPD(self,*args): 115 | return getPUPD(*args) 116 | 117 | def pwmSetRange(self,*args): 118 | pwmSetRange(*args) 119 | def pwmSetClock(self,*args): 120 | pwmSetClock(*args) 121 | def gpioClockSet(self,*args): 122 | gpioClockSet(*args) 123 | def pwmWrite(self,*args): 124 | pwmWrite(*args) 125 | 126 | def pinMode(self,*args): 127 | pinMode(*args) 128 | 129 | def digitalWrite(self,*args): 130 | digitalWrite(*args) 131 | def digitalRead(self,*args): 132 | return digitalRead(*args) 133 | def digitalWriteByte(self,*args): 134 | digitalWriteByte(*args) 135 | 136 | def analogWrite(self,*args): 137 | analogWrite(*args) 138 | def analogRead(self,*args): 139 | return analogRead(*args) 140 | 141 | def shiftOut(self,*args): 142 | shiftOut(*args) 143 | def shiftIn(self,*args): 144 | return shiftIn(*args) 145 | 146 | def pullUpDnControl(self,*args): 147 | return pullUpDnControl(*args) 148 | 149 | def waitForInterrupt(self,*args): 150 | return waitForInterrupt(*args) 151 | def wiringPiISR(self,*args): 152 | return wiringPiISR(*args) 153 | 154 | def softPwmCreate(self,*args): 155 | return softPwmCreate(*args) 156 | def softPwmWrite(self,*args): 157 | return softPwmWrite(*args) 158 | 159 | def softToneCreate(self,*args): 160 | return softToneCreate(*args) 161 | def softToneWrite(self,*args): 162 | return softToneWrite(*args) 163 | 164 | def setupCheck(self, *args): 165 | setupCheck(*args) 166 | def usingGpiomemCheck(self, *args): 167 | usingGpiomemCheck(*args) 168 | def setUsingGpiomem(self, *args): 169 | setUsingGpiomem(*args) 170 | 171 | def lcdHome(self,*args): 172 | return lcdHome(self,*args) 173 | def lcdCLear(self,*args): 174 | return lcdClear(self,*args) 175 | def lcdSendCommand(self,*args): 176 | return lcdSendCommand(self,*args) 177 | def lcdPosition(self,*args): 178 | return lcdPosition(self,*args) 179 | def lcdPutchar(self,*args): 180 | return lcdPutchar(self,*args) 181 | def lcdPuts(self,*args): 182 | return lcdPuts(self,*args) 183 | def lcdPrintf(self,*args): 184 | return lcdPrintf(self,*args) 185 | def lcdInit(self,*args): 186 | return lcdInit(self,*args) 187 | 188 | def piGlowSetup(self,*args): 189 | return piGlowSetup(self,*args) 190 | def piGlow1(self,*args): 191 | return piGlow1(self,*args) 192 | def piGlowLeg(self,*args): 193 | return piGlowLeg(self,*args) 194 | def piGlowRing(self,*args): 195 | return piGlowRing(self,*args) 196 | %} 197 | -------------------------------------------------------------------------------- /wiringpi.i: -------------------------------------------------------------------------------- 1 | %module odroid_wiringpi 2 | 3 | %{ 4 | #if PY_MAJOR_VERSION >= 3 5 | #define PyInt_AS_LONG PyLong_AsLong 6 | #define PyString_FromStringAndSize PyBytes_FromStringAndSize 7 | #endif 8 | 9 | #include "WiringPi/wiringPi/wiringPi.h" 10 | #include "WiringPi/wiringPi/wiringPiI2C.h" 11 | #include "WiringPi/wiringPi/wiringPiSPI.h" 12 | #include "WiringPi/wiringPi/wiringSerial.h" 13 | #include "WiringPi/wiringPi/wiringShift.h" 14 | #include "WiringPi/wiringPi/softPwm.h" 15 | #include "WiringPi/wiringPi/softServo.h" 16 | #include "WiringPi/wiringPi/softTone.h" 17 | #include "WiringPi/wiringPi/drcSerial.h" 18 | #include "WiringPi/wiringPi/ads1115.h" 19 | #include "WiringPi/wiringPi/max31855.h" 20 | #include "WiringPi/wiringPi/max5322.h" 21 | #include "WiringPi/wiringPi/mcp23008.h" 22 | #include "WiringPi/wiringPi/mcp23016.h" 23 | #include "WiringPi/wiringPi/mcp23016reg.h" 24 | #include "WiringPi/wiringPi/mcp23017.h" 25 | #include "WiringPi/wiringPi/mcp23s08.h" 26 | #include "WiringPi/wiringPi/mcp23s17.h" 27 | #include "WiringPi/wiringPi/mcp23x0817.h" 28 | #include "WiringPi/wiringPi/mcp23x08.h" 29 | #include "WiringPi/wiringPi/mcp3002.h" 30 | #include "WiringPi/wiringPi/mcp3004.h" 31 | #include "WiringPi/wiringPi/mcp3422.h" 32 | #include "WiringPi/wiringPi/mcp4802.h" 33 | #include "WiringPi/wiringPi/pcf8574.h" 34 | #include "WiringPi/wiringPi/pcf8591.h" 35 | #include "WiringPi/wiringPi/sn3218.h" 36 | #include "WiringPi/wiringPi/sr595.h" 37 | #include "WiringPi/wiringPi/bmp180.h" 38 | #include "WiringPi/wiringPi/drcNet.h" 39 | #include "WiringPi/wiringPi/ds18b20.h" 40 | #include "WiringPi/wiringPi/htu21d.h" 41 | #include "WiringPi/wiringPi/pseudoPins.h" 42 | #include "WiringPi/wiringPi/rht03.h" 43 | #include "WiringPi/wiringPi/wpiExtensions.h" 44 | #include "WiringPi/devLib/ds1302.h" 45 | #include "WiringPi/devLib/font.h" 46 | #include "WiringPi/devLib/gertboard.h" 47 | #include "WiringPi/devLib/lcd128x64.h" 48 | #include "WiringPi/devLib/lcd.h" 49 | #include "WiringPi/devLib/maxdetect.h" 50 | #include "WiringPi/devLib/piGlow.h" 51 | #include "WiringPi/devLib/piNes.h" 52 | #include "WiringPi/devLib/scrollPhat.h" 53 | #include "WiringPi/devLib/piFace.h" 54 | %} 55 | 56 | %apply unsigned char { uint8_t }; 57 | %typemap(in) (unsigned char *data, int len) { 58 | $1 = (unsigned char *) PyString_AsString($input); 59 | $2 = PyString_Size($input); 60 | }; 61 | 62 | // Grab a Python function object as a Python object. 63 | %typemap(in) PyObject *PyFunc { 64 | if (!PyCallable_Check($input)) { 65 | PyErr_SetString(PyExc_TypeError, "Need a callable object!"); 66 | return NULL; 67 | } 68 | $1 = $input; 69 | } 70 | 71 | %{ 72 | 73 | // we need to have our own callbacks array 74 | PyObject* event_callback[64] = {0,}; 75 | 76 | void _wiringPiISR_callback(int pinNumber) { 77 | PyObject *result; 78 | 79 | if (event_callback[pinNumber]) { 80 | // this will acquire the GIL 81 | SWIG_PYTHON_THREAD_BEGIN_BLOCK; 82 | 83 | result = PyObject_CallFunction(event_callback[pinNumber], NULL); 84 | if (result == NULL && PyErr_Occurred()) { 85 | PyErr_Print(); 86 | PyErr_Clear(); 87 | } 88 | Py_XDECREF(result); 89 | 90 | // release the GIL 91 | SWIG_PYTHON_THREAD_END_BLOCK; 92 | } 93 | } 94 | 95 | 96 | /* This is embarrasing, WiringPi does not support supplying args to the callback 97 | ... so we have to create callback function for each of the pins :( */ 98 | void _wiringPiISR_callback_pin0(void) { _wiringPiISR_callback(0); } 99 | void _wiringPiISR_callback_pin1(void) { _wiringPiISR_callback(1); } 100 | void _wiringPiISR_callback_pin2(void) { _wiringPiISR_callback(2); } 101 | void _wiringPiISR_callback_pin3(void) { _wiringPiISR_callback(3); } 102 | void _wiringPiISR_callback_pin4(void) { _wiringPiISR_callback(4); } 103 | void _wiringPiISR_callback_pin5(void) { _wiringPiISR_callback(5); } 104 | void _wiringPiISR_callback_pin6(void) { _wiringPiISR_callback(6); } 105 | void _wiringPiISR_callback_pin7(void) { _wiringPiISR_callback(7); } 106 | void _wiringPiISR_callback_pin8(void) { _wiringPiISR_callback(8); } 107 | void _wiringPiISR_callback_pin9(void) { _wiringPiISR_callback(9); } 108 | void _wiringPiISR_callback_pin10(void) { _wiringPiISR_callback(10); } 109 | void _wiringPiISR_callback_pin11(void) { _wiringPiISR_callback(11); } 110 | void _wiringPiISR_callback_pin12(void) { _wiringPiISR_callback(12); } 111 | void _wiringPiISR_callback_pin13(void) { _wiringPiISR_callback(13); } 112 | void _wiringPiISR_callback_pin14(void) { _wiringPiISR_callback(14); } 113 | void _wiringPiISR_callback_pin15(void) { _wiringPiISR_callback(15); } 114 | void _wiringPiISR_callback_pin16(void) { _wiringPiISR_callback(16); } 115 | void _wiringPiISR_callback_pin17(void) { _wiringPiISR_callback(17); } 116 | void _wiringPiISR_callback_pin18(void) { _wiringPiISR_callback(18); } 117 | void _wiringPiISR_callback_pin19(void) { _wiringPiISR_callback(19); } 118 | void _wiringPiISR_callback_pin20(void) { _wiringPiISR_callback(20); } 119 | void _wiringPiISR_callback_pin21(void) { _wiringPiISR_callback(21); } 120 | void _wiringPiISR_callback_pin22(void) { _wiringPiISR_callback(22); } 121 | void _wiringPiISR_callback_pin23(void) { _wiringPiISR_callback(23); } 122 | void _wiringPiISR_callback_pin24(void) { _wiringPiISR_callback(24); } 123 | void _wiringPiISR_callback_pin25(void) { _wiringPiISR_callback(25); } 124 | void _wiringPiISR_callback_pin26(void) { _wiringPiISR_callback(26); } 125 | void _wiringPiISR_callback_pin27(void) { _wiringPiISR_callback(27); } 126 | void _wiringPiISR_callback_pin28(void) { _wiringPiISR_callback(28); } 127 | void _wiringPiISR_callback_pin29(void) { _wiringPiISR_callback(29); } 128 | void _wiringPiISR_callback_pin30(void) { _wiringPiISR_callback(30); } 129 | void _wiringPiISR_callback_pin31(void) { _wiringPiISR_callback(31); } 130 | void _wiringPiISR_callback_pin32(void) { _wiringPiISR_callback(32); } 131 | void _wiringPiISR_callback_pin33(void) { _wiringPiISR_callback(33); } 132 | void _wiringPiISR_callback_pin34(void) { _wiringPiISR_callback(34); } 133 | void _wiringPiISR_callback_pin35(void) { _wiringPiISR_callback(35); } 134 | void _wiringPiISR_callback_pin36(void) { _wiringPiISR_callback(36); } 135 | void _wiringPiISR_callback_pin37(void) { _wiringPiISR_callback(37); } 136 | void _wiringPiISR_callback_pin38(void) { _wiringPiISR_callback(38); } 137 | void _wiringPiISR_callback_pin39(void) { _wiringPiISR_callback(39); } 138 | void _wiringPiISR_callback_pin40(void) { _wiringPiISR_callback(40); } 139 | void _wiringPiISR_callback_pin41(void) { _wiringPiISR_callback(41); } 140 | void _wiringPiISR_callback_pin42(void) { _wiringPiISR_callback(42); } 141 | void _wiringPiISR_callback_pin43(void) { _wiringPiISR_callback(43); } 142 | void _wiringPiISR_callback_pin44(void) { _wiringPiISR_callback(44); } 143 | void _wiringPiISR_callback_pin45(void) { _wiringPiISR_callback(45); } 144 | void _wiringPiISR_callback_pin46(void) { _wiringPiISR_callback(46); } 145 | void _wiringPiISR_callback_pin47(void) { _wiringPiISR_callback(47); } 146 | void _wiringPiISR_callback_pin48(void) { _wiringPiISR_callback(48); } 147 | void _wiringPiISR_callback_pin49(void) { _wiringPiISR_callback(49); } 148 | void _wiringPiISR_callback_pin50(void) { _wiringPiISR_callback(50); } 149 | void _wiringPiISR_callback_pin51(void) { _wiringPiISR_callback(51); } 150 | void _wiringPiISR_callback_pin52(void) { _wiringPiISR_callback(52); } 151 | void _wiringPiISR_callback_pin53(void) { _wiringPiISR_callback(53); } 152 | void _wiringPiISR_callback_pin54(void) { _wiringPiISR_callback(54); } 153 | void _wiringPiISR_callback_pin55(void) { _wiringPiISR_callback(55); } 154 | void _wiringPiISR_callback_pin56(void) { _wiringPiISR_callback(56); } 155 | void _wiringPiISR_callback_pin57(void) { _wiringPiISR_callback(57); } 156 | void _wiringPiISR_callback_pin58(void) { _wiringPiISR_callback(58); } 157 | void _wiringPiISR_callback_pin59(void) { _wiringPiISR_callback(59); } 158 | void _wiringPiISR_callback_pin60(void) { _wiringPiISR_callback(60); } 159 | void _wiringPiISR_callback_pin61(void) { _wiringPiISR_callback(61); } 160 | void _wiringPiISR_callback_pin62(void) { _wiringPiISR_callback(62); } 161 | void _wiringPiISR_callback_pin63(void) { _wiringPiISR_callback(63); } 162 | 163 | /* This function adds a new Python function object as a callback object */ 164 | 165 | static void wiringPiISRWrapper(int pin, int mode, PyObject *PyFunc) { 166 | 167 | // remove the old callback if any 168 | if (event_callback[pin]) { 169 | Py_XDECREF(event_callback[pin]); 170 | } 171 | 172 | // put new callback function 173 | event_callback[pin] = PyFunc; 174 | Py_INCREF(PyFunc); 175 | 176 | // and now the ugly switch 177 | void (*func)(void); 178 | switch(pin) { 179 | case 0: func = &_wiringPiISR_callback_pin0; break; 180 | case 1: func = &_wiringPiISR_callback_pin1; break; 181 | case 2: func = &_wiringPiISR_callback_pin2; break; 182 | case 3: func = &_wiringPiISR_callback_pin3; break; 183 | case 4: func = &_wiringPiISR_callback_pin4; break; 184 | case 5: func = &_wiringPiISR_callback_pin5; break; 185 | case 6: func = &_wiringPiISR_callback_pin6; break; 186 | case 7: func = &_wiringPiISR_callback_pin7; break; 187 | case 8: func = &_wiringPiISR_callback_pin8; break; 188 | case 9: func = &_wiringPiISR_callback_pin9; break; 189 | case 10: func = &_wiringPiISR_callback_pin10; break; 190 | case 11: func = &_wiringPiISR_callback_pin11; break; 191 | case 12: func = &_wiringPiISR_callback_pin12; break; 192 | case 13: func = &_wiringPiISR_callback_pin13; break; 193 | case 14: func = &_wiringPiISR_callback_pin14; break; 194 | case 15: func = &_wiringPiISR_callback_pin15; break; 195 | case 16: func = &_wiringPiISR_callback_pin16; break; 196 | case 17: func = &_wiringPiISR_callback_pin17; break; 197 | case 18: func = &_wiringPiISR_callback_pin18; break; 198 | case 19: func = &_wiringPiISR_callback_pin19; break; 199 | case 20: func = &_wiringPiISR_callback_pin20; break; 200 | case 21: func = &_wiringPiISR_callback_pin21; break; 201 | case 22: func = &_wiringPiISR_callback_pin22; break; 202 | case 23: func = &_wiringPiISR_callback_pin23; break; 203 | case 24: func = &_wiringPiISR_callback_pin24; break; 204 | case 25: func = &_wiringPiISR_callback_pin25; break; 205 | case 26: func = &_wiringPiISR_callback_pin26; break; 206 | case 27: func = &_wiringPiISR_callback_pin27; break; 207 | case 28: func = &_wiringPiISR_callback_pin28; break; 208 | case 29: func = &_wiringPiISR_callback_pin29; break; 209 | case 30: func = &_wiringPiISR_callback_pin30; break; 210 | case 31: func = &_wiringPiISR_callback_pin31; break; 211 | case 32: func = &_wiringPiISR_callback_pin32; break; 212 | case 33: func = &_wiringPiISR_callback_pin33; break; 213 | case 34: func = &_wiringPiISR_callback_pin34; break; 214 | case 35: func = &_wiringPiISR_callback_pin35; break; 215 | case 36: func = &_wiringPiISR_callback_pin36; break; 216 | case 37: func = &_wiringPiISR_callback_pin37; break; 217 | case 38: func = &_wiringPiISR_callback_pin38; break; 218 | case 39: func = &_wiringPiISR_callback_pin39; break; 219 | case 40: func = &_wiringPiISR_callback_pin40; break; 220 | case 41: func = &_wiringPiISR_callback_pin41; break; 221 | case 42: func = &_wiringPiISR_callback_pin42; break; 222 | case 43: func = &_wiringPiISR_callback_pin43; break; 223 | case 44: func = &_wiringPiISR_callback_pin44; break; 224 | case 45: func = &_wiringPiISR_callback_pin45; break; 225 | case 46: func = &_wiringPiISR_callback_pin46; break; 226 | case 47: func = &_wiringPiISR_callback_pin47; break; 227 | case 48: func = &_wiringPiISR_callback_pin48; break; 228 | case 49: func = &_wiringPiISR_callback_pin49; break; 229 | case 50: func = &_wiringPiISR_callback_pin50; break; 230 | case 51: func = &_wiringPiISR_callback_pin51; break; 231 | case 52: func = &_wiringPiISR_callback_pin52; break; 232 | case 53: func = &_wiringPiISR_callback_pin53; break; 233 | case 54: func = &_wiringPiISR_callback_pin54; break; 234 | case 55: func = &_wiringPiISR_callback_pin55; break; 235 | case 56: func = &_wiringPiISR_callback_pin56; break; 236 | case 57: func = &_wiringPiISR_callback_pin57; break; 237 | case 58: func = &_wiringPiISR_callback_pin58; break; 238 | case 59: func = &_wiringPiISR_callback_pin59; break; 239 | case 60: func = &_wiringPiISR_callback_pin60; break; 240 | case 61: func = &_wiringPiISR_callback_pin61; break; 241 | case 62: func = &_wiringPiISR_callback_pin62; break; 242 | case 63: func = &_wiringPiISR_callback_pin63; break; 243 | } 244 | 245 | // register our dedicated function in WiringPi 246 | wiringPiISR(pin, mode, func); 247 | } 248 | 249 | %} 250 | 251 | // overlay normal function with our wrapper 252 | %rename("wiringPiISR") wiringPiISRWrapper (int pin, int mode, PyObject *PyFunc); 253 | static void wiringPiISRWrapper(int pin, int mode, PyObject *PyFunc); 254 | 255 | %typemap(in) unsigned char data [8] { 256 | /* Check if is a list */ 257 | if (PyList_Check($input)) { 258 | if(PyList_Size($input) != 8){ 259 | PyErr_SetString(PyExc_TypeError,"must contain 8 items"); 260 | return NULL; 261 | } 262 | int i = 0; 263 | $1 = (unsigned char *) malloc(8); 264 | for (i = 0; i < 8; i++) { 265 | PyObject *o = PyList_GetItem($input,i); 266 | if (PyInt_Check(o) && PyInt_AsLong(PyList_GetItem($input,i)) <= 255 && PyInt_AsLong(PyList_GetItem($input,i)) >= 0) 267 | $1[i] = PyInt_AsLong(PyList_GetItem($input,i)); 268 | else { 269 | PyErr_SetString(PyExc_TypeError,"list must contain integers 0-255"); 270 | return NULL; 271 | } 272 | } 273 | } else { 274 | PyErr_SetString(PyExc_TypeError,"not a list"); 275 | return NULL; 276 | } 277 | }; 278 | 279 | %typemap(freearg) unsigned char data [8] { 280 | free((unsigned char *) $1); 281 | } 282 | 283 | %typemap(in) (unsigned char *data, int len) { 284 | $1 = (unsigned char *) PyString_AsString($input); 285 | $2 = PyString_Size($input); 286 | }; 287 | 288 | %typemap(argout) (unsigned char *data) { 289 | $result = SWIG_Python_AppendOutput($result, PyString_FromStringAndSize((char *) $1, result)); 290 | }; 291 | 292 | %include "bindings.i" 293 | %include "constants.py" 294 | %include "wiringpi-class.py" 295 | --------------------------------------------------------------------------------