Table of Contents

VIM1 WiringPi Python

WiringPi-Python Function List

//GPIO
class GPIO(object):
  def __init__(self,pinmode=0):
    self.MODE=pinmode
    if pinmode==self.WPI_MODE_PINS:
      wiringPiSetup()
    if pinmode==self.WPI_MODE_GPIO:
      wiringPiSetupGpio()
    if pinmode==self.WPI_MODE_GPIO_SYS:
      wiringPiSetupSys()
    if pinmode==self.WPI_MODE_PHYS:
      wiringPiSetupPhys()
	if pinmode==self.WPI_MODE_PIFACE:
      wiringPiSetupPiFace()
 
  def delay(self,*args):
    delay(*args)
  def delayMicroseconds(self,*args):
    delayMicroseconds(*args)
 
  def piBoardRev(self):
    return piBoardRev()
  def wpiPinToGpio(self,*args):
    return wpiPinToGpio(*args)
  def setPadDrive(self,*args):
    return setPadDrive(*args)
  def getAlt(self,*args):
    return getAlt(*args)
  def digitalWriteByte(self,*args):
    return digitalWriteByte(*args)
 
  def pinMode(self,*args):
    pinMode(*args)
 
  def digitalWrite(self,*args):
    digitalWrite(*args)
  def digitalRead(self,*args):
    return digitalRead(*args)
 
  def analogWrite(self,*args):
    analogWrite(*args)
  def analogRead(self,*args):
    return analogRead(*args)
 
  def pullUpDnControl(self,*args):
    return pullUpDnControl(*args)
 
  def softPwmCreate(self,*args):
    return softPwmCreate(*args)
  def softPwmWrite(self,*args):
    return softPwmWrite(*args)
 
//I2C:
class I2C(object):
  def setupInterface(self,*args):
  	return wiringPiI2CSetupInterface(*args)
  def setup(self,*args):
    return wiringPiI2CSetup(*args)
  def read(self,*args):
    return wiringPiI2CRead(*args)
  def readReg8(self,*args):
    return wiringPiI2CReadReg8(*args)
  def readReg16(self,*args):
    return wiringPiI2CReadReg16(*args)
  def write(self,*args):
    return wiringPiI2CWrite(*args)
  def writeReg8(self,*args):
    return wiringPiI2CWriteReg8(*args)
  def writeReg16(self,*args):
    return wiringPiI2CWriteReg16(*args)
 
//Serial:
class Serial(object):
  device = '/dev/ttyAMA0'
  baud = 9600
  serial_id = 0
  def printf(self,*args):
    return serialPrintf(self.serial_id,*args)
  def dataAvail(self,*args):
    return serialDataAvail(self.serial_id,*args)
  def getchar(self,*args):
    return serialGetchar(self.serial_id,*args)
  def putchar(self,*args):
    return serialPutchar(self.serial_id,*args)
  def puts(self,*args):
    return serialPuts(self.serial_id,*args)
  def __init__(self,device,baud):
    self.device = device
    self.baud = baud
    self.serial_id = serialOpen(self.device,self.baud)
  def __del__(self):
    serialClose(self.serial_id)

Demo Source Code

The test program set the value of Wiringpi number 16 and read it through Wiringpi number 17.

WiringPi-Python.py
import wiringpi as GPIO
 
INPUT = 0
OUTPUT = 1
OUTPUT_PIN = 17
INPUT_PIN = 16
OUTPUT_HIGH = 1
OUTPUT_LOW = 0
pinstatus_list = ['LOW','HIGH']
 
GPIO.wiringPiSetup()
GPIO.pinMode(OUTPUT_PIN, OUTPUT)
GPIO.pinMode(INPUT_PIN, INPUT)
 
print("----WiringPi Python Library Test-----")
 
print("set output pin is LOW level")
 
GPIO.digitalWrite(OUTPUT_PIN, OUTPUT_LOW)
result = GPIO.digitalRead(INPUT_PIN)
print('{}{}'.format('The read Pin value is', pinstatus_list[result]))
 
GPIO.delay(2000)
 
print("set output pin is High level")
 
GPIO.digitalWrite(OUTPUT_PIN, OUTPUT_HIGH)
result = GPIO.digitalRead(INPUT_PIN)
print('{}{}'.format('The read Pin value is', pinstatus_list[result]))
 
GPIO.delay(2000)
print("End")

Requires Dupont wire to link pins (Wiringpi number 16 and Wiringpi number 17).

2022/07/04 09:02 · frank