def GPIOhumidWriter(num): GPIO.setup("P8_18", GPIO.OUT) if num == 1: # open window GPIO.output("P8_18", GPIO.HIGH) else: # close window GPIO.output("P8_18", GPIO.LOW)
def run(self): port = "5559" context = zmq.Context() socket = context.socket(zmq.PAIR) socket.bind("tcp://*:%s" % port) GPIO.setup("P8_11", GPIO.OUT) GPIO.output("P8_11", GPIO.HIGH) w1="/sys/bus/w1/devices/28-000001cf4ced/w1_slave" while True: try: raw = open(w1, "r").read() temp = float(raw.split("t=")[-1])/1000 if temp > 32.0: GPIO.output("P8_11", GPIO.HIGH) relay = "OFF" if temp < 29.0: GPIO.output("P8_11", GPIO.LOW) relay = "ON" msg = "Temperature: " + str(temp) + " degrees. Relay state: "+ relay + "." except Exception: msg = logging.error("Can't read temperature! Check sensor connection.") socket.send(msg) time.sleep(1)
def test_set_pin(self,logicHigh=1,pin="P8_14"): ''' this is a test function to set a pin on the beaglebone to high or low ''' GPIO.setup(pin, GPIO.OUT) if logicHigh: GPIO.output(pin, GPIO.HIGH) else: GPIO.output(pin, GPIO.LOW)
def main(): GPIO.setup(LED_PIN, GPIO.OUT) GPIO.output(LED_PIN, GPIO.LOW) radio = rfm69.RFM69() radio.initialize(FREQUENCY,NODEID,NETWORKID) radio.readAllRegs(); if IS_RFM69HW: radio.setHighPower(IS_RFM69HW) #uncomment only for RFM69HW! radio.setEncryptionKey(ENCRYPTKEY) print "Transmitting at {} Mhz...".format(433 if FREQUENCY==rfm69.RF69_433MHZ else (868 if FREQUENCY==rfm69.RF69_868MHZ else 915)) lastPeriod = 0 sendSize = 0 while True: #check for any received packets if (radio.receiveDone()): print "[{}] {} [RX_RSSI: {}]".format(radio.SENDERID, radio.DATA, radio.RSSI) if (radio.ACKRequested()): radio.sendACK() print " - ACK sent" Blink(LED_PIN, .003) currPeriod = radio._millis()/TRANSMITPERIOD if (currPeriod != lastPeriod): lastPeriod = currPeriod s = "Sending[{}]: {} ".format(sendSize, payload[:sendSize]) if (radio.sendWithRetry(GATEWAYID, payload, sendSize, retries=RETRIES, retryWaitTime=ACK_TIME)): s += "ok!" else: s += "nothing..." print s sendSize = (sendSize + 1) % 31 Blink(LED_PIN, .003)
def handshake(): if not GPIO.input(slaveSelect): # print "slave low" GPIO.output(MOSI, GPIO.LOW) GPIO.output(spiClock, GPIO.LOW) else: # print "wait for slave low" GPIO.wait_for_edge(slaveSelect, GPIO.FALLING) GPIO.output(MOSI, GPIO.LOW) GPIO.output(spiClock, GPIO.LOW) # print "START" GPIO.wait_for_edge(slaveSelect, GPIO.RISING) GPIO.output(MOSI, GPIO.HIGH) GPIO.output(spiClock, GPIO.HIGH) # print "A" GPIO.wait_for_edge(slaveSelect, GPIO.FALLING) GPIO.output(MOSI, GPIO.LOW) GPIO.output(spiClock, GPIO.LOW) # print "B" GPIO.wait_for_edge(slaveSelect, GPIO.RISING) GPIO.setup(slaveSelect, GPIO.OUT) GPIO.output(slaveSelect, GPIO.LOW) # print "C" time.sleep(pause) GPIO.output(spiClock, GPIO.HIGH) # print "END" time.sleep(pause) GPIO.output(spiClock, GPIO.LOW)
def __init__(self, pin, trigger_value, mode=True, init_value=gpio.LOW, debug=False): self.trigger = trigger_value self.mode = mode self.debug = debug self.pin = pin gpio.setup(self.pin, gpio.OUT, initial = init_value) self.state = 0
def __init__(self , note2buttons , actuatorno , isinv , chan): #initialize con lista de notas (en notacion anglosajona), numero de puchabotones necesarios, si se usa logica negada y el canal MIDI a escuchar self.actuatorno = actuatorno self.isinv = isinv self.chan=chan #Not implemented self.mid2gpio = self.__convert2Gpios(note2buttons) #obtener los gpios necesarios a encender o apagar cuando llega un msg de noteOn o noteOff for i in range(0 , actuatorno): GPIO.setup(self.bbb_gpios[i], GPIO.OUT)
def __init__(self, pin, name=None): self._pin = pin if name: self._name = name else: self._name = self._pin GPIO.setup(self._pin, GPIO.IN)
def ignite(debuglevel): threshold=340 #150mv threshold threshigh=1024 #450mv upper threshold ADC.setup() ADC.read_raw("AIN4") #Flush this baseline=ADC.read_raw("AIN4") GPIO.setup("P8_14",GPIO.OUT) #This pin fires the ignition GPIO.output("P8_14",GPIO.LOW) PWM.start("P8_19",15,49500) #works best with an 11 turn primary time.sleep(0.05) #50ms Settling time for the analogue front end ADC.read_raw("AIN4") selftest=ADC.read_raw("AIN4") if selftest>threshold and selftest<threshigh and baseline<128: GPIO.output("P8_14",GPIO.HIGH) if debuglevel: print "Igniting" time.sleep(2) #plenty of time for ignition failure=0 else: if debuglevel: print "Failed" failure=1 GPIO.output("P8_14",GPIO.LOW) PWM.stop("P8_19") PWM.cleanup() #Debug output if debuglevel: print baseline print selftest return {'failure':failure, 'baseline':baseline ,'selftest':selftest }
def __init__(self): self.inUse = None self.prevHookState = 'Low' self.hook1 = "P8_19" # Output1 - Wht self.hook2 = "P8_26" # Output2 - Red self.hook3 = "P8_18" # Input - Blk self.ringer1 = "P8_9" self.ringer2 = "P8_10" print 'Pins Set: True' gpio.setup(self.hook1, gpio.OUT) gpio.setup(self.hook2, gpio.OUT) gpio.setup(self.hook3, gpio.IN) gpio.output(self.hook1, gpio.HIGH) gpio.output(self.hook2, gpio.HIGH) gpio.setup(self.ringer1, gpio.OUT) gpio.output(self.ringer1, gpio.LOW) gpio.setup(self.ringer2, gpio.OUT) gpio.output(self.ringer2, gpio.LOW) print 'GPIO Setup: True' self.operator = textToSpeech.TextToSpeech() self.dialer = linphone.Linphone() self.userInput = speechToText.SpeechToText() print 'Libraries Assigned: True' self.run()
def setup_input(pin, pull_mode): """Setup a GPIO as input.""" # pylint: disable=import-error,undefined-variable import Adafruit_BBIO.GPIO as GPIO GPIO.setup(pin, GPIO.IN, # noqa: F821 GPIO.PUD_DOWN if pull_mode == 'DOWN' # noqa: F821 else GPIO.PUD_UP) # noqa: F821
def tx_start(self): if not self.ptt_pin: return GPIO.setup(self.ptt_pin, GPIO.OUT) GPIO.output(self.ptt_pin, GPIO.HIGH) time.sleep(self.ptt_high)
def setup_input(pin, pull_mode): """Set up a GPIO as input.""" # pylint: disable=import-error from Adafruit_BBIO import GPIO GPIO.setup(pin, GPIO.IN, GPIO.PUD_DOWN if pull_mode == 'DOWN' else GPIO.PUD_UP)
def initFluidMotor(self): self.fluidLeft = "P8_16" self.fluidRight = "P8_18" GPIO.setup(self.fluidLeft, GPIO.OUT) GPIO.setup(self.fluidRight, GPIO.OUT) GPIO.output(self.fluidLeft, GPIO.LOW) GPIO.output(self.fluidRight, GPIO.LOW)
def __init__(self, pins, magnets, name, numPoints=10, timeout=1): super(self.__class__, self).__init__(pins, numPoints, name) GPIO.setup(pins[0], GPIO.IN) self.magnets = magnets self.lastEdge = None self.currentEdge = time.time() self.timeout = timeout
def _setup_gpio(self): """Initialize GPIO pins""" GPIO.setup(self.dir1Pin[LEFT], GPIO.OUT) GPIO.setup(self.dir2Pin[LEFT], GPIO.OUT) GPIO.setup(self.dir1Pin[RIGHT], GPIO.OUT) GPIO.setup(self.dir2Pin[RIGHT], GPIO.OUT) GPIO.setup(self.led, GPIO.OUT)
def __init__(self, baseIP, robotIP): # Initialize GPIO pins GPIO.setup(self.dir1Pin[LEFT], GPIO.OUT) GPIO.setup(self.dir2Pin[LEFT], GPIO.OUT) GPIO.setup(self.dir1Pin[RIGHT], GPIO.OUT) GPIO.setup(self.dir2Pin[RIGHT], GPIO.OUT) GPIO.setup(self.ledPin, GPIO.OUT) # Initialize PWM pins: PWM.start(channel, duty, freq=2000, polarity=0) PWM.start(self.pwmPin[LEFT], 0) PWM.start(self.pwmPin[RIGHT], 0) # Set motor speed to 0 self.setPWM([0, 0]) # Initialize ADC ADC.setup() self.encoderRead = encoderRead(self.encoderPin) # Set IP addresses self.baseIP = baseIP self.robotIP = robotIP self.robotSocket.bind((self.robotIP, self.port))
def init_LEDs(): PWM.start(RED, 100) # red PWM.start(GREEN, 100) # green PWM.start(BLUE, 100) # blue GPIO.setup(DOORPORT, GPIO.OUT) # LockPort GPIO.output(DOORPORT, GPIO.LOW) # Default low: locked
def initFluidMotor(self): self.fluidLeft = "P8_16" self.fluidRight = "P8_18" GPIO.setup(self.fluidLeft, GPIO.OUT) # Configure the motor pins as output GPIO.setup(self.fluidRight, GPIO.OUT) GPIO.output(self.fluidLeft, GPIO.LOW) # Disable the motor initially GPIO.output(self.fluidRight, GPIO.LOW)
def GPIOlightWriter(num): GPIO.setup("P8_12", GPIO.OUT) if num == 1: GPIO.output("P8_12", GPIO.HIGH) else: GPIO.output("P8_12", GPIO.LOW)
def __init__(self): pines = ["P8_8","P8_10","P8_12","P8_14","P8_16", "P8_18"] for i in pines: gpio.setup(i, gpio.OUT) gpio.output(i, gpio.LOW) print i, " inicializado" self.reset(True)
def main(): print "Setting up GPIO" # Variables GPIO.setup("P9_11", GPIO.IN) GPIO.add_event_detect("P9_11", GPIO.BOTH) GPIO.setup("P9_15", GPIO.OUT) global running try: while True: if GPIO.event_detected("P9_11"): if GPIO.input("P9_11"): print "Hazards on" running = True t1 = threading.Thread( target = blink_leds, args = ( "P9_15", ) ) t1.setDaemon( True ) t1.start() else: running = False print "Hazards off" GPIO.output("P9_15", GPIO.LOW) except KeyboardInterrupt: GPIO.cleanup() print "Ending program"
def digitalGpioExamples(): # Set up pin P8_10 as an output GPIO.setup("P8_10", GPIO.OUT) # or GPIO.setup("GPIO0_26", GPIO.OUT) referring to the actual pin name instead of header_number GPIO.output("P8_10", GPIO.HIGH) GPIO.cleanup() # Set up pin P8_14 as an input GPIO.setup("P8_14", GPIO.IN) # Check to see if there is a signal or not and report on the status if GPIO.input("P8_14"): print("HIGH") else: print("LOW") # If you want edge detection instead, look no further (THIS IS BLOCKING, so be aware) GPIO.wait_for_edge("P8_14", GPIO.RISING) # Non blocking version GPIO.add_event_detect("P9_12", GPIO.FALLING) #your amazing code here #detect wherever: if GPIO.event_detected("P9_12"): print "event detected!"
def setup(): global currentButtonState, lastDownTime, isRecording, audioInput global messageQ, clientMap, oscIn, oscOut, oscThread messageQ = PriorityQueue() clientMap = {} ## setup osc client oscOut = OSCClient() ## setup osc receiver oscIn = OSCServer((OSC_IN_ADDRESS, OSC_IN_PORT)) oscIn.addMsgHandler('default', _oscHandler) oscThread = Thread(target = oscIn.serve_forever) oscThread.start() print "osc in ready" ## setup gpio GPIO.setup(SWITCH_PIN, GPIO.IN) GPIO.setup(LED_PIN, GPIO.OUT) GPIO.output(LED_PIN, GPIO.LOW) currentButtonState = GPIO.input(SWITCH_PIN) lastDownTime = 0 isRecording = False ## setup audio audioInput = None try: audioInput = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NORMAL, "default:Headset") audioInput.setchannels(1) audioInput.setrate(44100) audioInput.setformat(alsaaudio.PCM_FORMAT_S16_LE) audioInput.setperiodsize(256) except: print "couldn't start audio device" audioInput = None
def __init__(self, heater_pin, temp_cs, top_pin=None,booster_pin=None, fan_pin = None): self.heater_pin = heater_pin self.fan_pin= fan_pin self.top_pin = top_pin self.booster_pin = booster_pin self.thermocouple = MAX31855(SPI1,temp_cs) #self.thermocouple = Client('/dev/ttyUSB0') self.pid = PID(PID_KP, PID_KI, PID_KD) #pinMode(heater_pin, OUTPUT) GPIO.setup(heater_pin, GPIO.OUT) #if (fan_pin): pinMode(fan_pin, OUTPUT) if (fan_pin): GPIO.setup(fan_pin, GPIO.OUT) else: self.fan_state = "disabled" self.heatOff() self.fanOff() addToCleanup(self.stop) self.current_phase = '' self.current_step = 0 self.realtime_data = [] self.error = '' self.abort = False self.solder_type = LEADED
def xband_pir(pin, cycles, outData, outTime, name): cycles = cycles * 350 print name, 'started' GPIO.setup(pin[0], GPIO.IN) # out pin GPIO.setup(pin[1], GPIO.OUT) # LED pin data = [] rowTime = [] time_ = [] i = 0 while i < cycles: if GPIO.input(pin[0]) : GPIO.output(pin[1], GPIO.HIGH) #print "motion detected" + name flag = 1 else: GPIO.output(pin[1], GPIO.LOW) flag = 0 data.append(flag) rowTime.append(time.time()) time_.append(rowTime[i] - rowTime[0]) i += 1 print name, 'finished' outData.put(data) outTime.put(time_)
def __init__(self, pwm_name, dir_a, dir_b, eqep): # Initialize the thread base super(controller, self).__init__() # Create stop event object self.stop_event = threading.Event() self.stop_confirm = threading.Event() # Store parameters self.pwm = pwm_name self.dir_a = dir_a self.dir_b = dir_b # Create a PID controller self.pid = PID(0.01, 0.01, 0.0, -100.0, 100.0, 0.0) # Load the eQEP interface self.eqep = eQEP(eqep, eQEP.MODE_RELATIVE) self.eqep.set_period(10000000) # Setup the GPIO gpio.setup(self.dir_a, gpio.OUT) gpio.setup(self.dir_b, gpio.OUT) gpio.output(self.dir_a, gpio.LOW) gpio.output(self.dir_b, gpio.LOW) # Setup the PWM pwm.start(self.pwm, 100.0)
def main(): print "Setting up GPIO" accUp = "P8_14" accDown = "P8_15" # Variables GPIO.setup( accUp, GPIO.IN ) GPIO.setup( accDown, GPIO.IN ) # GPIO.add_event_detect( accDown, GPIO.BOTH ) # GPIO.setup( "P9_15", GPIO.OUT ) global running speed = 50 try: print "IN" while True: t.sleep(.1) if GPIO.input( accUp ): speed = speed + 5 print "Speed: %s" % speed elif GPIO.input( accDown ): if (speed > 0): speed = speed - 5 print "Speed: %s" % speed except KeyboardInterrupt: GPIO.cleanup() print "Ending program"
def motor_setup(dir1_pin, dir2_pin, pwm_pin): """ Sets up context for operating a motor. """ # Initialize GPIO pins GPIO.setup(dir1_pin, GPIO.OUT) GPIO.setup(dir2_pin, GPIO.OUT) # Initialize PWM pins: PWM.start(channel, duty, freq=2000, polarity=0) PWM.start(pwm_pin, 0) def run_motor(speed): if speed > 100: speed = 100 elif speed < -100: speed = -100 if speed > 0: GPIO.output(dir1_pin, GPIO.LOW) GPIO.output(dir2_pin, GPIO.HIGH) PWM.set_duty_cycle(pwm_pin, abs(speed)) elif speed < 0: GPIO.output(dir1_pin, GPIO.HIGH) GPIO.output(dir2_pin, GPIO.LOW) PWM.set_duty_cycle(pwm_pin, abs(speed)) else: GPIO.output(dir1_pin, GPIO.LOW) GPIO.output(dir2_pin, GPIO.LOW) PWM.set_duty_cycle(pwm_pin, 0) yield run_motor GPIO.cleanup() PWM.cleanup()
def __init__(self, arm, axes): self.arm = arm self.polaraxes = [ PolarAxis(memp, pwm) for memp, pwm in axes ] self.updatedutycount = 0 self.t0 = time.time() if self.arm: GPIO.setup(self.arm, GPIO.OUT) GPIO.output(self.arm, GPIO.LOW) for memp, pwm in axes: if pwm: print("starting", pwm) PWM.start(pwm, 50, 100000, 1) if self.arm: GPIO.output(self.arm, GPIO.HIGH) def settostationary(armaxes): arm, axes = armaxes if arm: GPIO.output(arm, GPIO.LOW) for memp, pwm in axes: print("set stationary", pwm, arm) if pwm: PWM.start(pwm, 50, 100000, 1) atexit.register(settostationary, (arm, axes)) # values kept here by closure self.readeqeps()
def test_setup_cleanup(self): GPIO.setup("P8_10", GPIO.OUT) assert os.path.exists('/sys/class/gpio/gpio68') GPIO.cleanup() assert not os.path.exists('/sys/class/gpio/gpio68')
def test_setup_input_name(self): GPIO.setup("TIMER6", GPIO.IN) assert os.path.exists('/sys/class/gpio/gpio68') direction = open('/sys/class/gpio/gpio68/direction').read() assert direction == 'in\n' GPIO.cleanup()
def test_setup_output_key(self): GPIO.setup("P8_10", GPIO.OUT) assert os.path.exists('/sys/class/gpio/gpio68') direction = open('/sys/class/gpio/gpio68/direction').read() assert direction == 'out\n' GPIO.cleanup()
def test_setup_input_pull_down(self): GPIO.setup("P8_10", GPIO.IN, pull_up_down=GPIO.PUD_DOWN) assert os.path.exists('/sys/class/gpio/gpio68') direction = open('/sys/class/gpio/gpio68/direction').read() assert direction == 'in\n' GPIO.cleanup()
def test_setup_failed_type_error(self): with pytest.raises(TypeError): GPIO.setup("P8_10", "WEIRD") GPIO.cleanup()
#!/usr/bin/env python3 import time import Adafruit_BBIO.GPIO as GPIO ON = "GP0_6" # GP0 for buttons OFF = "GP0_5" # Set the GPIO pins: GPIO.setup(ON, GPIO.OUT) GPIO.setup(OFF, GPIO.OUT) GPIO.output(ON, 0) GPIO.output(OFF, 0) print("Clicking on button") GPIO.output(ON, 1) time.sleep(1) GPIO.output(ON, 0) print("Clicking off button") GPIO.output(OFF, 1) time.sleep(1) GPIO.output(OFF, 0)
import cv2 #################################################### # MOTOR INITIALIZATION # #################################################### stepPin1 = "P8_7" dirPin1 = "P8_8" stepPin2 = "P8_9" dirPin2 = "P8_10" stepPin3 = "P8_11" dirPin3 = "P8_12" stepPin4 = "P8_15" dirPin4 = "P8_16" GPIO.setup(stepPin1, GPIO.OUT) GPIO.setup(dirPin1, GPIO.OUT) GPIO.setup(stepPin2, GPIO.OUT) GPIO.setup(dirPin2, GPIO.OUT) GPIO.setup(stepPin3, GPIO.OUT) GPIO.setup(dirPin3, GPIO.OUT) GPIO.setup(stepPin4, GPIO.OUT) GPIO.setup(dirPin4, GPIO.OUT) steps_per_rev_big = 200 steps_per_rev_small = 200 #################################################### # MOTOR CONTROL FUNCTIONS # #################################################### #R1, if direction is positive, motor moves clockwise
# Toggle gpio pin with Python import Adafruit_BBIO.GPIO as GPIO import time gpio = raw_input("Enter the GPIO pin (ex. PX_XX): ") period = input ("Enter the period (in seconds): ") half_period = period/2 GPIO.setup(str(gpio), GPIO.OUT) while True: GPIO.output(str(gpio), GPIO.HIGH) time.sleep(half_period) GPIO.output(str(gpio), GPIO.LOW) time.sleep(half_period)
def test_setup_three_digit_gpio(self): GPIO.setup("P9_31", GPIO.OUT) assert os.path.exists('/sys/class/gpio/gpio110') GPIO.cleanup() assert not os.path.exists('/sys/class/gpio/gpio110')
def test_setup_failed_value_error(self): with pytest.raises(ValueError): GPIO.setup("P8_10", 3) GPIO.cleanup()
#!/usr/bin/python3 """ photodiodetest.py - test script for the firestarter board The laser is turned on The polygon is spun at a rate of 1000 Hz for 5 seconds The photodiode is measured for three seconds, if high within these three seconds test is succesfull, otherwise unsuccesfull. The laser is turned off. """ from ctypes import c_uint32 import Adafruit_BBIO.GPIO as GPIO from uio.ti.icss import Icss GPIO.setup("P9_23", GPIO.OUT) # enable polygon motor GPIO.output("P9_23", GPIO.LOW) pruss = Icss('/dev/uio/pruss/module') pruss.initialize() pruss.core0.load('./photodiodetest.bin') pruss.core0.run() while not pruss.core0.halted: pass byte0 = pruss.core0.dram.map(c_uint32) return_value = int(byte0.value) if return_value == 0: print("Test successfull") elif return_value == 1: print("Photo diode detector connected but no signal")
yellow_1 = "P9_12" green_1 = "P9_13" red_2 = "P9_14" yellow_2 = "P9_15" green_2 = "P9_16" red_3 = "P8_7" yellow_3 = "P8_8" green_3 = "P8_9" red_4 = "P8_10" yellow_4 = "P8_11" green_4 = "P8_12" GPIO.setup(red_1, GPIO.OUT) GPIO.setup(yellow_1, GPIO.OUT) GPIO.setup(green_1, GPIO.OUT) GPIO.setup(red_2, GPIO.OUT) GPIO.setup(yellow_2, GPIO.OUT) GPIO.setup(green_2, GPIO.OUT) GPIO.setup(red_3, GPIO.OUT) GPIO.setup(yellow_3, GPIO.OUT) GPIO.setup(green_3, GPIO.OUT) GPIO.setup(red_4, GPIO.OUT) GPIO.setup(yellow_4, GPIO.OUT) GPIO.setup(green_4, GPIO.OUT)
# Get Serial Numbers from Redis DB for channel in list(BSMP_ID_SERIALNUMBER_CHANNEL.keys()): if not redis_db.hexists("DetectorSerialNumber", BSMP_ID_SERIALNUMBER_CHANNEL[channel]): redis_db.hset("DetectorSerialNumber", BSMP_ID_SERIALNUMBER_CHANNEL[channel], 0) # Variable for counting values [LNLS1, LNLS2, LNLS3, LNLS4, LNLS5, LNLS6, Bergoz1, Bergoz2] global Counting Counting = [0] * 8 # Inhibit pins - Bergoz Inhibit = {"A1": "P9_14", "B1": "P9_16", "A2": "P9_13", "B2": "P9_15"} for pin in Inhibit: GPIO.setup(Inhibit[pin], GPIO.OUT) GPIO.output(Inhibit[pin], GPIO.LOW) # Error Codes - bsmp COMMAND_OK = 0xE0 ERROR_READ_ONLY = 0xE6 # Datetime string def time_string(): return datetime.datetime.now().strftime( "%d/%m/%Y %H:%M:%S.%f")[:-4] + " - " def includeChecksum(list_values) -> list: counter = 0
import Adafruit_BBIO.GPIO as GPIO import Adafruit_BBIO.PWM as PWM while 1: GPIO.setup("P8_13", GPIO.OUT) GPIO.output("P8_13", GPIO.HIGH) GPIO.cleanup() PWM.start("P8_13", 50) PWM.stop("P8_13") PWM.cleanup()
#uint8_t adc_pins[] = {A0,A1,A2,A3, A6,A7,A8,A9,A10,A11,A13,A14, A18,A19,A20}; adc_linpot_i = [11, 12, 0, 1, 2] adc_strain_i = [7, 6, 5, 4, 3] adc_jointpot_i = [13, 14, 10, 9, 8] index = 0 adc_linpot = [0, 0, 0, 0, 0] adc_strain = [0, 0, 0, 0, 0] adc_jointpot = [0, 0, 0, 0, 0] adc_values = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] i2c = Adafruit_I2C(9) #communication with Teensy at address 9 #Motor DIR GPIO.setup("P8_26", GPIO.OUT) GPIO.setup("P8_14", GPIO.OUT) GPIO.setup("P8_15", GPIO.OUT) GPIO.setup("P8_16", GPIO.OUT) GPIO.setup("P8_17", GPIO.OUT) #Motor PWM PWM.start("P9_31", 0.0) PWM.set_frequency("P9_31", 1000.0) PWM.start("P9_14", 0.0) PWM.set_frequency("P9_14", 1000.0) PWM.start("P8_19", 0.0) PWM.set_frequency("P8_19", 1000.0) PWM.start("P9_42", 0.0) PWM.set_frequency("P9_42", 1000.0) PWM.start("P9_28", 0.0) PWM.set_frequency("P9_28", 1000.0)
rospy.signal_shutdown("Unavailable pin config.") exit() if not gpio: rospy.logwarn( "Failed to import Adafruit_BBIO.gpio, running in desktop mode") rospy.loginfo("Starting DC motor driver on pins " + cw_pin + ", " + ccw_pin) success = False max_attempts = 10 for i in range(max_attempts): try: if gpio: gpio.setup(cw_pin, gpio.OUT) gpio.setup(ccw_pin, gpio.OUT) success = True except: sleep = random.randint(1, 20) rospy.logwarn(str(i) + ": Failed to configure. Waiting for " + \ str(sleep) + " seconds before reattempt.") rospy.sleep(sleep) if success: break if not success: rospy.logerr("Failed to configure after " + \ str(max_attempts) + " attempts.") exit()
import Adafruit_BBIO.GPIO as GPIO ng = "P9_11" nr = "P9_12" eg = "P9_17" er = "P9_18" sg = "P9_23" sr = "P9_24" wg = "P9_27" wr = "P9_26" import time all = [ng, nr, sg, sr, eg, er, wg, wr] for i in range(0, 8): GPIO.setup(all[i], GPIO.OUT) def ledon(pin): GPIO.output(pin, GPIO.HIGH) return def ledoff(pin): GPIO.output(pin, GPIO.LOW) return def northgreen(): print("north green") ledon(ng) ledon(er) ledon(wr)
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------- """ import Adafruit_BBIO.GPIO as GPIO import time GPIO.setup("USR%d" % 3, GPIO.OUT) while True: GPIO.output("USR%d" % 3, GPIO.HIGH) time.sleep(0.2) GPIO.output("USR%d" % 3, GPIO.LOW) time.sleep(0.2)
cred = credentials.Certificate("serviceAccountKey.json") firebase_admin.initialize_app(cred) db = firestore.client() #might need to make document link dynamic status_ref = db.collection(u'CoffeeMakers').document(u'n55uJF7D79BprQ6bgaiD') brew = "P9_12" on = GPIO.HIGH off = GPIO.LOW # Setting up GPIO to turn coffee pot on and off GPIO.setup(brew, GPIO.OUT) GPIO.setup(brew, GPIO.OUT, pull_up_down=GPIO.PUD_DOWN) #Setting up date and time information now = datetime.now() #New Brew Time input from user usr = datetime(2019,11,12,20,3) # Set by the website eventually GPIO.output(brew, off) # try: # status = status_ref.get() # print(format(status.to_dict()[u'isBrewing'])) # except google.cloud.exception.NotFound:
#!/usr/bin/env python3 import Adafruit_BBIO.GPIO as GPIO import time input="GP1_3" keepGoing=True # Set the GPIO pins: GPIO.setup(input, GPIO.IN) def updateLED(channel,): global keepGoing keepGoing=False print("Solving") print("Running...") GPIO.add_event_detect(input, GPIO.BOTH, callback=updateLED) try: while keepGoing: continue except KeyboardInterrupt: print("Cleaning Up") GPIO.cleanup()
#Douglas Wise #Sep 18, 2017 import Adafruit_BBIO.GPIO as GPIO import time import smbus #button assignments buttonL = "GP0_3" buttonR = "GP0_4" buttonD = "GP0_5" buttonU = "GP0_6" clear = "PAUSE" #Button/input Setup GPIO.setup(buttonL, GPIO.IN) GPIO.setup(buttonR, GPIO.IN) GPIO.setup(buttonD, GPIO.IN) GPIO.setup(buttonU, GPIO.IN) GPIO.setup(clear, GPIO.IN) bus = smbus.SMBus(1) # Use i2c bus 1 matrix = 0x70 # Use address 0x70 delay = 1 # Delay between images in s bus.write_byte_data(matrix, 0x21, 0) # Start oscillator (p10) bus.write_byte_data(matrix, 0x81, 0) # Disp on, blink off (p11) bus.write_byte_data(matrix, 0xe7, 0) # Full brightness (page 15)
import Adafruit_BBIO.GPIO as GPIO import Adafruit_BBIO.PWM as PWM import time GPIO.setup("P9_11", GPIO.OUT) GPIO.setup("P9_14", GPIO.OUT) GPIO.setup("P9_12", GPIO.IN) print("Program starting...") GPIO.output("P9_14", GPIO.HIGH) while (True): #print("PIR sensor is reading: ", GPIO.input("P9_12")) if (GPIO.input("P9_12")): GPIO.output("P9_11", GPIO.HIGH) else: GPIO.output("P9_11", GPIO.LOW) time.sleep(1) GPIO.cleanup()
from time import sleep from sys import exit #general needed values CUTTER_PIN = "P9_12" TRX_DEVICE = "/dev/ttyO1" POWER_ON_ALT = 79 #altitude in meters of power on CHUTE_DEPLOY = 330 #altitude to deploy main chute at MIN_ALT = 800 #target minimum altitude before coming back down #setup the gps and transmitter uart ports UART.setup("UART1") UART.setup("UART2") #initialize the cutter pin, it is triggered on a high signal GPIO.setup(CUTTER_PIN, GPIO.OUT) GPIO.output(CUTTER_PIN, GPIO.LOW) #setup gyro and altimeter alt = BMP180.BMP180(POWER_ON_ALT) #motion = LSM9DS0.LSM9DS0() gyro = LSM9DS0.LSM9DS0_GYRO( LSM9DS0.LSM9DS0_GYRODR_95HZ | LSM9DS0.LSM9DS0_GYRO_CUTOFF_1, LSM9DS0.LSM9DS0_GYROSCALE_2000DPS) accel = LSM9DS0.LSM9DS0_ACCEL() #xbee initialization xbee = serial.Serial('/dev/ttyO1', 19200) xbee.write("payload system started\n")
def __setupGPIO(self, gpio, direction): try: GPIO.setup(gpio, direction) except: raise
import Adafruit_BBIO.GPIO as GPIO from time import sleep redLED = "P8_8" greenLED = "P8_10" GPIO.setup(redLED, GPIO.OUT) GPIO.setup(greenLED, GPIO.OUT) delay = input("Please enter the time between each blink in seconds: ") freq = input("Please enter the number of times you want the LED's to blink: ") for i in range(0, freq): GPIO.output(redLED, GPIO.HIGH) GPIO.output(greenLED, GPIO.HIGH) sleep(delay) GPIO.output(redLED, GPIO.LOW) GPIO.output(greenLED, GPIO.LOW) sleep(delay) #Clean up all the GPIO pins status GPIO.cleanup()
#!/usr/bin/env python # import RPi.GPIO as GPIO import Adafruit_BBIO.GPIO as GPIO import time # GPIO.setmode(GPIO.BCM) input_A = 'P9_41' input_B = 'P9_42' GPIO.setup(input_A, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(input_B, GPIO.IN, pull_up_down=GPIO.PUD_UP) old_a = True old_b = True def get_encoder_turn(): # return -1, 0, or +1 global old_a, old_b result = 0 new_a = GPIO.input(input_A) new_b = GPIO.input(input_B) if new_a != old_a or new_b != old_b : if old_a == 0 and new_a == 1 : result = (old_b * 2 - 1) elif old_b == 0 and new_b == 1 : result = -(old_a * 2 - 1) old_a, old_b = new_a, new_b time.sleep(0.001) return result
import Adafruit_BBIO.GPIO as GPIO import Adafruit_BBIO.ADC as ADC import decimal, time a="P8_8" b="P8_10" c="P8_12" d="P8_14" GPIO.setup("P8_8",GPIO.OUT) GPIO.setup("P8_10",GPIO.OUT) GPIO.setup("P8_12",GPIO.OUT) GPIO.setup("P8_14",GPIO.OUT) dt=1*10**-3 vueltas=1 #numero de vueltas pasos=8 #numero de pasos por vuelta hold=1 #espera entre pasos #Define function for making coil on and off def coilOn(pin): GPIO.output(pin, GPIO.HIGH) return() def coilOff(pin): GPIO.output(pin, GPIO.LOW) return() def alloff(): for i in range(8,15,2): #GPIO.setup("P8_%d",GPIO.OUT)
moves the x-motor for a given amount of steps and stepspeed """ from uio.ti.icss import Icss import ctypes import Adafruit_BBIO.GPIO as GPIO # INPUT XSTEPSPERMM = 76.2 STEPSPEED = round(1 * XSTEPSPERMM) STEPS = round(1 * XSTEPSPERMM) DIRECTION = False # false is in direction home x_direction_pin = "P9_42" enable_pin = "P9_12" GPIO.setup(enable_pin, GPIO.OUT) GPIO.setup(x_direction_pin, GPIO.OUT) if DIRECTION: GPIO.output(x_direction_pin, GPIO.HIGH) else: GPIO.output(x_direction_pin, GPIO.LOW) GPIO.output(enable_pin, GPIO.LOW) # DERIVED CPU_SPEED = 200E6 INST_PER_LOOP = 2 HALF_PERIOD_STEP = CPU_SPEED / (2 * STEPSPEED * INST_PER_LOOP)
def _setup(self, pin): GPIO.setup(pin, GPIO.OUT) GPIO.output(pin, GPIO.HIGH)
#!/usr/bin/env python3 # From: https://github.com/blynkkk/lib-python import blynklib import os import Adafruit_BBIO.GPIO as GPIO LED = 'P9_14' GPIO.setup(LED, GPIO.OUT) GPIO.output(LED, 1) BLYNK_AUTH = os.getenv('BLYNK_AUTH') # Initialize Blynk blynk = blynklib.Blynk(BLYNK_AUTH) # Register Virtual Pins @blynk.handle_event('write V*') def my_write_handler(pin, value): print('Current V{} value: {}'.format(pin, value)) @blynk.handle_event('write V0') def my_write_handler(pin, value): print('Current V{} value: {}'.format(pin, value[0])) GPIO.output(LED, int(value[0])) # @blynk.handle_event('write V0') # def my_write_handler2(pin, value): # # this widget will show some time in seconds..