def init(self, pins): wiringpi2.wiringPiSetup() self._pins = set(pins) Log('Setting pins %s to output mode...' % list(self._pins)) for i in self._pins: wiringpi2.pinMode(i, PINMODE_OUTPUT) Log("Done.")
def fancontrol(input): import wiringpi2 as wiringpi OUTPUT = 1 INPUT = 0 wiringpi.wiringPiSetup() wiringpi.pinMode(8,OUTPUT) wiringpi.digitalWrite(8,input)
def test(): pin = 0 gpio.wiringPiSetup() #初始化 gpio.wiringPiSetupSys() #初始化 gpio.pinMode(pin, GPIO.OUTPUT) # 把pin25设置为输出模式 gpio.digitalWrite(pin, GPIO.HIGH) #pin25输出为高电平 print(gpio.digitalRead(pin)) #打印pin25的状态
def initialize_hardware(self): wiringpi.wiringPiSetup() wiringpi.pinMode(GPIOPin.PIN_STATUS_LED.value, PinMode.OUTPUT.value) wiringpi.pinMode(GPIOPin.PIN_SOUND.value, PinMode.OUTPUT.value) wiringpi.pinMode(GPIOPin.PIN_RGB_RED.value, PinMode.OUTPUT.value) wiringpi.pinMode(GPIOPin.PIN_RGB_GREEN.value, PinMode.OUTPUT.value) wiringpi.pinMode(GPIOPin.PIN_RGB_BLUE.value, PinMode.OUTPUT.value)
def readData(pin): hum = 0 temp = 0 crc = 0 GPIO.pinMode(pin, 1) GPIO.digitalWrite(pin, 1) GPIO.digitalWrite(pin, 0) GPIO.delay(20) GPIO.digitalWrite(pin, 1) GPIO.pinMode(pin, 0) GPIO.delayMicroseconds(40) if GPIO.digitalRead(pin) == 0: untilHigh(pin) for i in range(16): hum <<= 1 untilLow(pin) untilHigh(pin) GPIO.delayMicroseconds(28) hum += GPIO.digitalRead(pin) for i in range(16): temp <<= 1 untilLow(pin) untilHigh(pin) GPIO.delayMicroseconds(28) temp += GPIO.digitalRead(pin) for i in range(8): crc <<= 1 untilLow(pin) untilHigh(pin) GPIO.delayMicroseconds(28) crc += GPIO.digitalRead(pin) return [True, hum, temp, crc] else: return [False, hum, temp, crc]
def get(self): response = {} # Make sure sensor pin is set to input mode try: wpi.pinMode(config['SENSOR_PIN_NUM'],0) except: response['status'] = "error" response['errorCode'] = "GPIO pin input mode error." response['message'] = "Cannot {} garage door.".format(config['MODE']) resp = jsonify(response) resp.status_code = 500 return resp try: if wpi.digitalRead(config['SENSOR_PIN_NUM']): response['doorStatus'] = 'open' else: response['doorStatus'] = 'closed' except: response['status'] = "error" response['errorCode'] = "GPIO pin read error." response['message'] = "Cannot determine garage door status." resp = jsonify(response) resp.status_code = 500 return resp response['status'] = "success" response['errorCode'] = None response['message'] = "Garage door is {}.".format(response['doorStatus']) resp = jsonify(response) resp.status_code = 200 return resp
def switch(self, v): if self.reading() != v: self.logger.debug('relay: switch: pin:%s %s' % (self.pin, str(v))) wiringpi.pinMode(self.pin, v) wiringpi.digitalWrite(self.pin, v) else: self.logger.debug('relay: switch: pin %s ignore already %s' % (self.pin, str(v)))
def __init__(self, therm_pin, sensor_pin, target_temp=55): self.target_temp = target_temp self.THERM = therm_pin self.sensor = Sensor(sensor_pin) self.running = True self.heat_on = False self.current_temp = None self.OUT = 1 self.IN = 0 self.PWM = 0 self.bounds = [55, 66, 80] self.learner = learner.Events(self, 'therm', 55, 5, 5 * 60) self.set_lock = RLock() wiringpi.wiringPiSetupSys() setupInCmd1 = 'echo "{}" > /sys/class/gpio/export'.format(sensor_pin) setupOutCmd1 = 'echo "{}" > /sys/class/gpio/export'.format(self.THERM) setupInCmd2 = 'echo "in" > /sys/class/gpio/gpio{}/direction'.format(sensor_pin) setupOutCmd2 = 'echo "out" > /sys/class/gpio/gpio{}/direction'.format(self.THERM) Popen( setupInCmd1, shell=True) Popen( setupInCmd2, shell=True) Popen(setupOutCmd1, shell=True) Popen(setupOutCmd2, shell=True) wiringpi.pinMode(self.THERM, self.OUT) wiringpi.pinMode(sensor_pin, self.IN) wiringpi.digitalWrite(self.THERM, 0) # give some time to read an initial temperature self.timer = Timer(15, self.tick) self.timer.start() self.temp_log_timer = Timer(5 * 60, self.logTemp) self.temp_log_timer.start() self.temp_logger = jsonlog.jsonLog('data/real-therm-data')
def set_pin(pin, state): global state_updated s = None try: s = pin_state[pin] except KeyError: logger.debug("pin {0} had no state. Initializing?".format(pin)) if wiringpi.getAlt(pin) != PIN_MODE_ACTIVE: logger.warn( 'Attempting to set output value on NON-ACTIVE pin {0} (mode: {1}). Forcing to OUTPUT and setting...'.format( pin, PIN_MODES.get(wiringpi.getAlt(pin)))) wiringpi.pinMode(pin, PIN_MODE_ACTIVE) pin_state[pin] = state if s == state: state_updated = False else: state_updated = True name = pin_names.get(pin) if name is not None: n = name else: n = "Pin_{0}".format(pin) logger.info("{0} -> {1}".format(n, state_names[pin_state.get(pin)]))
def __init__(self): """ Set up hardware """ super().__init__() wiringpi.wiringPiSetup() # Set up each pin for digital output for i in self.lightPinMap: wiringpi.pinMode(i, 1)
def __init__(self, GPIO, name, hasNeutral): self.pin = GPIO self.name = name self.hasNeutral = hasNeutral self.isMidPulse = False self.pulseStart = 0 self.pulseEnd = 0 self.pulses = [] self.minPulseLen = 1200 self.maxDeltaLen = 600 self.neutralDeltaLen = 1500 self.lastOutput = 0.0 self.isPrintData = True self.preprocessData = True try: with open('radio.cfg') as file: for line in file: if line.startswith(self.name): data = line.split(',') self.minPulseLen = int(data[2]) self.maxDeltaLen = int(data[1]) - self.minPulseLen if self.hasNeutral: self.neutralDeltaLen = int(data[3]) - self.minPulseLen except (OSError, IOError): procComms.PrintLog('Config file not found. Use radioConfig.py!') wiringpi.pinMode(self.pin, 0)
def __init__(self, cursor): threading.Thread.__init__(self) wiringpi.wiringPiSetupGpio() wiringpi.pinMode(17, 0) self.cursor = cursor self.start() self.shot = False
def setup_servo(): wiringpi.wiringPiSetupGpio() wiringpi.pinMode(18,2) # hardware pwm only works on GPIO port 18 wiringpi.pwmSetMode(0) wiringpi.pwmSetClock(375) wiringpi.pwmSetRange(1024) wiringpi.pwmWrite(18,0)
def set(self,newState): newState = int(newState) # FIXME need to catch error print "Switching relay " + `self.relayA` + " to " + `newState` wiringpi.pinMode(self.relayA,self.OUTPUT_MODE) initialState = wiringpi.digitalRead(self.relayA) wiringpi.digitalWrite(self.relayA, newState) currentState = wiringpi.digitalRead(self.relayA) result = None if(initialState == currentState): result = "Target state was already set. No action taken" else: result = "Switched" errors = None return { "controller": self.name, "timestamp": datetime.datetime.now().isoformat(' '), "result": result, "errors": errors, }
def init(): lcd.init() lcd.cls() lcd.backlight(ON) wiringpi.pinMode(BUTTON_OK,INPUT) wiringpi.pinMode(BUTTON_FKEY,INPUT)
def Init(): wiringpi2.pinMode(data_pin, 0) wiringpi2.pinMode(clock_pin, 0) wiringpi2.wiringPiSetup() SendData(cmdlist["led_cmd"]) wiringpi2.delay(50)
def init_control_plane(): logger.info("Initializing control plane") chip1_i2c_addr = 0x20 # Controlled by A0, A1, A2 pins GND or +5V # chip2_i2c_addr = 0x22 # Controlled by A0, A1, A2 pins GND or +5V # chip3_i2c_addr = 0x23 # Controlled by A0, A1, A2 pins GND or +5V # chip4_i2c_addr = 0x24 # Controlled by A0, A1, A2 pins GND or +5V wiringpi.wiringPiSetup() # initialise wiringpi wiringpi.mcp23017Setup(pin_base, chip1_i2c_addr) # pins 65-80 # wiringpi.mcp23017Setup(pin_base + 16, chip2_i2c_addr) # pins 81-96 # wiringpi.mcp23017Setup(pin_base + 32, chip3_i2c_addr) # pins 97-112 # wiringpi.mcp23017Setup(pin_base + 48, chip4_i2c_addr) # pins 113-128 for pin in range(pin_base, pin_max): set_pin(pin, OFF) wiringpi.pinMode(pin, PIN_MODE_ACTIVE) # set to output mode sleep(1) for pin in range(pin_base, pin_max): mode = wiringpi.getAlt(pin) if mode != PIN_MODE_ACTIVE: logger.error("Initialized pin {0} to mode {1} but found it in mode {2}".format(pin, PIN_MODE_ACTIVE, mode)) # and then apply our CHANGES apply_model(False) logger.info("Control plane initialized successfully")
def set_pin_as_input(pin): """Set the specified pin as an input. :param pin: index of pin in cm.hardware.gpio_pins :type pin: int """ wiringpi.pinMode(cm.hardware.gpio_pins[pin], _GPIOASINPUT)
def init(self, PWMmode): self.PWMmode = PWMmode wiringpi2.wiringPiSetup() if self.PWMmode == True: wiringpi2.pinMode(1, 2) else: wiringpi2.pinMode(1,1)
def init_pump_control(): #os.system("gpio mode 7 out") wpi.wiringPiSetup() wpi.pinMode(_PIN, _OUTPUT) rospy.set_param("pump_state", False) rospy.init_node("pump_control") s = rospy.Service("pump_control", PumpControl, pump_control_callback) rospy.spin()
def setup(): wiringpi.wiringPiSetupGpio() wiringpi.pinMode(25,1) #red light wiringpi.digitalWrite(25,0) #red is off wiringpi.pinMode(24,1) #green light wiringpi.digitalWrite(24,0) #green is off flash(2)
def __init__(self): led.wiringPiSetupGpio() led.pinMode(18, 2) # sets GPIO 24 to output #self.pwmLed=pwmLed #self.ledPin=18 self.pwmThread=threading.Thread(target=self.fade)
def __init__(self,steps_per_rev=12800,p_pin=19,d_pin=26): self.steps_per_rev = steps_per_rev self.p_pin = p_pin self.d_pin = d_pin self.p_direction = -1 #assign picker direction self.motor_address = 0 io1.pinMode(self.d_pin,1) io1.pinMode(self.p_pin,1)
def __init__(self, pin1=13, pin2=15): """pin1 = white/signal | pin2 = red/power""" self.pin1 = pin1 self.pin2 = pin2 wp.pinMode(self.pin1, OUTPUT) output_pins.append(self.pin1) wp.pinMode(self.pin2, OUTPUT) output_pins.append(self.pin2)
def controlPin(self, onTime, offTime, pin): wp.pinMode(pin, 1) while not self.stop: wp.digitalWrite(pin, 1) time.sleep(onTime.value) wp.digitalWrite(pin, 0) time.sleep(offTime.value)
def __init__(self,): threading.Thread.__init__(self) #self.adc = adc self.waterflow = 0.0 self.quit = False wp.wiringPiSetup() for i in range(0, 7): wp.pinMode(i, 0)
def __init__(self): self.amyPin = 4 self.benPin = 5 wiringpi2.wiringPiSetup() wiringpi2.pinMode(self.amyPin,1) wiringpi2.pinMode(self.benPin,1)
def __init__(self, external_lights): super(Lights, self).__init__() self.external_lights = external_lights # hardware PWM led (and power off lights) wiringpi2.pinMode(self.LIGHTS_PIN, wiringpi2.GPIO.PWM_OUTPUT) wiringpi2.pwmWrite(self.LIGHTS_PIN, self.PWM_VAL_MAX) if self.external_lights: wiringpi2.pinMode(self.EXTERNAL_LIGHTS_PIN, wiringpi2.GPIO.OUTPUT) wiringpi2.digitalWrite(self.EXTERNAL_LIGHTS_PIN, 1)
def __init__(self, freq = 100.0): self.freq = freq output_pins.append(12) wp.pinMode(12, PWM) wp.pwmSetRange(4000) #range can go up to 4096, 4000 is good because it's large and a multiple of 100 clock = 19.2e6 / (4000.0 * freq) #set the divisor so the frequency comes out right wp.pwmSetClock(int(clock)) #this function needs an int wp.pwmSetMode(0) # necessary or else it's in a weird mode where nothing works wp.pwmWrite(12, 0) # stop for safety
def resetAD7705(self): # Reset wiringpi2.pinMode(23,1) wiringpi2.digitalWrite(23,0) wiringpi2.digitalWrite(23,1) # Initialize AD7705 self.spi.xfer2([0xff, 0xff, 0xff, 0xff, 0xff]) self.spi.xfer2([0x20, 0x0c, 0x10, 0x40, 0x08]) return 1
def __init__(self, stepPin, dirPin): #initial a Bipolar_Stepper_Moter objects by assigning the pins wiringpi2.wiringPiSetupPhys() self.stepPin = stepPin self.dirPin = dirPin wiringpi2.pinMode(self.stepPin, 1) wiringpi2.pinMode(self.dirPin, 1) print "Stepper Configured"
def readheading(self): wiringpi.wiringPiSetupGpio() wiringpi.pinMode(self.pin, 0) ser = wiringpi.serialOpen('/dev/serial0', 115200) data = [] while True: data.append(wiringpi.serialGetchar(ser)) print(wiringpi.serialGetchar(ser)) sleep(0.03) return data
def buzzer(): Buzz = x # x will be buzzer's Pin number GPIO.pinMode(Buzz, 1) while True: dist = ult.distance_5() if dist <= 30: GPIO.digitalWrite(BUzz, 0) time.sleep(dist / 30) GPIO.digitalWrite(BUZZ, 1)
def __init__(self, power_calculator, datasocket): threading.Thread.__init__(self) self.pinnumber = 0 self.pc = power_calculator self.datasocket = datasocket self.beatperiod = 5 # seconds self.beatsteps = 100 self.dutycycle = 0 self.quit = False wp.pinMode(self.pinnumber, 1) # Set pin 0 to output
def __init__(self): wiringpi2.wiringPiSetupGpio() self.SPEAKER = 18 self.MODE_PWM = 2 wiringpi2.pinMode(self.SPEAKER, self.MODE_PWM) wiringpi2.pwmSetMode(wiringpi2.GPIO.PWM_MODE_MS) wiringpi2.pwmWrite(self.SPEAKER, 0)
def initGPIO(): try: io.wiringPiSetupGpio() except: print "start IDLE with 'gksudo idle' from command line" os._exit(1) for pin in range(0, 4): io.pinMode(pinList[pin], 0) io.pullUpDnControl(pinList[pin], 2) # input enable pull up
def set_pin_as_output(pin): """Set the specified pin as an output. :param pin: index of pin in cm.hardware.gpio_pins :type pin: int """ if is_pin_pwm[pin]: wiringpi.softPwmCreate(cm.hardware.gpio_pins[pin], 0, _PWM_MAX) else: wiringpi.pinMode(cm.hardware.gpio_pins[pin], _GPIOASOUTPUT)
def __init__(self): threading.Thread.__init__(self) wp.pinMode(0, 1) self.timer = time.time() self.cycle_time = settings.safety_cycle_time self.safety_margin = settings.safety_margin self.watchdog_safe = True self.quit = False self.time_to_live = 0 self.reactivate()#Initially activate Watchdog self.reset_ttl()
def wiring(wp_id, wp_state): wiringpi.wiringPiSetup() if wp_id in WIRINGPI_list: wiringpi.pinMode(wp_id, 1) wiringpi.digitalWrite(wp_id, wp_state) message = Markup('GPIO <strong>' + str(wp_id) + '</strong> switched to : ' + str(wp_state)) flash(message, 'success') else: flash('Invalid WiringPi number', 'danger') return render_template('playground/index.html', **wiringData)
def __init__(self, pin=DEFAULT_PIN, calibration_file=None, smoothing=None, wiringpi_obj=None, zero_pin=None, **kwargs): super(PWMCalibrator, self).__init__() if not SOFTPWM_SUPPORT and ((pin != WIRINGPI_PWM_PIN) or zero_pin != None): raise Exception( "No soft PWM support (is wiringpi2 installed?). Only pin 1 may be used." ) self.pin = pin if wiringpi_obj is not None: self.wp = wiringpi_obj else: wiringpi.wiringPiSetup() # PWM: hardware or software? if (not SOFTPWM_SUPPORT) or (self.pin == WIRINGPI_PWM_PIN): wiringpi.pinMode(self.pin, wiringpi.GPIO.PWM_OUTPUT) self.pwm_write = wiringpi.pwmWrite self.pwm_max = PWM_MAX else: wiringpi.softPwmCreate(self.pin, 0, SOFT_PWM_MAX) self.pwm_write = wiringpi.softPwmWrite self.pwm_max = kwargs.get('soft_pwm_max', SOFT_PWM_MAX) # zero out any zero pins, as necessary # (this is used for bidirectional meters; by default the pi's pins # are in a high-impedence mode that will prevent adequate calibration) if zero_pin != None: if zero_pin == WIRINGPI_PWM_PIN: wiringpi.pinMode(zero_pin, wiringpi.GPIO.PWM_OUTPUT) wiringpi.pwmWrite(zero_pin, 0) else: wiringpi.softPwmCreate(zero_pin, 0, SOFT_PWM_MAX) wiringpi.softPwmWrite(zero_pin, 0) self.pwm_value = 0 self.calibration = [] if smoothing is True: self.smoothing = 0.005 else: self.smoothing = smoothing if calibration_file is not None: self.calibration_file = calibration_file else: self.calibration_file = DEFAULT_CALIBRATION_FILENAME
def init18b20(): GPIO.pinMode(DQ, OUT) GPIO.digitalWrite(DQ, H) GPIO.digitalWrite(DQ, L) GPIO.delayMicroseconds(480) # 480-960(us) GPIO.pinMode(DQ, IN) GPIO.delayMicroseconds(30) # 15-60(us) while True: if GPIO.digitalRead(DQ) == H: break GPIO.delayMicroseconds(150) # 60-240(us) GPIO.digitalWrite(DQ, H)
def initGPIO(): try : io.wiringPiSetupGpio() except : print"start IDLE with 'gksudo idle' from command line" os._exit(1) for pin in range (0,4): io.pinMode(compPins[pin],0) # mux pin to input io.pullUpDnControl(compPins[pin],2) # input enable pull up for pin in range (0,3): io.pinMode(ledPins[pin],1) # LED pin to output io.digitalWrite(ledPins[pin],0)
def __init__(self, clk, dio, brightness=7): self.clk = clk self.dio = dio if not 0 <= brightness <= 7: raise ValueError("Brightness out of range") self._brightness = brightness pinMode(self.clk, GPIO.OUTPUT) pinMode(self.dio, GPIO.OUTPUT) digitalWrite(self.clk, 0) digitalWrite(self.dio, 0)
def __init__(self, lock): threading.Thread.__init__(self) self.__lock = lock # SPI (MCP3008) self.__adc = MCP3008(SPI_const.CS0, 0, self.__lock) # Hardware PWM wipi.wiringPiSetupPhys() wipi.pinMode(12, 2) # TODO: have pin as parameter to __init__() self.__running = True
def initGPIO(): global pinReset, pinClock pinReset = 23 pinClock = 24 try: io.wiringPiSetupGpio() except: print "start IDLE with 'gksudo idle' from command line" os._exit(1) io.pinMode(pinReset, 1) io.pinMode(pinClock, 1) io.mcp3002Setup(70, 0)
def __init__(self): self.pins = [2, 7, 3] #GPIO self.ryb = [0, 0, 0] #Red Yellow Blue wiringpi2.wiringPiSetup() for x in self.pins: wiringpi2.pinMode(x, 1) wiringpi2.digitalWrite(x, 1) time.sleep(2.5) for x in self.pins: wiringpi2.digitalWrite(x, 0) time.sleep(0.5) self.ryb = [0, 0, 1]
def __init__(self): self.log = logging.getLogger(__name__) # Setup GPIO pins # This routine uses /sys/class/gpio for non-root access. # Attention: export all pins beforehand (done by launcher.sh at the moment) wiringpi2.wiringPiSetupSys() # Inputs for key, value in self.PINS.items(): self.log.debug('Setting up pin %d for "%s"', value, key) # Set input mode wiringpi2.pinMode(value, self.GPIO_INPUT) # Pull pin down to ground wiringpi2.pullUpDnControl(value, self.GPIO_PUD_DOWN)
def cleanup(): wiringpi.pwmWrite(LEFT_MOTOR_PWM, 0) wiringpi.pwmWrite(RIGHT_MOTOR_PWM, 0) wiringpi.pinMode(LEFT_MOTOR_PWM, 0) wiringpi.pinMode(RIGHT_MOTOR_PWM, 0) GPIO.output(LEFT_MOTOR_A, GPIO.LOW) GPIO.output(LEFT_MOTOR_B, GPIO.LOW) GPIO.output(RIGHT_MOTOR_A, GPIO.LOW) GPIO.output(RIGHT_MOTOR_B, GPIO.LOW) GPIO.setup(LEFT_MOTOR_A, GPIO.IN) GPIO.setup(LEFT_MOTOR_B, GPIO.IN) GPIO.setup(RIGHT_MOTOR_A, GPIO.IN) GPIO.setup(RIGHT_MOTOR_B, GPIO.IN)
def monotron(): # 音程をコントロール REF = 3.3 # 5.p or 3.3 w.wiringPiSetup() w.pinMode(0, 1) w.pinMode(1, 2) w.digitalWrite(0, 1) while 1: for i in [0, 300, 380, 460, 540, 640, 720, 1000]: w.pwmWrite(1, i) print(i) time.sleep(0.5) w.digitalWrite(0, 0)
def set_pin_as_input(pin): """Set the specified pin as an input. :param pin: index of pin in _GPIO_PINS :type pin: int """ if _EXPORT_PINS and is_a_raspberryPI: # set pin as input for use in export mode subprocess.check_call( [_GPIO_UTILITY_PATH, 'export', str(_GPIO_PINS[pin]), 'in']) else: wiringpi.pinMode(_GPIO_PINS[pin], _GPIOASINPUT)
def __init__(self, pin, lock): threading.Thread.__init__(self) self.__pin = pin self.__lock = lock # SPI (MCP3008) self.__adc = MCP3008(SPI_const.CS0, 0, self.__lock) # Hardware PWM wipi.wiringPiSetupPhys() wipi.pinMode(self.__pin, 2) self.__running = True
def __init__(self): # Setup pins wiringpi.pinMode(68, 1) # sets GPA0 to output wiringpi.pinMode(69, 1) # sets GPA1 to output wiringpi.pinMode(70, 1) # sets GPA2 to output wiringpi.pinMode(71, 1) # sets GPA3 to output wiringpi.pinMode(72, 1) # sets GPA4 to output wiringpi.digitalWrite(68, 1) wiringpi.digitalWrite(69, 1) wiringpi.digitalWrite(70, 1) wiringpi.digitalWrite(71, 1) wiringpi.digitalWrite(72, 1)
def __init__(self, startPin, startAction, stopPin, stopAction): wpi.wiringPiSetup() wpi.pinMode(startPin, wpi.GPIO.INPUT) wpi.pullUpDnControl(startPin, wpi.GPIO.PUD_UP) wpi.wiringPiISR(startPin, wpi.GPIO.INT_EDGE_FALLING, self.startTrigger) wpi.pinMode(stopPin, wpi.GPIO.INPUT) wpi.pullUpDnControl(stopPin, wpi.GPIO.PUD_UP) wpi.wiringPiISR(stopPin, wpi.GPIO.INT_EDGE_FALLING, self.stopTrigger) self.startAction = startAction self.stopAction = stopAction self.newEvent = False self.latestEvent = ''
def __init__(self): self.pin = 5 # 29 on PI2 rev B #init GPIO #wiringpi.wiringPiSetupGpio() already called by someone wiringpi.pinMode(self.pin, 1) # sets GPIO 24 to output wiringpi.digitalWrite(self.pin, 1) # sets port 24 to 0 (0V, off) #ROS init self.rate = rospy.Rate(10) # 10Hz self.subscriber = rospy.Subscriber("led_control_info", Int16, self.callback)
def __init__(self): SPI_data = 16 SPI_clock = 21 SPI_latch = 20 self.heat_relay = 12 wiringpi2.wiringPiSetup() self.thermocouple = thermocouple.thermocouple() self.thermocouple.setup(SPI_data, SPI_clock, SPI_latch) self.relay_state = 0 wiringpi2.pinMode(self.heat_relay,1) wiringpi2.digitalWrite(self.heat_relay, self.relay_state)
def __init__(self, pin): self.dtMin, self.dtMax, self.dtMed = 35, 120, 65 self.dt = self.dtMed self.pin = pin self.direction = '' wiringpi.wiringPiSetupGpio() wiringpi.pinMode(self.pin, 2) wiringpi.pwmSetMode(0) wiringpi.pwmSetClock(400) wiringpi.pwmSetRange(1024) try: wiringpi.pwmWrite(self.pin, 40) except Exception as e: print str(e)
def readByte(): data = 0 for i in range(8): GPIO.pinMode(DQ, OUT) GPIO.digitalWrite(DQ, L) GPIO.digitalWrite(DQ, H) GPIO.pinMode(DQ, IN) GPIO.delayMicroseconds(15) if GPIO.digitalRead(DQ) == H: data |= (1 << i) else: data &= ~(1 << i) GPIO.delayMicroseconds(30) return data
def init(): GPIO.setmode(GPIO.BCM) wiringpi.wiringPiSetupGpio() wiringpi.pinMode(LEFT_MOTOR_PWM, 2) wiringpi.pinMode(RIGHT_MOTOR_PWM, 2) wiringpi.pwmSetMode(0) wiringpi.pwmSetClock(CLK_DIVISOR) wiringpi.pwmSetRange(MAX_SPEED) wiringpi.pwmWrite(LEFT_MOTOR_PWM, 0) wiringpi.pwmWrite(RIGHT_MOTOR_PWM, 0) GPIO.setup(LEFT_MOTOR_A, GPIO.OUT) GPIO.setup(LEFT_MOTOR_B, GPIO.OUT) GPIO.setup(RIGHT_MOTOR_A, GPIO.OUT) GPIO.setup(RIGHT_MOTOR_B, GPIO.OUT)
def setSpeedBase(self, adv, rot): wpi.pinMode(self.leftt_wheel_pin, 1) wpi.pinMode(self.right_wheel_pin, 1) velLeft, velRight = self.computeRobotSpeed(adv,rot) for pin, speed in zip([self.left_wheel_pin, self.right_wheel_pin], [velLeft,velRight]): direction = 0 if (speed >= 0) else 1 wpi.digitalWrite(pin, direction) time.sleep(0.1) for id_duty, speed in zip(range(2), [self.left_wheel_pin, self.right_wheel_pin]): with open('/sys/devices/platform/pwm-ctrl/duty'+str(id_duty), 'w') as file_duty: file_duty.write(str(abs(speed)))
def RCTime(self,pin=11,wiring=True,short=False): duration=0 #not sure if the GPIO version of this translation works, #so keep using Wiringpi version if wiring==True: #initQTI() #make pin output wp.pinMode(pin,1) #set pin to high to discharge capacitor wp.digitalWrite(pin,1) #wait 1 ms time.sleep(0.001) #make pin Input wp.pinMode(pin,0) #turn off internal pullups #wp.digitalWrite(pin,0) wp.pullUpDnControl(pin,1) #print "here" if short == True: while wp.digitalRead(pin)==1 and duration < self.rightTail: #wait for the pin to go Low #print pin, wp.digitalRead(pin) #print 'not yet' duration+=1 else: while wp.digitalRead(pin)==1 and duration <self.cap: # while wp.digitalRead(pin)==1: #print "here" duration+=1 #print duration #wp.pinMode(pin,1) #wp.digitalWrite(pin,1) else: GPIO.setup(pin,GPIO.OUT) #set pin to high to discharge capacitor GPIO.output(pin,GPIO.LOW) #wait 1 ms time.sleep(0.1) #make pin Input GPIO.setup(pin,GPIO.IN) #GPIO.setup(pin,GPIO.IN,GPIO.PUD_DOWN) #turn off internal pullups while GPIO.input(pin)== GPIO.LOW: #wait for the pin to go Low #print GPIO.input(sensorIn) duration+=1 #print duration, pin return duration