├── examples ├── RUN_THESE_WITH_SUDO ├── delay.py ├── callback.py ├── orangepi-sensors │ ├── Light_Sensor.py │ ├── sensor_control_led.py │ ├── light.py │ ├── joystick.py │ ├── IO-expand.py │ ├── rotary_encoder.py │ ├── dht11.py │ ├── ds18b20.py │ ├── rtc.py │ └── oled_ssd1306.py ├── softtone.py ├── quick2wire-io.py ├── two-mcp23017.py ├── blink.py ├── ladder-board.py ├── softpwm.py ├── serialTest.py ├── spidev_test.py ├── n5510-mcp23017.py └── ds1307.py ├── .gitignore ├── tests ├── piglow.py ├── test.py └── test_wiringPi_GPIO.py ├── .gitmodules ├── fixUndefFunc.c ├── MANIFEST.in ├── Makefile ├── setup.cfg ├── CHANGES.txt ├── constants.py ├── generate-bindings.py ├── README.rst ├── wiringpi-class.py ├── setup.py ├── LICENSE.txt └── wiringpi.i /examples/RUN_THESE_WITH_SUDO: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | build/ 3 | *.egg-info/ 4 | dist/ 5 | __pycache__ 6 | *.pyc 7 | wiringpi_wrap.c 8 | wiringpi.py 9 | bindings.i -------------------------------------------------------------------------------- /tests/piglow.py: -------------------------------------------------------------------------------- 1 | import wiringpi 2 | io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS) 3 | io.piGlowSetup() 4 | io.piGlowLeg(1,100) 5 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "wiringOP"] 2 | path = wiringOP 3 | url = https://github.com/orangepi-xunlong/wiringOP.git 4 | branch = master 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 | -------------------------------------------------------------------------------- /fixUndefFunc.c: -------------------------------------------------------------------------------- 1 | #include 2 | unsigned int digitalRead8 (int pin) { return 0;} 3 | void digitalWrite8 (int pin, int value) {} -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | graft wiringOP/wiringPi 2 | graft wiringOP/devLib 3 | include README.rst 4 | include LICENSE.txt 5 | include setup.cfg 6 | include wiringpi.py 7 | include wiringpi_wrap.c 8 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/test_wiringPi_GPIO.py: -------------------------------------------------------------------------------- 1 | import wiringpi 2 | 3 | def test_wiringPiSetup(): 4 | assert wiringpi.wiringPiSetup() == 0 5 | 6 | def test_digitalRead(): 7 | assert wiringpi.digitalRead(1) != None 8 | def test_digitalWrite(): 9 | assert wiringpi.digitalWrite(1,0) == None -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: bindings 2 | python3 setup.py build 3 | 4 | bindings: 5 | python3 generate-bindings.py > bindings.i 6 | 7 | clean: 8 | rm -rf build dist wiringpi.egg-info 9 | rm -rf wiringpi.py wiringpi_wrap.c 10 | 11 | install: bindings 12 | sudo python3 setup.py install 13 | 14 | test: 15 | pytest tests 16 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | author = Philip Howard 3 | author_email = phil@gadgetoid.com 4 | url = https://github.com/WiringPi/WiringPi-Python/ 5 | 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. 6 | long_description = file:README.rst 7 | license = LGPL 8 | -------------------------------------------------------------------------------- /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/orangepi-sensors/Light_Sensor.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import time 3 | import wiringpi 4 | from wiringpi import GPIO 5 | 6 | I2C_ADDR = 0x48 7 | BASE = 64 8 | A0 = BASE+0 9 | 10 | wiringpi.wiringPiSetup() 11 | wiringpi.pcf8591Setup(BASE, I2C_ADDR) 12 | while True: 13 | try: 14 | value = wiringpi.analogRead(A0) 15 | print("value: %d"%value) 16 | time.sleep(2) 17 | except KeyboardInterrupt: 18 | print('\nExit') 19 | sys.exit(0) 20 | -------------------------------------------------------------------------------- /examples/softtone.py: -------------------------------------------------------------------------------- 1 | # Test of the softTone module in wiringPi 2 | # Plays a scale out on pin 3 - connect pizeo disc to pin 3 & 0v 3 | import wiringpi 4 | 5 | PIN = 3 6 | 7 | SCALE = [262, 294, 330, 349, 392, 440, 494, 525] 8 | 9 | wiringpi.wiringPiSetup() 10 | wiringpi.softToneCreate(PIN) 11 | 12 | while True: 13 | for idx in range(8): 14 | print(idx) 15 | wiringpi.softToneWrite(PIN, SCALE[idx]) 16 | wiringpi.delay(500) 17 | -------------------------------------------------------------------------------- /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/orangepi-sensors/sensor_control_led.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import wiringpi 3 | from wiringpi import GPIO 4 | 5 | LED = 6 6 | PIN = 16 7 | 8 | wiringpi.wiringPiSetup() 9 | wiringpi.pinMode(LED, GPIO.OUTPUT) 10 | wiringpi.pinMode(PIN, GPIO.INPUT) 11 | 12 | while True: 13 | try: 14 | if wiringpi.digitalRead(PIN): 15 | wiringpi.digitalWrite(LED, GPIO.LOW) 16 | else: 17 | wiringpi.digitalWrite(LED, GPIO.HIGH) 18 | except KeyboardInterrupt: 19 | print("\nexit") 20 | sys.exit(0) 21 | 22 | -------------------------------------------------------------------------------- /examples/orangepi-sensors/light.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import time 3 | import wiringpi 4 | from wiringpi import GPIO 5 | 6 | PIN = 6 7 | 8 | wiringpi.wiringPiSetup() 9 | wiringpi.pinMode(PIN, GPIO.OUTPUT) 10 | 11 | while True: 12 | try: 13 | wiringpi.digitalWrite(PIN, GPIO.HIGH) 14 | print(wiringpi.digitalRead(PIN)) 15 | time.sleep(1) 16 | wiringpi.digitalWrite(PIN, GPIO.LOW) 17 | print(wiringpi.digitalRead(PIN)) 18 | time.sleep(1) 19 | except KeyboardInterrupt: 20 | print("\nexit") 21 | sys.exit(0) 22 | 23 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /examples/orangepi-sensors/joystick.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import time 3 | import wiringpi 4 | from wiringpi import GPIO 5 | 6 | I2C_ADDR = 0x48 7 | BASE = 64 8 | A0 = BASE+0 9 | A1 = BASE+1 10 | 11 | wiringpi.wiringPiSetup() 12 | wiringpi.pcf8591Setup(BASE, I2C_ADDR) 13 | 14 | while True: 15 | try: 16 | i = 0 17 | while i < 2: 18 | if 0 == i: 19 | x = wiringpi.analogRead(A0) 20 | if 1 == i: 21 | y = wiringpi.analogRead(A1) 22 | i += 1 23 | print("X=%d Y=%d"%(x,y)) 24 | time.sleep(1) 25 | except KeyboardInterrupt: 26 | print('\nExit') 27 | sys.exit(0) 28 | -------------------------------------------------------------------------------- /examples/orangepi-sensors/IO-expand.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import time 3 | import wiringpi 4 | from wiringpi import GPIO 5 | 6 | I2C_ADDR = 0x38 7 | BASE = 100 8 | 9 | wiringpi.wiringPiSetup() 10 | wiringpi.pcf8574Setup(BASE, I2C_ADDR) 11 | 12 | i = 0 13 | while i < 8: 14 | wiringpi.pinMode(BASE + i, GPIO.OUTPUT) 15 | i += 1 16 | 17 | wiringpi.pinMode(BASE + 0, GPIO.OUTPUT) 18 | 19 | while True: 20 | try: 21 | wiringpi.digitalWrite(BASE + 0, GPIO.HIGH) 22 | time.sleep(1) 23 | wiringpi.digitalWrite(BASE + 0, GPIO.LOW) 24 | time.sleep(1) 25 | except KeyboardInterrupt: 26 | print('\nExit') 27 | sys.exit(0) 28 | 29 | -------------------------------------------------------------------------------- /examples/blink.py: -------------------------------------------------------------------------------- 1 | import wiringpi 2 | import time 3 | import sys 4 | from wiringpi import GPIO 5 | 6 | NUM = 17 #26pin 7 | #NUM = 18 #26pin 8 | #NUM = 20 #for Orange Pi Zero 2 9 | #NUM = 19 #for Orange Pi 4 10 | #NUM = 28 #40pin 11 | 12 | wiringpi.wiringPiSetup() 13 | 14 | for i in range(0, NUM): 15 | wiringpi.pinMode(i, GPIO.OUTPUT) ; 16 | 17 | while True: 18 | try: 19 | for i in range(0, NUM): 20 | wiringpi.digitalWrite(i, GPIO.HIGH) 21 | time.sleep(1) 22 | for i in range(0, NUM): 23 | wiringpi.digitalWrite(i, GPIO.LOW) 24 | time.sleep(1) 25 | except KeyboardInterrupt: 26 | print("\nexit") 27 | sys.exit(0) 28 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | PWM_OUTPUT = 2; 16 | GPIO_CLOCK = 3; 17 | SOFT_PWM_OUTPUT = 4; 18 | SOFT_TONE_OUTPUT = 5; 19 | PWM_TONE_OUTPUT = 6; 20 | 21 | LOW = 0; 22 | HIGH = 1; 23 | 24 | # Pull up/down/none 25 | 26 | PUD_OFF = 0; 27 | PUD_DOWN = 1; 28 | PUD_UP = 2; 29 | 30 | # PWM 31 | 32 | PWM_MODE_MS = 0; 33 | PWM_MODE_BAL = 1; 34 | 35 | # Interrupt levels 36 | 37 | INT_EDGE_SETUP = 0; 38 | INT_EDGE_FALLING = 1; 39 | INT_EDGE_RISING = 2; 40 | INT_EDGE_BOTH = 3; 41 | 42 | # Shifting (from wiringShift.h) 43 | 44 | LSBFIRST = 0; 45 | MSBFIRST = 1; 46 | 47 | %} 48 | -------------------------------------------------------------------------------- /examples/serialTest.py: -------------------------------------------------------------------------------- 1 | import wiringpi 2 | import sys 3 | import argparse 4 | 5 | parser = argparse.ArgumentParser(description='') 6 | parser.add_argument("--device", type=str, default="/dev/ttyS4", help='specify the serial node') 7 | args = parser.parse_args() 8 | 9 | wiringpi.wiringPiSetup() 10 | serial = wiringpi.serialOpen(args.device, 115200) 11 | if serial < 0: 12 | print("Unable to open serial device: %s"% args.device) 13 | sys.exit(-1) 14 | 15 | for count in range(0, 256): 16 | try: 17 | print("\nOut: %3d:" % count, end="") 18 | wiringpi.serialFlush(serial) 19 | wiringpi.serialPutchar(serial, count) 20 | wiringpi.delayMicroseconds(300000) 21 | 22 | while wiringpi.serialDataAvail(serial): 23 | print(" -> %3d" % wiringpi.serialGetchar(serial), end="") 24 | wiringpi.serialFlush(serial) 25 | except KeyboardInterrupt: 26 | print("\nexit") 27 | sys.exit(0) 28 | 29 | wiringpi.serialClose(serial) # Pass in ID 30 | -------------------------------------------------------------------------------- /examples/orangepi-sensors/rotary_encoder.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import time 3 | import wiringpi 4 | from wiringpi import GPIO 5 | 6 | SIA = 9 7 | SIB= 10 8 | SW = 6 9 | 10 | wiringpi.wiringPiSetup() 11 | wiringpi.pinMode(SW, GPIO.INPUT) 12 | wiringpi.pinMode(SIA, GPIO.INPUT) 13 | wiringpi.pinMode(SIB, GPIO.INPUT) 14 | 15 | flag = 0 16 | resetflag = 0 17 | globalCount = 0 18 | 19 | while True: 20 | try: 21 | lastSib = wiringpi.digitalRead(SIB) 22 | while not wiringpi.digitalRead(SW): 23 | resetflag = 1 24 | while not wiringpi.digitalRead(SIA): 25 | currentSib = wiringpi.digitalRead(SIB) 26 | flag =1 27 | 28 | if resetflag: 29 | globalCount = 0 30 | resetflag = 0 31 | print ('Count reset\ncurrent = 0') 32 | continue 33 | if flag: 34 | if lastSib == 0 and currentSib == 1: 35 | print ('Anticlockwise rotation') 36 | globalCount += 1 37 | if lastSib == 1 and currentSib == 0: 38 | print ('clockwise rotation') 39 | globalCount -=1 40 | 41 | flag =0 42 | print ('current = %s' % globalCount) 43 | except KeyboardInterrupt: 44 | print('\nExit') 45 | sys.exit(0) 46 | 47 | -------------------------------------------------------------------------------- /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 | def is_c_decl(line): 11 | for fn in ['wiringPiISR','wiringPiSetupPiFace','wiringPiSetupPiFaceForGpioProg']: 12 | if fn in line: 13 | return False 14 | for prefix in ['extern','void','int','uint8_t']: 15 | if line.startswith(prefix): 16 | return True 17 | 18 | print("// Generated by generate-bindings.py - do not edit manually!") 19 | 20 | for file in HEADERS: 21 | print("\n// Header file {}".format(file)) 22 | if file == "wiringOP/devLib/font.h": 23 | continue # continue here 24 | h = open(file).read().split('\n') 25 | extern = False 26 | cont = False 27 | if 'extern "C" {' not in h: 28 | extern = True 29 | for line in h: 30 | line = line.strip() 31 | if cont: 32 | print("\t{}".format(line)) 33 | cont = ";" not in line 34 | continue 35 | if line.startswith('extern "C"'): 36 | extern = True 37 | continue 38 | if is_c_decl(line) and extern: 39 | print(line) 40 | cont = ";" not in line 41 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Note 2 | ~~~~ 3 | 4 | wiringOP for Python 5 | =================== 6 | 7 | wiringOP: An implementation of most of the Arduino Wiring functions for 8 | the Orange Pi. 9 | 10 | Supported boards 11 | =================== 12 | tested on: 13 | ``Orange Pi Zero2`` 14 | ``Orange Pi 3 LTS`` 15 | ``Orange Pi 4 LTS`` 16 | 17 | Manual Build 18 | ============ 19 | 20 | Get/setup repo 21 | -------------- 22 | 23 | .. code:: bash 24 | 25 | git clone --recursive https://github.com/orangepi-xunlong/wiringOP-Python.git 26 | cd wiringOP-Python 27 | 28 | Don't forget the --recursive; it is required to also pull in the WiringPi C code from its own repository. 29 | 30 | Prerequisites 31 | ------------- 32 | 33 | To rebuild the bindings you **must** first have installed ``swig``, 34 | ``python3-dev``, and ``python3-setuptools``. wiringOP should also be installed system-wide for access 35 | to the ``gpio`` tool. 36 | 37 | .. code:: bash 38 | 39 | sudo apt-get install swig python3-dev python3-setuptools 40 | 41 | Build & install with 42 | -------------------- 43 | 44 | ``python3 generate-bindings.py > bindings.i`` 45 | 46 | ``sudo python3 setup.py install`` 47 | 48 | Usage 49 | ===== 50 | 51 | .. code:: python 52 | 53 | import wiringpi 54 | 55 | # One of the following MUST be called before using IO functions: 56 | wiringpi.wiringPiSetup() # For sequential pin numbering 57 | 58 | **General IO:** 59 | 60 | .. code:: python 61 | 62 | wiringpi.pinMode(6, 1) # Set pin 6 to 1 ( OUTPUT ) 63 | wiringpi.digitalWrite(6, 1) # Write 1 ( HIGH ) to pin 6 64 | wiringpi.digitalRead(6) # Read pin 6 65 | -------------------------------------------------------------------------------- /examples/orangepi-sensors/dht11.py: -------------------------------------------------------------------------------- 1 | import wiringpi 2 | from wiringpi import GPIO 3 | 4 | pin = 6 5 | 6 | def getval(pin): 7 | tl=[] 8 | tb=[] 9 | wiringpi.wiringPiSetup() 10 | wiringpi.pinMode(pin, GPIO.OUTPUT) 11 | wiringpi.digitalWrite(pin, GPIO.HIGH) 12 | wiringpi.delay(1) 13 | wiringpi.digitalWrite(pin, GPIO.LOW) 14 | wiringpi.delay(25) 15 | wiringpi.digitalWrite(pin, GPIO.HIGH) 16 | wiringpi.delayMicroseconds(20) 17 | wiringpi.pinMode(pin, GPIO.INPUT) 18 | while(wiringpi.digitalRead(pin)==1): pass 19 | 20 | for i in range(45): 21 | tc=wiringpi.micros() 22 | ''' 23 | ''' 24 | while(wiringpi.digitalRead(pin)==0): pass 25 | while(wiringpi.digitalRead(pin)==1): 26 | if wiringpi.micros()-tc>500: 27 | break 28 | if wiringpi.micros()-tc>500: 29 | break 30 | tl.append(wiringpi.micros()-tc) 31 | 32 | tl=tl[1:] 33 | for i in tl: 34 | if i>100: 35 | tb.append(1) 36 | else: 37 | tb.append(0) 38 | 39 | return tb 40 | 41 | def GetResult(pin): 42 | for i in range(10): 43 | SH=0;SL=0;TH=0;TL=0;C=0 44 | result=getval(pin) 45 | 46 | if len(result)==40: 47 | for i in range(8): 48 | SH*=2;SH+=result[i] # humi Integer 49 | SL*=2;SL+=result[i+8] # humi decimal 50 | TH*=2;TH+=result[i+16] # temp Integer 51 | TL*=2;TL+=result[i+24] # temp decimal 52 | C*=2;C+=result[i+32] # Checksum 53 | if ((SH+SL+TH+TL)%256)==C and C!=0: 54 | break 55 | else: 56 | print("Read Sucess,But checksum error! retrying") 57 | 58 | else: 59 | print("Read failer! Retrying") 60 | break 61 | wiringpi.delay(200) 62 | return SH,SL,TH,TL 63 | 64 | SH,SL,TH,TL=GetResult(pin) 65 | print("humi:",SH,SL,"temp:",TH,TL) 66 | 67 | 68 | -------------------------------------------------------------------------------- /examples/spidev_test.py: -------------------------------------------------------------------------------- 1 | import wiringpi 2 | import argparse 3 | 4 | parser = argparse.ArgumentParser(description='') 5 | parser.add_argument("--channel", type=int, default=1, help='specify the spi channel') 6 | parser.add_argument("--port", type=int, default=0, help='specify the spi port') 7 | parser.add_argument("--speed", type=int, default=500000, help='specify the spi speed') 8 | parser.add_argument("--mode", type=int, default=0, help='specify the spi mode') 9 | args = parser.parse_args() 10 | 11 | default_tx = [ 12 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 13 | 0x40, 0x00, 0x00, 0x00, 0x00, 0x95, 14 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 15 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 16 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 17 | 0xF0, 0x0D, 18 | ] 19 | 20 | def hexdump(src, line_size, prefix): 21 | result = [] 22 | digits = 4 if isinstance(src, str) else 2 23 | 24 | for i in range(0, len(src), line_size): 25 | s = src[i:i + line_size] 26 | hexa = ' '.join([hex(x)[2:].upper().zfill(digits) for x in s]) 27 | text = ''.join([chr(x) if 0x20 <= x < 0x7F else '.' for x in s]) 28 | result.append(prefix + ' | ' + hexa.ljust(line_size * (digits + 1)) + ' |' + "{0}".format(text) + '|') 29 | 30 | return '\n'.join(result) 31 | 32 | print("spi mode: 0x%x" % args.mode); 33 | print("max speed: %d Hz (%d KHz)\n" %(args.speed, args.speed / 1000), end=''); 34 | 35 | wiringpi.wiringPiSPISetupMode(args.channel, args.port, args.speed, args.mode) 36 | revlen, recvData = wiringpi.wiringPiSPIDataRW(args.channel, bytes(default_tx)) 37 | 38 | print(hexdump(bytes(default_tx), 32, "TX")) 39 | print(hexdump(bytes(recvData), 32, "RX")) 40 | -------------------------------------------------------------------------------- /examples/orangepi-sensors/ds18b20.py: -------------------------------------------------------------------------------- 1 | #import sys 2 | import wiringpi 3 | from wiringpi import GPIO 4 | 5 | PIN = 6 6 | 7 | def oneWireReset(pin): 8 | wiringpi.pinMode(pin, GPIO.OUTPUT) 9 | wiringpi.digitalWrite(pin, GPIO.HIGH) 10 | wiringpi.digitalWrite(pin, GPIO.LOW) 11 | wiringpi.delayMicroseconds(500) 12 | wiringpi.digitalWrite(pin, GPIO.HIGH) 13 | wiringpi.delayMicroseconds(60) 14 | wiringpi.pinMode(pin, GPIO.INPUT) 15 | if not wiringpi.digitalRead(pin): 16 | ack = 1 17 | else: 18 | ack = 0 19 | wiringpi.delayMicroseconds(500) 20 | return ack 21 | 22 | def writeBit(pin, bit): 23 | wiringpi.pinMode(pin, GPIO.OUTPUT) 24 | wiringpi.digitalWrite(pin, GPIO.LOW) 25 | wiringpi.delayMicroseconds(2) 26 | wiringpi.digitalWrite(pin, bit) 27 | wiringpi.delayMicroseconds(80) 28 | wiringpi.digitalWrite(pin, GPIO.HIGH) 29 | wiringpi.delayMicroseconds(1) 30 | 31 | def oneWireSendComm(pin, byte): 32 | i = 0 33 | while i < 8: 34 | sta = byte & 0x01 35 | writeBit(pin, sta) 36 | byte >>= 1 37 | i += 1 38 | 39 | def readBit(pin): 40 | wiringpi.pinMode(pin, GPIO.OUTPUT) 41 | wiringpi.digitalWrite(pin, GPIO.HIGH) 42 | wiringpi.digitalWrite(pin, GPIO.LOW) 43 | wiringpi.delayMicroseconds(2) 44 | wiringpi.digitalWrite(pin, GPIO.HIGH) 45 | 46 | wiringpi.pinMode(pin, GPIO.INPUT) 47 | wiringpi.delayMicroseconds(2) 48 | 49 | tmp = wiringpi.digitalRead(pin) 50 | wiringpi.delayMicroseconds(40) 51 | return tmp 52 | 53 | def oneWireReceive(pin): 54 | i = 0 55 | k = 0 56 | while i < 8: 57 | j = readBit(pin) 58 | k = (j << 7) | (k >> 1) 59 | i += 1 60 | k = k & 0x00FF 61 | return k 62 | 63 | def tempchange(lsb, msb): 64 | if (msb >= 0xF0): 65 | msb = 255 - msb 66 | lsb = 256 - lsb 67 | tem = -(msb*16*16 + lsb) 68 | else: 69 | tem = (msb*16*16 + lsb) 70 | temp = tem*0.0625 71 | print("Current Temp: %.2f"%(temp)) 72 | 73 | def main(): 74 | wiringpi.wiringPiSetup() 75 | if oneWireReset(PIN): 76 | oneWireSendComm(PIN, 0xcc) 77 | oneWireSendComm(PIN, 0x44) 78 | if oneWireReset(PIN): 79 | oneWireSendComm(PIN, 0xcc) 80 | oneWireSendComm(PIN, 0xbe) 81 | lsb = oneWireReceive(PIN) 82 | msb = oneWireReceive(PIN) 83 | tempchange(lsb, msb) 84 | 85 | if __name__ == '__main__': 86 | main() 87 | 88 | 89 | -------------------------------------------------------------------------------- /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/orangepi-sensors/rtc.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import time 3 | import wiringpi 4 | #from wiringpi import GPIO 5 | 6 | I2C_ADDR = 0x68 7 | 8 | def b2s(bcd, mask): 9 | bcd &= mask 10 | b1 = bcd & 0x0F 11 | b2 = ((bcd >> 4) & 0x0F)*10 12 | return b1 + b2 13 | 14 | def decCompensation(units): 15 | unitsU = units%10 16 | if units >= 50: 17 | units = 0x50 + unitsU 18 | elif units >= 40: 19 | units = 0x40 + unitsU 20 | elif units >= 30: 21 | units = 0x30 + unitsU 22 | elif units >= 20: 23 | units = 0x20 + unitsU 24 | elif units >= 10: 25 | units = 0x10 + unitsU 26 | return units 27 | 28 | def getHours(): 29 | HH = time.strftime("%H") 30 | return decCompensation(int(HH)) 31 | 32 | def getMins(): 33 | MM = time.strftime("%M") 34 | return decCompensation(int(MM)) 35 | 36 | def getSecs(): 37 | SS = time.strftime("%S") 38 | return decCompensation(int(SS)) 39 | 40 | def getWeeks(): 41 | WW = time.strftime("%w") 42 | return decCompensation(int(WW)) 43 | 44 | def getDays(): 45 | DD = time.strftime("%d") 46 | return decCompensation(int(DD)) 47 | 48 | def getMons(): 49 | MON = time.strftime("%m") 50 | return decCompensation(int(MON)) 51 | 52 | def getYear(): 53 | YY = time.strftime("%Y") 54 | return decCompensation(int(YY)) 55 | 56 | def clear_register(fd): 57 | wiringpi.wiringPiI2CWriteReg8(fd, 0x02, 0b0) # hours 58 | wiringpi.wiringPiI2CWriteReg8(fd, 0x01, 0b0) # mins 59 | wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0b10000000) # secs 60 | wiringpi.wiringPiI2CWriteReg8(fd, 0x03, 0b0) # weeks 61 | wiringpi.wiringPiI2CWriteReg8(fd, 0x04, 0b0) # days 62 | wiringpi.wiringPiI2CWriteReg8(fd, 0x05, 0b0) # mons 63 | 64 | def sys2rtcSet(fd): 65 | wiringpi.wiringPiI2CWriteReg8(fd, 0x02, getHours()) 66 | wiringpi.wiringPiI2CWriteReg8(fd, 0x01, getMins()) 67 | wiringpi.wiringPiI2CWriteReg8(fd, 0x00, getSecs()+0b10000000) 68 | wiringpi.wiringPiI2CWriteReg8(fd, 0x03, getWeeks()) 69 | wiringpi.wiringPiI2CWriteReg8(fd, 0x04, getDays()) 70 | wiringpi.wiringPiI2CWriteReg8(fd, 0x05, getMons()) 71 | wiringpi.wiringPiI2CWriteReg8(fd, 0x06, getYear()) 72 | 73 | def read_register(fd): 74 | secs = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x00), 0x7F) 75 | mins = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x01), 0x7F) 76 | hours = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x02) - 0b10000000, 0x3F) 77 | week = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x03), 0x3F) 78 | day = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x04), 0x1F) 79 | mon = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x05), 0x07) 80 | year = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x06), 0xFF) + 1970 81 | print("week:%d mon:%d day:%d hours:%d mins:%d secs:%d year:%d"%(week,mon,day,hours,mins,secs,year)) 82 | 83 | def main(): 84 | wiringpi.wiringPiSetup() 85 | fd = wiringpi.wiringPiI2CSetup(I2C_ADDR) 86 | if not fd: 87 | return False; 88 | while True: 89 | try: 90 | # clear RTC Register 91 | clear_register(fd) 92 | # set sys time to RTC Register 93 | sys2rtcSet(fd) 94 | # read RTC Register 95 | read_register(fd) 96 | time.sleep(1) 97 | except KeyboardInterrupt: 98 | print("\nexit") 99 | sys.exit(0) 100 | 101 | if __name__ == '__main__': 102 | main() 103 | 104 | -------------------------------------------------------------------------------- /examples/ds1307.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import time 3 | import wiringpi 4 | from datetime import datetime 5 | import operator 6 | import argparse 7 | 8 | parser = argparse.ArgumentParser(description='i2c') 9 | parser.add_argument("--device", type=str, default="/dev/i2c-0", help='specify the i2c node') 10 | args = parser.parse_args() 11 | 12 | i2caddr = 0x68 13 | 14 | def b2s(bcd, mask): 15 | bcd &= mask 16 | b1 = bcd & 0x0F 17 | b2 = ((bcd >> 4) & 0x0F)*10 18 | return b1 + b2 19 | 20 | def decCompensation(units): 21 | unitsU = units%10 22 | if units >= 50: 23 | units = 0x50 + unitsU 24 | elif units >= 40: 25 | units = 0x40 + unitsU 26 | elif units >= 30: 27 | units = 0x30 + unitsU 28 | elif units >= 20: 29 | units = 0x20 + unitsU 30 | elif units >= 10: 31 | units = 0x10 + unitsU 32 | return units 33 | 34 | def getHours(): 35 | HH = time.strftime("%H") 36 | return decCompensation(int(HH)) 37 | 38 | def getMins(): 39 | MM = time.strftime("%M") 40 | return decCompensation(int(MM)) 41 | 42 | def getSecs(): 43 | SS = time.strftime("%S") 44 | return decCompensation(int(SS)) 45 | 46 | def getWeeks(): 47 | WW = time.strftime("%w") 48 | return decCompensation(int(WW)) 49 | 50 | def getDays(): 51 | DD = time.strftime("%d") 52 | return decCompensation(int(DD)) 53 | 54 | def getMons(): 55 | MON = time.strftime("%m") 56 | return decCompensation(int(MON)) 57 | 58 | def getYear(): 59 | YY = time.strftime("%Y") 60 | return decCompensation(int(YY)) 61 | 62 | def ds1307_write_byte(fd, reg, byte): 63 | if wiringpi.wiringPiI2CWriteReg8(fd, reg, byte) < 0: 64 | print("Error write byte to ds1307") 65 | return -1 66 | return 0 67 | 68 | def ds1307_read_byte(fd, reg): 69 | byte = wiringpi.wiringPiI2CReadReg8(fd, reg) 70 | if byte < 0: 71 | print("Error read byte from ds1307") 72 | return -1 73 | return byte 74 | 75 | def sys2rtcSet(fd): 76 | ds1307_write_byte(fd, 0x02, getHours()) 77 | ds1307_write_byte(fd, 0x01, getMins()) 78 | ds1307_write_byte(fd, 0x00, getSecs()) 79 | ds1307_write_byte(fd, 0x03, getWeeks()) 80 | ds1307_write_byte(fd, 0x04, getDays()) 81 | ds1307_write_byte(fd, 0x05, getMons()) 82 | ds1307_write_byte(fd, 0x06, getYear()) 83 | 84 | def read_register(fd): 85 | byte = ds1307_read_byte(fd, 0x0) 86 | if byte >> 7: 87 | ds1307_write_byte(fd, 0x0, 0x0) 88 | second = operator.mod(byte, 16) + operator.floordiv(byte, 16) * 10 89 | 90 | byte = ds1307_read_byte(fd, 0x01) 91 | minute = operator.mod(byte, 16) + operator.floordiv(byte, 16) * 10 92 | 93 | byte = ds1307_read_byte(fd, 0x02) 94 | hour = operator.mod(byte, 16) + operator.floordiv(byte, 16) * 10 95 | 96 | week = ds1307_read_byte(fd, 0x03) 97 | 98 | byte = ds1307_read_byte(fd, 0x04) 99 | day = operator.mod(byte, 16) + operator.floordiv(byte, 16) * 10 100 | 101 | byte = ds1307_read_byte(fd, 0x05) 102 | month = operator.mod(byte, 16) + operator.floordiv(byte, 16) * 10 103 | 104 | byte = ds1307_read_byte(fd, 0x06) 105 | year = operator.mod(byte, 16) + operator.floordiv(byte, 16) * 10 + 1970 106 | 107 | if year == 2000 or month > 12 or month<1 or day < 1 or day > 31: 108 | return False 109 | 110 | if second > 59: 111 | return False 112 | return datetime(year,month,day,hour,minute,second) 113 | 114 | def main(): 115 | wiringpi.wiringPiSetup() 116 | fd = wiringpi.wiringPiI2CSetupInterface(args.device, i2caddr) 117 | try: 118 | sys2rtcSet(fd) 119 | while True: 120 | time.sleep(1) 121 | dt = read_register(fd) 122 | if not dt: 123 | continue 124 | else: 125 | str_time = dt.strftime("%a %Y-%m-%d %H:%M:%S") 126 | print("%s"%(str_time)) 127 | except KeyboardInterrupt: 128 | print("\nexit") 129 | sys.exit(0) 130 | 131 | if __name__ == '__main__': 132 | main() 133 | 134 | -------------------------------------------------------------------------------- /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 write(self,*args): 41 | return wiringPiI2CWrite(*args) 42 | def writeReg8(self,*args): 43 | return wiringPiI2CWriteReg8(*args) 44 | def writeReg16(self,*args): 45 | return wiringPiI2CWriteReg16(*args) 46 | 47 | class GPIO(object): 48 | WPI_MODE_PINS = 0 49 | WPI_MODE_GPIO = 1 50 | WPI_MODE_GPIO_SYS = 2 51 | WPI_MODE_PHYS = 3 52 | WPI_MODE_PIFACE = 4 53 | WPI_MODE_UNINITIALISED = -1 54 | 55 | INPUT = 0 56 | OUTPUT = 1 57 | PWM_OUTPUT = 2 58 | GPIO_CLOCK = 3 59 | 60 | LOW = 0 61 | HIGH = 1 62 | 63 | PUD_OFF = 0 64 | PUD_DOWN = 1 65 | PUD_UP = 2 66 | 67 | PWM_MODE_MS = 0 68 | PWM_MODE_BAL = 1 69 | 70 | INT_EDGE_SETUP = 0 71 | INT_EDGE_FALLING = 1 72 | INT_EDGE_RISING = 2 73 | INT_EDGE_BOTH = 3 74 | 75 | LSBFIRST = 0 76 | MSBFIRST = 1 77 | 78 | MODE = 0 79 | def __init__(self,pinmode=0): 80 | self.MODE=pinmode 81 | if pinmode==self.WPI_MODE_PINS: 82 | wiringPiSetup() 83 | if pinmode==self.WPI_MODE_GPIO: 84 | wiringPiSetupGpio() 85 | if pinmode==self.WPI_MODE_GPIO_SYS: 86 | wiringPiSetupSys() 87 | if pinmode==self.WPI_MODE_PHYS: 88 | wiringPiSetupPhys() 89 | if pinmode==self.WPI_MODE_PIFACE: 90 | wiringPiSetupPiFace() 91 | 92 | def delay(self,*args): 93 | delay(*args) 94 | def delayMicroseconds(self,*args): 95 | delayMicroseconds(*args) 96 | def millis(self): 97 | return millis() 98 | def micros(self): 99 | return micros() 100 | 101 | def piHiPri(self,*args): 102 | return piHiPri(*args) 103 | 104 | def piBoardRev(self): 105 | return piBoardRev() 106 | def wpiPinToGpio(self,*args): 107 | return wpiPinToGpio(*args) 108 | def setPadDrive(self,*args): 109 | return setPadDrive(*args) 110 | def getAlt(self,*args): 111 | return getAlt(*args) 112 | def digitalWriteByte(self,*args): 113 | return digitalWriteByte(*args) 114 | 115 | def pwmSetMode(self,*args): 116 | pwmSetMode(*args) 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 lcdHome(self,*args): 165 | return lcdHome(self,*args) 166 | def lcdCLear(self,*args): 167 | return lcdClear(self,*args) 168 | def lcdSendCommand(self,*args): 169 | return lcdSendCommand(self,*args) 170 | def lcdPosition(self,*args): 171 | return lcdPosition(self,*args) 172 | def lcdPutchar(self,*args): 173 | return lcdPutchar(self,*args) 174 | def lcdPuts(self,*args): 175 | return lcdPuts(self,*args) 176 | def lcdPrintf(self,*args): 177 | return lcdPrintf(self,*args) 178 | def lcdInit(self,*args): 179 | return lcdInit(self,*args) 180 | def piGlowSetup(self,*args): 181 | return piGlowSetup(self,*args) 182 | def piGlow1(self,*args): 183 | return piGlow1(self,*args) 184 | def piGlowLeg(self,*args): 185 | return piGlowLeg(self,*args) 186 | def piGlowRing(self,*args): 187 | return piGlowRing(self,*args) 188 | %} 189 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | from setuptools import setup, Extension 5 | from setuptools.command.build_py import build_py 6 | from setuptools.command.sdist import sdist 7 | from distutils.spawn import find_executable 8 | from glob import glob 9 | from subprocess import Popen, PIPE 10 | import re 11 | 12 | sources = glob('wiringOP/devLib/*.c') 13 | sources += glob('wiringOP/wiringPi/*.c') 14 | sources += ['wiringpi.i'] 15 | sources += ['fixUndefFunc.c'] 16 | try: 17 | sources.remove('wiringOP/devLib/piFaceOld.c') 18 | except ValueError: 19 | # the file is already excluded in the source distribution 20 | pass 21 | 22 | # Fix so that build_ext runs before build_py 23 | # Without this, wiringpi.py is generated too late and doesn't 24 | # end up in the distribution when running setup.py bdist or bdist_wheel. 25 | # Based on: 26 | # https://stackoverflow.com/a/29551581/7938656 27 | # and 28 | # https://blog.niteoweb.com/setuptools-run-custom-code-in-setup-py/ 29 | 30 | 31 | class build_py_ext_first(build_py): 32 | def run(self): 33 | self.run_command("build_ext") 34 | return build_py.run(self) 35 | 36 | # Make sure wiringpi_wrap.c is available for the source dist, also. 37 | 38 | 39 | class sdist_ext_first(sdist): 40 | def run(self): 41 | self.run_command("build_ext") 42 | return sdist.run(self) 43 | 44 | def cmdline(command, arguments): 45 | process = Popen(args=[command, arguments],stdin=PIPE, stdout=PIPE, stderr=PIPE) 46 | return process.communicate()[0] 47 | 48 | BOARD = "" 49 | boards = ["orangepir1", "orangepizero", "orangepizero-lts", "orangepipc", "orangepipch5", "orangepipcplus", 50 | "orangepiplus2e", "orangepione", "orangepioneh5", "orangepilite", "orangepiplus", "orangepizeroplus2h3", 51 | "orangepizeroplus", "orangepipc2", "orangepiprime", "orangepizeroplus2h5", "orangepiwin", "orangepiwinplus", 52 | "orangepi3", "orangepi3-lts", "orangepilite2", "orangepioneplus", "orangepi4", "orangepi4-lts", "orangepirk3399", 53 | "orangepi800", "orangepizero2", "orangepizero2-lts", "orangepizero2-b", "orangepir1plus-lts", "orangepir1plus"] 54 | 55 | inf_orangepi = cmdline('cat','/etc/orangepi-release') 56 | inf_armbian = cmdline('cat','/etc/armbian-release') 57 | if inf_orangepi != b'': 58 | match = re.search(r"(?<=^BOARD=).*", inf_orangepi.decode("utf-8"), re.MULTILINE) 59 | if match == None: sys.exit(1) #something went wrong 60 | BOARD = match.group() 61 | elif inf_armbian != b'': 62 | match = re.search(r"(?<=^BOARD=).*", inf_armbian.decode("utf-8"), re.MULTILINE) 63 | if match == None: sys.exit(1) #something went wrong 64 | BOARD = match.group() 65 | if BOARD == "orangepi-r1": EXTRA_CFLAGS = "orangepir1" 66 | elif BOARD == "orangepi-rk3399": EXTRA_CFLAGS = "orangepirk3399" 67 | elif BOARD == "orangepizeroplus2-h3": EXTRA_CFLAGS = "orangepizeroplus2h3" 68 | elif BOARD == "orangepizeroplus2-h5": EXTRA_CFLAGS = "orangepizeroplus2h5" 69 | else: 70 | print("All available boards:\n") 71 | cnt = 0 72 | for board in boards: 73 | print("%4d. %s\n"%(cnt, board)) 74 | cnt+=1 75 | while True: 76 | choice = input("Choice: ") 77 | if choice == None or choice.isdigit() != True: 78 | continue 79 | if 0 <= int(choice) <= 30: 80 | BOARD = boards[int(choice)] 81 | break 82 | print("Invalid input ...\n") 83 | 84 | if BOARD == "orangepir1": BOARD = "orangepir1-h2" 85 | elif BOARD == "orangepizero" or BOARD == "orangepizero-lts": BOARD = "orangepizero-h2" 86 | elif BOARD == "orangepipc" or BOARD == "orangepipch5": BOARD = "orangepipc-h3" 87 | elif BOARD == "orangepipcplus": BOARD = "orangepipcplus-h3" 88 | elif BOARD == "orangepiplus2e": BOARD = "orangepiplus2e-h3" 89 | elif BOARD == "orangepione" or BOARD == "orangepioneh5": BOARD = "orangepione-h3" 90 | elif BOARD == "orangepilite": BOARD = "orangepilite-h3" 91 | elif BOARD == "orangepiplus": BOARD = "orangepiplus-h3" 92 | elif BOARD == "orangepizeroplus": BOARD = "orangepizeroplus-h5" 93 | elif BOARD == "orangepipc2": BOARD = "orangepipc2-h5" 94 | elif BOARD == "orangepiprime": BOARD = "orangepiprime-h5" 95 | elif BOARD == "orangepiwin": BOARD = "orangepiwin-a64" 96 | elif BOARD == "orangepiwinplus": BOARD = "orangepiwinplus-a64" 97 | elif BOARD == "orangepi3" or BOARD == "orangepi3-lts": BOARD = "orangepi3-h6" 98 | elif BOARD == "orangepilite2": BOARD = "orangepilite2-h6" 99 | elif BOARD == "orangepioneplus": BOARD = "orangepioneplus-h6" 100 | elif BOARD == "orangepizero2" or BOARD == "orangepizero2-lts" or BOARD == "orangepizero2-b": BOARD = "orangepizero2-h616" 101 | elif BOARD == "orangepir1plus" or BOARD == "orangepir1plus-lts": BOARD = "orangepir1plus-rk3328" 102 | 103 | if BOARD == "": BOARD = "orangepioneplus-h6" 104 | 105 | EXTRA_CFLAGS = "" 106 | 107 | if BOARD == "orangepi2giot": EXTRA_CFLAGS = "-DCONFIG_ORANGEPI_2G_IOT" 108 | elif BOARD == "orangepipc2-h5": EXTRA_CFLAGS = "-DCONFIG_ORANGEPI_PC2" 109 | elif BOARD == "orangepiprime-h5": EXTRA_CFLAGS = "-DCONFIG_ORANGEPI_PRIME" 110 | elif BOARD == "orangepizeroplus-h5": EXTRA_CFLAGS = "-DCONFIG_ORANGEPI_ZEROPLUS" 111 | elif BOARD == "orangepiwin-a64" or BOARD == "orangepiwinplus-a64": EXTRA_CFLAGS = "-DCONFIG_ORANGEPI_WIN" 112 | elif BOARD == "orangepione-h3" or BOARD == "orangepilite-h3" or BOARD == "orangepipc-h3" or BOARD == "orangepiplus-h3" or BOARD == "orangepipcplus-h3" or BOARD == "orangepiplus2e-h3": EXTRA_CFLAGS = "-DCONFIG_ORANGEPI_H3" 113 | elif BOARD == "orangepizero-h2" or BOARD == "orangepir1-h2": EXTRA_CFLAGS = "-DCONFIG_ORANGEPI_ZERO" 114 | elif BOARD == "orangepioneplus-h6" or BOARD == "orangepilite2-h6": EXTRA_CFLAGS = "-DCONFIG_ORANGEPI_LITE2" 115 | elif BOARD == "orangepi3-h6": EXTRA_CFLAGS = "-DCONFIG_ORANGEPI_3" 116 | elif BOARD == "orangepizero2-h616": EXTRA_CFLAGS = "-DCONFIG_ORANGEPI_ZERO2" 117 | elif BOARD == "orangepizeroplus2h3": EXTRA_CFLAGS = "-DCONFIG_ORANGEPI_ZEROPLUS2_H3" 118 | elif BOARD == "orangepizeroplus2h5": EXTRA_CFLAGS = "-DCONFIG_ORANGEPI_ZEROPLUS2_H5" 119 | elif BOARD == "orangepirk3399": EXTRA_CFLAGS = "-DCONFIG_ORANGEPI_RK3399" 120 | elif BOARD == "orangepi4": EXTRA_CFLAGS = "-DCONFIG_ORANGEPI_4" 121 | elif BOARD == "orangepi4-lts": EXTRA_CFLAGS = "-DCONFIG_ORANGEPI_4_LTS" 122 | elif BOARD == "orangepi800": EXTRA_CFLAGS = "-DCONFIG_ORANGEPI_800" 123 | elif BOARD == "orangepir1plus-rk3328": EXTRA_CFLAGS = "-DCONFIG_ORANGEPI_R1PLUS" 124 | 125 | _wiringpi = Extension( 126 | '_wiringpi', 127 | include_dirs=['wiringOP', 'wiringOP/wiringPi', 'wiringOP/devLib'], 128 | extra_compile_args=[EXTRA_CFLAGS, "-DCONFIG_ORANGEPI"], 129 | swig_opts=['-threads'], 130 | extra_link_args=['-lcrypt', '-lrt'], 131 | sources=sources 132 | ) 133 | 134 | setup( 135 | name='wiringpi', 136 | version='2.60.1', 137 | ext_modules=[_wiringpi], 138 | py_modules=["wiringpi"], 139 | install_requires=[], 140 | cmdclass={'build_py': build_py_ext_first, 'sdist': sdist_ext_first} 141 | ) 142 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /wiringpi.i: -------------------------------------------------------------------------------- 1 | %module 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 "wiringOP/wiringPi/wiringPi.h" 10 | #include "wiringOP/wiringPi/wiringPiI2C.h" 11 | #include "wiringOP/wiringPi/wiringPiSPI.h" 12 | #include "wiringOP/wiringPi/wiringSerial.h" 13 | #include "wiringOP/wiringPi/wiringShift.h" 14 | #include "wiringOP/wiringPi/drcSerial.h" 15 | #include "wiringOP/wiringPi/ads1115.h" 16 | #include "wiringOP/wiringPi/max31855.h" 17 | #include "wiringOP/wiringPi/max5322.h" 18 | #include "wiringOP/wiringPi/mcp23008.h" 19 | #include "wiringOP/wiringPi/mcp23016.h" 20 | #include "wiringOP/wiringPi/mcp23016reg.h" 21 | #include "wiringOP/wiringPi/mcp23017.h" 22 | #include "wiringOP/wiringPi/mcp23s08.h" 23 | #include "wiringOP/wiringPi/mcp23s17.h" 24 | #include "wiringOP/wiringPi/mcp23x0817.h" 25 | #include "wiringOP/wiringPi/mcp23x08.h" 26 | #include "wiringOP/wiringPi/mcp3002.h" 27 | #include "wiringOP/wiringPi/mcp3004.h" 28 | #include "wiringOP/wiringPi/mcp3422.h" 29 | #include "wiringOP/wiringPi/mcp4802.h" 30 | #include "wiringOP/wiringPi/pcf8574.h" 31 | #include "wiringOP/wiringPi/pcf8591.h" 32 | #include "wiringOP/wiringPi/sn3218.h" 33 | #include "wiringOP/wiringPi/softPwm.h" 34 | #include "wiringOP/wiringPi/softServo.h" 35 | #include "wiringOP/wiringPi/softTone.h" 36 | #include "wiringOP/wiringPi/sr595.h" 37 | #include "wiringOP/wiringPi/bmp180.h" 38 | #include "wiringOP/wiringPi/drcNet.h" 39 | #include "wiringOP/wiringPi/ds18b20.h" 40 | #include "wiringOP/wiringPi/htu21d.h" 41 | #include "wiringOP/wiringPi/pseudoPins.h" 42 | #include "wiringOP/wiringPi/rht03.h" 43 | #include "wiringOP/wiringPi/wpiExtensions.h" 44 | #include "wiringOP/devLib/ds1302.h" 45 | #include "wiringOP/devLib/font.h" 46 | #include "wiringOP/devLib/gertboard.h" 47 | #include "wiringOP/devLib/lcd128x64.h" 48 | #include "wiringOP/devLib/lcd.h" 49 | #include "wiringOP/devLib/maxdetect.h" 50 | #include "wiringOP/devLib/piGlow.h" 51 | #include "wiringOP/devLib/piNes.h" 52 | #include "wiringOP/devLib/scrollPhat.h" 53 | #include "wiringOP/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 | -------------------------------------------------------------------------------- /examples/orangepi-sensors/oled_ssd1306.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import time 3 | import wiringpi 4 | from wiringpi import GPIO 5 | 6 | I2C_ADDR = 0x3c 7 | fd = 0 8 | yi = [' ',' ',' ',' '] 9 | zi = [ 10 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//0 11 | 12 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//1 13 | 14 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//2 15 | 16 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//3 17 | 18 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//4 19 | 20 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//5 21 | 22 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//6 23 | 24 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//7 25 | 26 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//8 27 | 28 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//9 29 | 30 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//10 31 | 32 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//11 33 | 34 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//12 35 | 36 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//13 37 | 38 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//14 39 | 40 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//15 41 | 42 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//16 43 | 44 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//17 45 | 46 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//18 47 | 48 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//19 49 | 50 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//20 51 | 52 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//21 53 | 54 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//22 55 | 56 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//23 57 | 58 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//24 59 | 60 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//25 61 | 62 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//26 63 | 64 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//27 65 | 66 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//28 67 | 68 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//29 69 | 70 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//30 71 | 72 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//31 73 | 74 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//32 75 | 76 | 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x00,0x00,0x00,0x00,#//33 77 | 78 | 0x00,0x10,0x0C,0x02,0x10,0x0C,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//34 79 | 80 | 0x00,0x40,0xC0,0x78,0x40,0xC0,0x78,0x00,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x00,#//35 81 | 82 | 0x00,0x70,0x88,0x88,0xFC,0x08,0x30,0x00,0x00,0x18,0x20,0x20,0xFF,0x21,0x1E,0x00,#//36 83 | 84 | 0xF0,0x08,0xF0,0x80,0x60,0x18,0x00,0x00,0x00,0x31,0x0C,0x03,0x1E,0x21,0x1E,0x00,#//37 85 | 86 | 0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x2C,0x19,0x27,0x21,0x10,#//38 87 | 88 | 0x00,0x12,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//39 89 | 90 | 0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,#//40 91 | 92 | 0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,#//41 93 | 94 | 0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,#//42 95 | 96 | 0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x0F,0x01,0x01,0x01,#//43 97 | 98 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x90,0x70,0x00,0x00,0x00,0x00,0x00,#//44 99 | 100 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x00,#//45 101 | 102 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,#//46 103 | 104 | 0x00,0x00,0x00,0x00,0xC0,0x38,0x04,0x00,0x00,0x60,0x18,0x07,0x00,0x00,0x00,0x00,#//47 105 | 106 | 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,#//48 107 | 108 | 0x00,0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,#//49 109 | 110 | 0x00,0x70,0x08,0x08,0x08,0x08,0xF0,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,#//50 111 | 112 | 0x00,0x30,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x18,0x20,0x21,0x21,0x22,0x1C,0x00,#//51 113 | 114 | 0x00,0x00,0x80,0x40,0x30,0xF8,0x00,0x00,0x00,0x06,0x05,0x24,0x24,0x3F,0x24,0x24,#//52 115 | 116 | 0x00,0xF8,0x88,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x20,0x20,0x20,0x11,0x0E,0x00,#//53 117 | 118 | 0x00,0xE0,0x10,0x88,0x88,0x90,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x20,0x1F,0x00,#//54 119 | 120 | 0x00,0x18,0x08,0x08,0x88,0x68,0x18,0x00,0x00,0x00,0x00,0x3E,0x01,0x00,0x00,0x00,#//55 121 | 122 | 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,#//56 123 | 124 | 0x00,0xF0,0x08,0x08,0x08,0x10,0xE0,0x00,0x00,0x01,0x12,0x22,0x22,0x11,0x0F,0x00,#//57 125 | 126 | 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,#//58 127 | 128 | 0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,#//59 129 | 130 | 0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,#//60 131 | 132 | 0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x00,#//61 133 | 134 | 0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,#//62 135 | 136 | 0x00,0x70,0x48,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x00,0x30,0x37,0x00,0x00,0x00,#//63 137 | 138 | 0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x28,0x2F,0x28,0x17,0x00,#//64 139 | 140 | 0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,#//65 141 | 142 | 0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,#//66 143 | 144 | 0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,#//67 145 | 146 | 0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,#//68 147 | 148 | 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,#//69 149 | 150 | 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,#//70 151 | 152 | 0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,#//71 153 | 154 | 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,#//72 155 | 156 | 0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,#//73 157 | 158 | 0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,#//74 159 | 160 | 0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,#//75 161 | 162 | 0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,#//76 163 | 164 | 0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x01,0x3E,0x01,0x3F,0x20,0x00,#//77 165 | 166 | 0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,#//78 167 | 168 | 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,#//79 169 | 170 | 0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,#//80 171 | 172 | 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x28,0x28,0x30,0x50,0x4F,0x00,#//81 173 | 174 | 0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,#//82 175 | 176 | 0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,#//83 177 | 178 | 0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,#//84 179 | 180 | 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,#//85 181 | 182 | 0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,#//86 183 | 184 | 0x08,0xF8,0x00,0xF8,0x00,0xF8,0x08,0x00,0x00,0x03,0x3E,0x01,0x3E,0x03,0x00,0x00,#//87 185 | 186 | 0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,#//88 187 | 188 | 0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,#//89 189 | 190 | 0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,#//90 191 | 192 | 0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,#//91 193 | 194 | 0x00,0x04,0x38,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,#//92 195 | 196 | 0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,#//93 197 | 198 | 0x00,0x00,0x04,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//94 199 | 200 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,#//95 201 | 202 | 0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//96 203 | 204 | 0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x19,0x24,0x24,0x12,0x3F,0x20,0x00,#//97 205 | 206 | 0x10,0xF0,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,#//98 207 | 208 | 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,#//99 209 | 210 | 0x00,0x00,0x80,0x80,0x80,0x90,0xF0,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,#//100 211 | 212 | 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x24,0x24,0x24,0x24,0x17,0x00,#//101 213 | 214 | 0x00,0x80,0x80,0xE0,0x90,0x90,0x20,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,#//102 215 | 216 | 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,#//103 217 | 218 | 0x10,0xF0,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,#//104 219 | 220 | 0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,#//105 221 | 222 | 0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,#//106 223 | 224 | 0x10,0xF0,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x06,0x29,0x30,0x20,0x00,#//107 225 | 226 | 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,#//108 227 | 228 | 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,#//109 229 | 230 | 0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,#//110 231 | 232 | 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,#//111 233 | 234 | 0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0x91,0x20,0x20,0x11,0x0E,0x00,#//112 235 | 236 | 0x00,0x00,0x00,0x80,0x80,0x00,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0x91,0xFF,0x80,#//113 237 | 238 | 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,#//114 239 | 240 | 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,#//115 241 | 242 | 0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x10,0x00,#//116 243 | 244 | 0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,#//117 245 | 246 | 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x03,0x0C,0x30,0x0C,0x03,0x00,0x00,#//118 247 | 248 | 0x80,0x80,0x00,0x80,0x80,0x00,0x80,0x80,0x01,0x0E,0x30,0x0C,0x07,0x38,0x06,0x01,#//119 249 | 250 | 0x00,0x80,0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x20,0x31,0x0E,0x2E,0x31,0x20,0x00,#//120 251 | 252 | 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x81,0x86,0x78,0x18,0x06,0x01,0x00,#//121 253 | 254 | 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,#//122 255 | 256 | 0x00,0x00,0x00,0x00,0x00,0xFC,0x02,0x02,0x00,0x00,0x00,0x00,0x01,0x3E,0x40,0x40,#//122 257 | 258 | 0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,#//124 259 | 260 | 0x02,0x02,0xFC,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x3E,0x01,0x00,0x00,0x00,0x00,#//125 261 | 262 | 0x00,0x02,0x01,0x02,0x02,0x04,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//126 263 | 264 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//127 265 | ] 266 | 267 | def full_string(s): 268 | while len(s) < 16: 269 | s += ' ' 270 | return s 271 | 272 | def main(): 273 | #init 274 | wiringpi.wiringPiSetup() 275 | fd = wiringpi.wiringPiI2CSetup(I2C_ADDR) 276 | if not fd: 277 | return False; 278 | wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xa1) 279 | wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xc8) 280 | wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x8d) 281 | wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x14) 282 | wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xa6) 283 | wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x21) 284 | wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x00) 285 | wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x7f) 286 | wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xaf) 287 | 288 | #clear oled 289 | for a in range(8): 290 | wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xb0 + a) 291 | for b in range(128): 292 | wiringpi.wiringPiI2CWriteReg8(fd, 0x40, 0x00) 293 | 294 | while True: 295 | try: 296 | #get time 297 | yi[0] = full_string("++++OrangePi++++") 298 | #yi[1] = full_string(time.strftime("%m/%d %w")) 299 | yi[1] = full_string(time.strftime("%m/%d %a")) 300 | yi[2] = full_string(time.strftime("%H:%M")) 301 | yi[3] = full_string("SSD1306 I2C OLED") 302 | 303 | #write 304 | for zt3 in range(4): 305 | wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xb0+(zt3*2)) 306 | for zt4 in range(16): 307 | for zt in range(8): 308 | wiringpi.wiringPiI2CWriteReg8(fd, 0x40, zi[ord(yi[zt3][zt4])*16+zt]) 309 | wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xb0+(zt3*2)+1) 310 | for zt4 in range(16): 311 | for zt in range(8): 312 | wiringpi.wiringPiI2CWriteReg8(fd, 0x40, zi[ord(yi[zt3][zt4])*16+zt+8]) 313 | time.sleep(1) 314 | except KeyboardInterrupt: 315 | print("\nexit") 316 | sys.exit(0) 317 | 318 | if __name__ == '__main__': 319 | main() 320 | 321 | --------------------------------------------------------------------------------