mirror of
git://soft.sys114.com/WiringPi2-Python
synced 2025-12-19 01:28:43 +09:00
Updated to reflect wiringpi2 to wiringpi rename
This commit is contained in:
@@ -3,5 +3,5 @@ graft WiringPi/devLib
|
||||
include README.md
|
||||
include LICENSE.txt
|
||||
include setup.cfg
|
||||
include wiringpi2.py
|
||||
include wiringpi.py
|
||||
include wiringpi_wrap.c
|
||||
|
||||
34
README.md
34
README.md
@@ -44,50 +44,50 @@ Description incoming!
|
||||
|
||||
##Usage
|
||||
|
||||
import wiringpi2
|
||||
import wiringpi
|
||||
|
||||
wiringpi2.wiringPiSetup() # For sequential pin numbering, one of these MUST be called before using IO functions
|
||||
wiringpi.wiringPiSetup() # For sequential pin numbering, one of these MUST be called before using IO functions
|
||||
# OR
|
||||
wiringpi2.wiringPiSetupSys() # For /sys/class/gpio with GPIO pin numbering
|
||||
wiringpi.wiringPiSetupSys() # For /sys/class/gpio with GPIO pin numbering
|
||||
# OR
|
||||
wiringpi2.wiringPiSetupGpio() # For GPIO pin numbering
|
||||
wiringpi.wiringPiSetupGpio() # For GPIO pin numbering
|
||||
|
||||
|
||||
Setting up IO expanders (This example was tested on a quick2wire board with one digital IO expansion board connected via I2C):
|
||||
|
||||
wiringpi2.mcp23017Setup(65,0x20)
|
||||
wiringpi2.pinMode(65,1)
|
||||
wiringpi2.digitalWrite(65,1)
|
||||
wiringpi.mcp23017Setup(65,0x20)
|
||||
wiringpi.pinMode(65,1)
|
||||
wiringpi.digitalWrite(65,1)
|
||||
|
||||
**General IO:**
|
||||
|
||||
wiringpi2.pinMode(6,1) # Set pin 6 to 1 ( OUTPUT )
|
||||
wiringpi2.digitalWrite(6,1) # Write 1 ( HIGH ) to pin 6
|
||||
wiringpi2.digitalRead(6) # Read pin 6
|
||||
wiringpi.pinMode(6,1) # Set pin 6 to 1 ( OUTPUT )
|
||||
wiringpi.digitalWrite(6,1) # Write 1 ( HIGH ) to pin 6
|
||||
wiringpi.digitalRead(6) # Read pin 6
|
||||
|
||||
**Setting up a peripheral:**
|
||||
WiringPi2 supports expanding your range of available "pins" by setting up a port expander. The implementation details of
|
||||
your port expander will be handled transparently, and you can write to the additional pins ( starting from PIN_OFFSET >= 64 )
|
||||
as if they were normal pins on the Pi.
|
||||
|
||||
wiringpi2.mcp23017Setup(PIN_OFFSET,I2C_ADDR)
|
||||
wiringpi.mcp23017Setup(PIN_OFFSET,I2C_ADDR)
|
||||
|
||||
**Soft Tone**
|
||||
|
||||
Hook a speaker up to your Pi and generate music with softTone. Also useful for generating frequencies for other uses such as modulating A/C.
|
||||
|
||||
wiringpi2.softToneCreate(PIN)
|
||||
wiringpi2.softToneWrite(PIN,FREQUENCY)
|
||||
wiringpi.softToneCreate(PIN)
|
||||
wiringpi.softToneWrite(PIN,FREQUENCY)
|
||||
|
||||
**Bit shifting:**
|
||||
|
||||
wiringpi2.shiftOut(1,2,0,123) # Shift out 123 (b1110110, byte 0-255) to data pin 1, clock pin 2
|
||||
wiringpi.shiftOut(1,2,0,123) # Shift out 123 (b1110110, byte 0-255) to data pin 1, clock pin 2
|
||||
|
||||
**Serial:**
|
||||
|
||||
serial = wiringpi2.serialOpen('/dev/ttyAMA0',9600) # Requires device/baud and returns an ID
|
||||
wiringpi2.serialPuts(serial,"hello")
|
||||
wiringpi2.serialClose(serial) # Pass in ID
|
||||
serial = wiringpi.serialOpen('/dev/ttyAMA0',9600) # Requires device/baud and returns an ID
|
||||
wiringpi.serialPuts(serial,"hello")
|
||||
wiringpi.serialClose(serial) # Pass in ID
|
||||
|
||||
**Full details at:**
|
||||
http://www.wiringpi.com
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import wiringpi2
|
||||
import wiringpi
|
||||
PIN_TO_SENSE = 23
|
||||
|
||||
def gpio_callback():
|
||||
print "GPIO_CALLBACK!"
|
||||
|
||||
wiringpi2.wiringPiSetupGpio()
|
||||
wiringpi2.pinMode(PIN_TO_SENSE, wiringpi2.GPIO.INPUT)
|
||||
wiringpi2.pullUpDnControl(PIN_TO_SENSE, wiringpi2.GPIO.PUD_UP)
|
||||
wiringpi.wiringPiSetupGpio()
|
||||
wiringpi.pinMode(PIN_TO_SENSE, wiringpi.GPIO.INPUT)
|
||||
wiringpi.pullUpDnControl(PIN_TO_SENSE, wiringpi.GPIO.PUD_UP)
|
||||
|
||||
wiringpi2.wiringPiISR(PIN_TO_SENSE, wiringpi2.GPIO.INT_EDGE_BOTH, gpio_callback)
|
||||
wiringpi.wiringPiISR(PIN_TO_SENSE, wiringpi.GPIO.INT_EDGE_BOTH, gpio_callback)
|
||||
|
||||
while True:
|
||||
wiringpi2.delay(2000)
|
||||
wiringpi.delay(2000)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Demonstrates use of Arduino-like delay function
|
||||
import wiringpi2
|
||||
import wiringpi
|
||||
print 'Hello World'
|
||||
wiringpi2.delay(1500) # Delay for 1.5 seconds
|
||||
wiringpi.delay(1500) # Delay for 1.5 seconds
|
||||
print 'Hi again!'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import wiringpi2 as wiringpi
|
||||
import wiringpi
|
||||
INPUT = 0
|
||||
OUTPUT = 1
|
||||
LOW = 0
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander )
|
||||
import wiringpi2 as wiringpi
|
||||
import wiringpi
|
||||
|
||||
PIN_BACKLIGHT = 67 # LED
|
||||
PIN_SCLK = 68 # Clock SCLK
|
||||
@@ -92,4 +92,4 @@ for time in range(0,4):
|
||||
lcd_clear()
|
||||
wiringpi.delay(1000)
|
||||
lcd_fill()
|
||||
wiringpi.delay(1000)
|
||||
wiringpi.delay(1000)
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
# Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander )
|
||||
import wiringpi2
|
||||
import wiringpi
|
||||
|
||||
pin_base = 65
|
||||
i2c_addr = 0x20
|
||||
pins = [65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80]
|
||||
|
||||
wiringpi2.wiringPiSetup()
|
||||
wiringpi2.mcp23017Setup(pin_base,i2c_addr)
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.mcp23017Setup(pin_base,i2c_addr)
|
||||
|
||||
for pin in pins:
|
||||
wiringpi2.pinMode(pin,1)
|
||||
wiringpi2.digitalWrite(pin,1)
|
||||
# wiringpi2.delay(1000)
|
||||
# wiringpi2.digitalWrite(pin,0)
|
||||
wiringpi.pinMode(pin,1)
|
||||
wiringpi.digitalWrite(pin,1)
|
||||
# wiringpi.delay(1000)
|
||||
# wiringpi.digitalWrite(pin,0)
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
# Pulsates an LED connected to GPIO pin 1 with a suitable resistor 4 times using softPwm
|
||||
# softPwm uses a fixed frequency
|
||||
import wiringpi2
|
||||
import wiringpi
|
||||
|
||||
OUTPUT = 1
|
||||
|
||||
PIN_TO_PWM = 1
|
||||
|
||||
wiringpi2.wiringPiSetup()
|
||||
wiringpi2.pinMode(PIN_TO_PWM,OUTPUT)
|
||||
wiringpi2.softPwmCreate(PIN_TO_PWM,0,100) # Setup PWM using Pin, Initial Value and Range parameters
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.pinMode(PIN_TO_PWM,OUTPUT)
|
||||
wiringpi.softPwmCreate(PIN_TO_PWM,0,100) # Setup PWM using Pin, Initial Value and Range parameters
|
||||
|
||||
for time in range(0,4):
|
||||
for brightness in range(0,100): # Going from 0 to 100 will give us full off to full on
|
||||
wiringpi2.softPwmWrite(PIN_TO_PWM,brightness) # Change PWM duty cycle
|
||||
wiringpi2.delay(10) # Delay for 0.2 seconds
|
||||
wiringpi.softPwmWrite(PIN_TO_PWM,brightness) # Change PWM duty cycle
|
||||
wiringpi.delay(10) # Delay for 0.2 seconds
|
||||
for brightness in reversed(range(0,100)):
|
||||
wiringpi2.softPwmWrite(PIN_TO_PWM,brightness)
|
||||
wiringpi2.delay(10)
|
||||
wiringpi.softPwmWrite(PIN_TO_PWM,brightness)
|
||||
wiringpi.delay(10)
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
# Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander )
|
||||
import wiringpi2
|
||||
import wiringpi
|
||||
|
||||
pin_base = 65
|
||||
i2c_addr = 0x20
|
||||
i2c_addr_2 = 0x21
|
||||
#pins = [65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80]
|
||||
|
||||
wiringpi2.wiringPiSetup()
|
||||
wiringpi2.mcp23017Setup(pin_base,i2c_addr)
|
||||
wiringpi2.mcp23017Setup(pin_base+16,i2c_addr_2)
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.mcp23017Setup(pin_base,i2c_addr)
|
||||
wiringpi.mcp23017Setup(pin_base+16,i2c_addr_2)
|
||||
|
||||
#for pin in pins:
|
||||
for pin in range(65,96):
|
||||
wiringpi2.pinMode(pin,1)
|
||||
wiringpi2.digitalWrite(pin,1)
|
||||
# wiringpi2.delay(1000)
|
||||
# wiringpi2.digitalWrite(pin,0)
|
||||
wiringpi.pinMode(pin,1)
|
||||
wiringpi.digitalWrite(pin,1)
|
||||
# wiringpi.delay(1000)
|
||||
# wiringpi.digitalWrite(pin,0)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import wiringpi2 as wiringpi
|
||||
import wiringpi
|
||||
io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
|
||||
io.piGlowSetup()
|
||||
io.piGlowLeg(1,100)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import wiringpi2 as wiringpi
|
||||
import wiringpi
|
||||
io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
|
||||
print io.digitalRead(1)
|
||||
print io.analogRead(1)
|
||||
|
||||
Reference in New Issue
Block a user