def StartGPIO(): wp.wiringPiSetupPhys() wp.pinMode(CsPin, wp.OUTPUT) wp.pinMode(DrdyPin, wp.INPUT) wp.pinMode(ResetPin, wp.OUTPUT) wp.digitalWrite(CsPin, wp.HIGH) wp.digitalWrite(ResetPin, wp.HIGH)
def setup(): global pwmL, pwmR GPIO.setmode(GPIO.BOARD) print("GPIO pin mode was set to GPIO.BOARD") GPIO.setup(pinHighL, GPIO.OUT) print("Using pin " + str(pinHighL) + " as GPIO.OUT") GPIO.setup(pinLowL, GPIO.OUT) print("Using pin " + str(pinLowR) + " as GPIO.OUT") GPIO.setup(pinHighR, GPIO.OUT) print("Using pin " + str(pinHighR) + " as GPIO.OUT") GPIO.setup(pinLowR, GPIO.OUT) print("Using pin " + str(pinLowR) + " as GPIO.OUT") GPIO.setup(pinPwmL, GPIO.OUT) print("Using pin " + str(pinPwmL) + " as GPIO.OUT") GPIO.setup(pinPwmR, GPIO.OUT) print("Using pin " + str(pinPwmR) + " as GPIO.OUT") pwmL = GPIO.PWM(pinPwmL, pwmFreq) print("Initiated PWM instance on pin " + str(pinPwmL)) pwmR = GPIO.PWM(pinPwmR, pwmFreq) print("Initiated PWM instance on pin " + str(pinPwmR)) pwmL.start(0) print("[PWM] Left speed: 0%") pwmR.start(0) print("[PWM] Right speed: 0%") print("RPi.GPIO setup complete!") print("Setting up WiringPi for the line sensors...") wp.wiringPiSetupPhys() for pin in pinsSensor: wp.pullUpDnControl(pin, wp.PUD_DOWN) print("WiringPi setup complete!")
def __init__(self): # Set up the wiringpi object to use physical pin numbers wp.wiringPiSetupPhys() # Initialize the DRDY pin wp.pinMode(self.DRDY_PIN, self.INPUT) # Initialize the reset pin wp.pinMode(self.RESET_PIN, self.OUTPUT) wp.digitalWrite(self.RESET_PIN, self.HIGH) # Initialize PDWN pin wp.pinMode(self.PDWN_PIN, self.OUTPUT) wp.digitalWrite(self.PDWN_PIN, self.HIGH) # Initialize CS pin for ADS1256 wp.pinMode(self.CS_PIN_AD, self.OUTPUT) wp.digitalWrite(self.CS_PIN_AD, self.HIGH) # Initialize CS pin for AD5314 wp.pinMode(self.CS_PIN_DA, self.OUTPUT) wp.digitalWrite(self.CS_PIN_DA, self.HIGH) # Initialize the spidev SPI setup self.spi_bus = spidev.SpiDev() self.spi_init() debug_print("SPI success " + str(self.spi_bus))
def __init__(self, conf=mohm_definitions): # Set up the wiringpi object to use physical pin numbers wp.wiringPiSetupPhys() # Config and initialize the SPI and GPIO pins used by the ADC. # The following four entries are actively used by the code: self.ESC1_PIN = conf.ESC1_PIN self.ESC2_PIN = conf.ESC2_PIN self.ESC3_PIN = conf.ESC3_PIN self.GAIN_PIN = conf.GAIN_PIN self.INPUT1 = conf.INPUT1 self.INPUT2 = conf.INPUT2 self.INPUT3 = conf.INPUT3 self.INPUT4 = conf.INPUT4 # GPIO Outputs configuration, used to scaled selection for pin in (conf.ESC1_PIN, conf.ESC2_PIN, conf.ESC3_PIN, conf.GAIN_PIN): if pin is not None: wp.pinMode(pin, wp.OUTPUT) wp.digitalWrite(pin, wp.LOW) # GPIO Outputs configuration, used to scaled selection for pin in (conf.INPUT1, conf.INPUT2, conf.INPUT3, conf.INPUT4): if pin is not None: wp.pinMode(pin, wp.INPUT)
def __init__(self, SPI_CHANNEL, SPI_FREQUENCY, CS_PIN): "Instantiates a DAC object with the given parameters" self.SPI_CHANNEL = SPI_CHANNEL self.SPI_FREQUENCY = SPI_FREQUENCY self.CS_PIN = CS_PIN debug_print('pydac8532 initializing with:') debug_print(' SPI_MODE = %d' % self.SPI_MODE) debug_print(' SPI_CHANNEL = %d' % self.SPI_CHANNEL) debug_print(' SPI_FREQUENCY = ' + format(self.SPI_FREQUENCY, ',')) debug_print(' CS_PIN = %d' % self.CS_PIN) # Set up the wiringPi object to use physical pin numbers wp.wiringPiSetupPhys() # Initialize CS pin wp.pinMode(self.CS_PIN, wp.OUTPUT) wp.digitalWrite(self.CS_PIN, wp.HIGH) # Initialize the wiringPi SPI setup spi_success = wp.wiringPiSPISetupMode(self.SPI_CHANNEL, self.SPI_FREQUENCY, self.SPI_MODE) #JKR debug_print('SPI success: ' + str(spi_success))
def __init__(self, SPI_CHANNEL, SPI_FREQUENCY, CS_PIN): self.SPI_CHANNEL = SPI_CHANNEL self.SPI_FREQUENCY = SPI_FREQUENCY self.CS_PIN = CS_PIN debug_print('pylps22hb initializing with:') debug_print(' SPI_MODE = %d' % self.SPI_MODE) debug_print(' SPI_CHANNEL = %d' % self.SPI_CHANNEL) debug_print(' SPI_FREQUENCY = ' + format(self.SPI_FREQUENCY, ',')) debug_print(' CS_PIN = %d' % CS_PIN) # Set up the wiringpi object to use physical pin numbers wp.wiringPiSetupPhys() # Initialize CS pins wp.pinMode(self.CS_PIN, wp.OUTPUT) wp.digitalWrite(self.CS_PIN, wp.HIGH) # Initialize the wiringpi SPI setup #spi_success = wp.wiringPiSPISetup(self.SPI_CHANNEL, self.SPI_FREQUENCY) spi_success = wp.wiringPiSPISetupMode(self.SPI_CHANNEL, self.SPI_FREQUENCY, self.SPI_MODE) #JKR debug_print("SPI success " + str(spi_success))
def __init__(self): # Set up the wiringpi object to use physical pin numbers wp.wiringPiSetupPhys() print("pyads1256 1") # Initialize the DRDY pin wp.pinMode(self.DRDY_PIN, wp.INPUT) print("pyads1256 2") # Initialize the reset pin wp.pinMode(self.RESET_PIN, wp.OUTPUT) wp.digitalWrite(self.RESET_PIN, wp.HIGH) print("pyads1256 3") # Initialize PDWN pin wp.pinMode(self.PDWN_PIN, wp.OUTPUT) wp.digitalWrite(self.PDWN_PIN, wp.HIGH) print("pyads1256 4") # Initialize CS pin wp.pinMode(self.CS_PIN, wp.OUTPUT) wp.digitalWrite(self.CS_PIN, wp.HIGH) print("pyads1256 5") # Initialize the wiringpi SPI setup print("Initializing wiringPiSPISetup with channel=", self.SPI_CHANNEL, "and frequency=", self.SPI_FREQUENCY) spi_success = wp.wiringPiSPISetup(self.SPI_CHANNEL, self.SPI_FREQUENCY) debug_print("SPI success " + str(spi_success)) print("pyads1256 6", spi_success)
def __init__(self, *args): debug_print('pydads1256 initializing with:') debug_print(' SPI_MODE = %d' % self.SPI_MODE) debug_print(' SPI_CHANNEL = %d' % self.SPI_CHANNEL) debug_print(' SPI_FREQUENCY = ' + format(self.SPI_FREQUENCY, ',')) debug_print(' CS_PIN = %d' % self.CS_PIN) debug_print(' DRDY_PIN = %d' % self.DRDY_PIN) debug_print(' RESET_PIN = %d' % self.RESET_PIN) debug_print(' PDWN_PIN = %d' % self.PDWN_PIN) # Set up the wiringpi object to use physical pin numbers wp.wiringPiSetupPhys() # Initialize the DRDY pin wp.pinMode(self.DRDY_PIN, wp.INPUT) # Initialize the reset pin wp.pinMode(self.RESET_PIN, wp.OUTPUT) wp.digitalWrite(self.RESET_PIN, wp.HIGH) # Initialize PDWN pin wp.pinMode(self.PDWN_PIN, wp.OUTPUT) wp.digitalWrite(self.PDWN_PIN, wp.HIGH) # Initialize CS pin wp.pinMode(self.CS_PIN, wp.OUTPUT) wp.digitalWrite(self.CS_PIN, wp.HIGH) # Initialize the wiringpi SPI setup #spi_success = wp.wiringPiSPISetup(self.SPI_CHANNEL, self.SPI_FREQUENCY) spi_success = wp.wiringPiSPISetupMode(self.SPI_CHANNEL, self.SPI_FREQUENCY, self.SPI_MODE) #JKR debug_print("SPI success " + str(spi_success))
def __init__(self, pin): super(WiringPiPump, self).__init__(pin) # wiringpi.wiringPiSetupGpio() wiringpi.wiringPiSetupPhys() wiringpi.pinMode(pin, wiringpi.GPIO.INPUT) wiringpi.pullUpDnControl( pin, wiringpi.GPIO.PUD_OFF) # use external pull-down resistor wiringpi.wiringPiISR(pin, wiringpi.GPIO.INT_EDGE_BOTH, self.event)
def __init__(self, broker): Module.__init__(self, broker) self.subscribe("red_value", self.handleRedValue) self.subscribe("green_value", self.handleGreenValue) self.subscribe("blue_value", self.handleBlueValue) wiringpi.wiringPiSetupPhys() wiringpi.pinMode(self.r_pin, 2) wiringpi.pinMode(self.g_pin, 2) wiringpi.pinMode(self.b_pin, 2)
def __init__(self, low=45, high=75): self.low = low self.high = high self.pin = 32 self.is_high = False wiringpi.wiringPiSetupPhys() wiringpi.pinMode(self.pin, 2) wiringpi.pwmSetMode(0) wiringpi.pwmSetRange(1024) wiringpi.pwmSetClock(375) wiringpi.pwmWrite(self.pin, self.low)
def handle(self, text, parsed): import wiringpi # get config profile = config.get() pin=profile[self.SLUG]['pin'] wiringpi.wiringPiSetupPhys() wiringpi.pinMode(pin,1) if any(word in text for word in [u"打开",u"开启"]): wiringpi.digitalWrite(pin,0) self.say("好的,已经打开台灯", cache=True) elif any(word in text for word in [u"关闭",u"关掉",u"熄灭"]): wiringpi.digitalWrite(pin,1) self.say("好的,已经关闭台灯", cache=True)
def init_gpio(): """ 初始化gpio口 :return: """ # Set up the wiringpi object to use physical pin numbers wp.wiringPiSetupPhys() # wp.pinMode(INT_PIN, INPUT) # wp.digitalWrite(CS_PIN, HIGH) # 中断注册 # print('INT: ') print(wp.wiringPiISR(INT_PIN, wp.INT_EDGE_FALLING, int_from_pca9535))
def handle(text, mic, profile, wxbot=None): logger = logging.getLogger(__name__) # get config pin = profile[SLUG]['pin'] wiringpi.wiringPiSetupPhys() wiringpi.pinMode(pin, 1) if any(word in text for word in [u"打开", u"开启"]): wiringpi.digitalWrite(pin, 0) mic.say("好的,已经打开台灯") elif any(word in text for word in [u"关闭", u"关掉", u"熄灭"]): wiringpi.digitalWrite(pin, 1) mic.say("好的,已经关闭台灯") return True
def __new__(cls): if cls.singleton is None: try: import RPi.GPIO as GPIO import wiringpi except (ImportError, RuntimeError): GPIO = None wiringpi = None if GPIO is not None: wiringpi.wiringPiSetupPhys() cls.singleton = super(WiringPi, cls).__new__(cls) cls.singleton._is_raspberry_pi = GPIO is not None cls.singleton._module = wiringpi return cls.singleton
def __init__(self): # Set up the wiringpi object to use physical pin numbers wp.wiringPiSetupPhys() # Initialize the DRDY pin wp.pinMode(self.DRDY_PIN, self.INPUT) # Initialize the reset pin wp.pinMode(self.RESET_PIN, self.OUTPUT) wp.digitalWrite(self.RESET_PIN, self.HIGH) # Initialize PDWN pin wp.pinMode(self.PDWN_PIN, self.OUTPUT) wp.digitalWrite(self.PDWN_PIN, self.HIGH) # Initialize CS pin wp.pinMode(self.CS_PIN, self.OUTPUT) wp.digitalWrite(self.CS_PIN, self.HIGH)
def __init__(self): # Set up the wiringpi object to use physical pin numbers wp.wiringPiSetupPhys() # Initialize the DRDY pin wp.pinMode(self.DRDY_PIN, wp.INPUT) # Initialize the reset pin wp.pinMode(self.RESET_PIN, wp.OUTPUT) wp.digitalWrite(self.RESET_PIN, wp.HIGH) # Initialize PDWN pin wp.pinMode(self.PDWN_PIN, wp.OUTPUT) wp.digitalWrite(self.PDWN_PIN, wp.HIGH) # Initialize CS pin wp.pinMode(self.CS_PIN, wp.OUTPUT) wp.digitalWrite(self.CS_PIN, wp.HIGH) # Initialize the wiringpi SPI setup spi_success = wp.wiringPiSPISetupMode(self.SPI_CHANNEL, self.SPI_FREQUENCY, self.SPI_MODE) debug_print("SPI success " + str(spi_success))
def __init__(self, r_pin, g_pin, b_pin): self.R_PIN = r_pin self.G_PIN = g_pin self.B_PIN = b_pin self.LED_PINS = [self.R_PIN, self.G_PIN, self.B_PIN] self.states = { 'loading': False, 'error': False, 'transmitting': False, 'receiving': False } self.last_value = False self.setup = wiringpi.wiringPiSetupPhys() self.pinMode = wiringpi.pinMode self.delay_time = .4 self.current_time = time() self.last_time = time()
def onjoined(*args): print 'realm joined' global state print 'initialize start' # setup hardware pwm using wiringpi print 'hardware pwm setup' wiringpi.wiringPiSetupPhys() wiringpi.pinMode(GPIO_PWM, 2) # 2=hardware pwm wiringpi.pwmWrite(GPIO_PWM, 1024) # setup GPIO ports using RPi.GPIO print 'software pwm setup' GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(GPIO_GROUP1, GPIO.OUT) GPIO.output(GPIO_GROUP1, False) GPIO.setup(GPIO_GROUP2, GPIO.OUT) GPIO.output(GPIO_GROUP2, False) GPIO.setup(GPIO_GROUP3, GPIO.OUT) GPIO.output(GPIO_GROUP3, False) if group_count > 3: GPIO.setup(GPIO_GROUP4, GPIO.OUT) GPIO.output(GPIO_GROUP4, False) grp1_p = GPIO.PWM(GPIO_GROUP1, PWM_FREQUENCY) grp1_p.start(0) grp2_p = GPIO.PWM(GPIO_GROUP2, PWM_FREQUENCY) grp2_p.start(0) grp3_p = GPIO.PWM(GPIO_GROUP3, PWM_FREQUENCY) grp3_p.start(0) if group_count > 3: grp4_p = GPIO.PWM(GPIO_GROUP4, PWM_FREQUENCY) grp4_p.start(0) pwm_all = [grp1_p, grp2_p, grp3_p, grp4_p] else: pwm_all = [grp1_p, grp2_p, grp3_p] # main loop while True: if state == STATE_DEMO: print 'demo mode' for grp_p in pwm_all: grp_p.ChangeDutyCycle(0) wiringpi.pwmWrite(12, 1024) # グループ1からグループ4まで点灯 for grp_p in pwm_all: for d in range(0, 101): grp_p.ChangeDutyCycle(d) yield sleep(0.03) if state != STATE_DEMO: break if state != STATE_DEMO: break sleep(2) for d in range(100, -1, -1): v = int((1024 / 100.0) * d) wiringpi.pwmWrite(12, v) yield sleep(0.05) if state != STATE_DEMO: break for grp_p in pwm_all: grp_p.ChangeDutyCycle(0) yield sleep(2) elif state == STATE_NORMAL: for grp_p in pwm_all: grp_p.ChangeDutyCycle(100) v = int((1024 / 100.0) * value) wiringpi.pwmWrite(12, v) if state != STATE_NORMAL: break yield sleep(0.001)
# 1 3.3v # # 34 GND # 39 GND # # 33 GPIO13 wpi-23 # 35 GPIO19 wpi-24 # 36 GPIO16 wpi-27 # 37 GPIO26 wpi-25 # 38 GPIO20 wpi-28 # 40 GPIO21 wpi-29 # import wiringpi from time import sleep wiringpi.wiringPiSetupPhys() # choose physical pin numbers # # pins 39 and 40 are the last two pins on the raspberry pi # GPIO connector, pin 39 is a ground, pin 40 is a GPIO # wiringpi.pinMode(12, 2) # make pin 40 an output wiringpi.pinMode(38, 1) # make pin 40 an output wiringpi.pinMode(37, 1) # make pin 40 an output while (1): for i in range(1023): wiringpi.pwmWrite(12, i) # turn pin 40 on sleep(0.001)
#!/usr/bin/python3 import wiringpi import time PIN = 12 wiringpi.wiringPiSetupPhys() wiringpi.pinMode(PIN, 2) maxreps = 10 repetitions = 0 while repetitions < maxreps: for i in range(0, 1001, 50): wiringpi.pwmWrite(PIN, i) time.sleep(0.1) for i in range(0, 1001, 50): wiringpi.pwmWrite(PIN, 1000 - i) time.sleep(0.1) repetitions += 1 wiringpi.pwmWrite(PIN, 0)
#//SCLK ----- SCLK #//DRDY ----- ctl_IO data starting #//RST ----- ctl_IO reset spi = spidev.SpiDev() spi.open(0, 0) spi.max_speed_hz = 1920000 spi.mode = 0b01 spi.lsbfirst = True #define SPICS RPI_GPIO_P1_16 //P4 SPICS = 16 RES1PIN = 29 RES2PIN = 31 wp.wiringPiSetupPhys() wp.pinMode(SPICS, wp.OUTPUT) wp.pinMode(RES1PIN, wp.OUTPUT) wp.pinMode(RES2PIN, wp.OUTPUT) def CS_1(): wp.digitalWrite(SPICS, wp.HIGH) def CS_0(): wp.digitalWrite(SPICS, wp.LOW) channel_A = 0x30 channel_B = 0x34
def setup(): wiringpi.wiringPiSetupPhys()
import Adafruit_GPIO.SPI import Adafruit_MCP3008 import pigpio import threading import atexit logging.basicConfig(level=logging.INFO, format="[{asctime}] {levelname} - {message}", style="{") LOG = logging.getLogger(__name__) LOOP_INTERVAL = 1 LOG_INTERVAL = 120 wiringpi.wiringPiSetupPhys() # use physical pin mapping timers: typing.Dict[str, datetime.datetime] = collections.defaultdict( datetime.datetime.now) SPI_PORT = 0 SPI_DEVICE = 0 class Loop(threading.Thread): def __init__(self, event: threading.Event, target: typing.Callable, *args, **kwargs): threading.Thread.__init__(self) self.stopped = event self._args = args self._kwargs = kwargs
import time import sys reload(sys) # Reload does the trick! sys.setdefaultencoding('UTF8') import subprocess import fcntl, socket, struct import wiringpi # external file imports import PID # PID controller by # IvPID. # Copyright (C) 2015 Ivmech Mechatronics Ltd. <*****@*****.**> # activate wiringPi with mapping to physical ports of pinheader wiringpi.wiringPiSetupPhys() os.system('modprobe w1-gpio') os.system('modprobe w1-therm') base_dir = '/sys/bus/w1/devices/' try: device_folder_0 = glob.glob(base_dir + '28*')[0] device_folder_1 = glob.glob(base_dir + '28*')[1] except: print "no one wire devices found" try: device_file_0 = device_folder_0 + '/w1_slave' device_file_1 = device_folder_1 + '/w1_slave'
def __init__(self): wp.wiringPiSetupPhys() wp.pinMode(self.CS_PIN, self.OUTPUT) wp.digitalWrite(self.CS_PIN, self.HIGH)
def __init__(self, conf=ADS1256_default_config): # Set up the wiringpi object to use physical pin numbers wp.wiringPiSetupPhys() # Config and initialize the SPI and GPIO pins used by the ADC. # The following four entries are actively used by the code: self.SPI_CHANNEL = conf.SPI_CHANNEL self.DRDY_PIN = conf.DRDY_PIN self.CS_PIN = conf.CS_PIN self.DRDY_TIMEOUT = conf.DRDY_TIMEOUT self.DRDY_DELAY = conf.DRDY_DELAY # Only one GPIO input: if conf.DRDY_PIN is not None: self.DRDY_PIN = conf.DRDY_PIN wp.pinMode(conf.DRDY_PIN, wp.INPUT) # GPIO Outputs. Only the CS_PIN is currently actively used. ~RESET and # ~PDWN must be set to static logic HIGH level if not hardwired: for pin in (conf.CS_PIN, conf.RESET_PIN, conf.PDWN_PIN): if pin is not None: wp.pinMode(pin, wp.OUTPUT) wp.digitalWrite(pin, wp.HIGH) # Initialize the wiringpi SPI setup. Return value is the Linux file # descriptor for the SPI bus device: fd = wp.wiringPiSPISetupMode(conf.SPI_CHANNEL, conf.SPI_FREQUENCY, conf.SPI_MODE) if fd == -1: raise IOError("ERROR: Could not access SPI device file") return False # ADS1255/ADS1256 command timing specifications. Do not change. # Delay between requesting data and reading the bus for # RDATA, RDATAC and RREG commands (datasheet: t_6 >= 50*CLKIN period). self._DATA_TIMEOUT_US = int(1 + (50 * 1000000) / conf.CLKIN_FREQUENCY) # Command-to-command timeout after SYNC and RDATAC # commands (datasheet: t11) self._SYNC_TIMEOUT_US = int(1 + (24 * 1000000) / conf.CLKIN_FREQUENCY) # See datasheet ADS1256: CS needs to remain low # for t_10 = 8*T_CLKIN after last SCLK falling edge of a command. # Because this delay is longer than timeout t_11 for the # RREG, WREG and RDATA commands of 4*T_CLKIN, we do not need # the extra t_11 timeout for these commands when using software # chip select selection and the _CS_TIMEOUT_US. self._CS_TIMEOUT_US = int(1 + (8 * 1000000) / conf.CLKIN_FREQUENCY) # When using hardware/hard-wired chip select, still a command- # to command timeout of t_11 is needed as a minimum for the # RREG, WREG and RDATA commands. self._T_11_TIMEOUT_US = int(1 + (4 * 1000000) / conf.CLKIN_FREQUENCY) # Initialise class properties self.v_ref = conf.v_ref # At hardware initialisation, a settling time for the oscillator # is necessary before doing any register access. # This is approx. 30ms, according to the datasheet. time.sleep(0.03) self.wait_DRDY() # Device reset for defined initial state self.reset() # Configure ADC registers: # Status register not yet set, only variable written to avoid multiple # triggering of the AUTOCAL procedure by changing other register flags self._status = conf.status # Class properties now configure registers via their setter functions self.mux = conf.mux self.adcon = conf.adcon self.drate = conf.drate self.gpio = conf.gpio self.status = conf.status
def __init__(self, pin=12): # usually BCM GPIO 18 self.__pin = pin wipi.wiringPiSetupPhys() wipi.pinMode(self.__pin, 2)