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 selftest(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: if debuglevel: print "Self test ok" failure=0 else: if debuglevel: print "Failed" failure=1 PWM.stop("P8_19") time.sleep(0.2) PWM.cleanup() GPIO.cleanup() #Debug output if debuglevel: print baseline print selftest return {'failure':failure, 'baseline':baseline ,'selftest':selftest }
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 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 avoid_(): def readfile_coordinates(): global line f = open('temp.txt', 'r') temp = f.readlines(line) f.close() latitude = temp.split("")[0] longitude = temp.split("")[1] while True: try: while True: readfile_coordinates(line) scheduler() arbiter() except KeyboardInterrupt: # pressing ctrl C stops operation and cleans up PWM.stop(left_wheel) PWM.stop(right_wheel) PWM.cleanup() GPIO.cleanup() ADC.cleanup()
def __init__(self, node_name_override = 'read_encoders'): # rospy.init_node(node_name_override) self.nodename = rospy.get_name() rospy.loginfo("Node starting with name %s", self.nodename) self.rate = float(rospy.get_param("rate", 10)) # Pines de los encoders self.cs1 = "P9_31" self.cs2 = "P9_29" self.do = "P9_25" self.clk = "P9_23" # GPIO.cleanup() GPIO.setup(self.cs1, GPIO.OUT) GPIO.setup(self.cs2, GPIO.OUT) GPIO.setup(self.do, GPIO.IN) GPIO.setup(self.clk, GPIO.OUT) # self.closeComm(self.cs1) self.closeComm(self.cs2) # self.e1val = 0 self.e2val = 0 # self.e1Pub = rospy.Publisher("e1", Int16) self.e2Pub = rospy.Publisher("e2", Int16)
def Blink(numTimes,speed): GPIO.output("P8_11", GPIO.LOW) for i in range(0,numTimes):## Run loop numTimes GPIO.output("P8_7", GPIO.HIGH) print "Iteration " + str(i+1)## Print current loop GPIO.output("P8_9", GPIO.HIGH) time.sleep(speed)## Wait GPIO.output("P8_9", GPIO.LOW) time.sleep(speed)## Wait for i in range(0,numTimes):## Run loop numTimes GPIO.output("P8_7", GPIO.LOW) print "Iteration " + str(i+1)## Print current loop GPIO.output("P8_9", GPIO.HIGH) time.sleep(speed)## Wait GPIO.output("P8_9", GPIO.LOW) time.sleep(speed)## Wait for i in range(0,numTimes):## Run loop numTimes GPIO.output("P8_7", GPIO.LOW) print "Iteration " + str(i+1)## Print current loop GPIO.output("P8_9", GPIO.HIGH) time.sleep(speed)## Wait GPIO.output("P8_9", GPIO.LOW) time.sleep(speed)## Wait print "Done" ## When loop is complete, print "Done" GPIO.output("P8_9", GPIO.LOW) GPIO.cleanup()
def zonkers_init_ios(): """Set the I/O pins to inputs on the beagle bone, so that the zonker board can control them.""" # The input bits 7 -> 0 are on P8 pins 18 -> 11. # The output bits 7 -> 0 are on P8 pins 25 -> 32. GPIO.setup("P8_18", GPIO.IN) GPIO.setup("P8_17", GPIO.IN) GPIO.setup("P8_16", GPIO.IN) GPIO.setup("P8_15", GPIO.IN) GPIO.setup("P8_14", GPIO.IN) GPIO.setup("P8_13", GPIO.IN) GPIO.setup("P8_12", GPIO.IN) GPIO.setup("P8_11", GPIO.IN) GPIO.setup("P8_25", GPIO.IN) GPIO.setup("P8_26", GPIO.IN) GPIO.setup("P8_27", GPIO.IN) GPIO.setup("P8_28", GPIO.IN) GPIO.setup("P8_29", GPIO.IN) GPIO.setup("P8_30", GPIO.IN) GPIO.setup("P8_31", GPIO.IN) GPIO.setup("P8_32", GPIO.IN) GPIO.cleanup()
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 cleanup(): try: os.unlink(PID_FILE) except: pass for led in LEDS: GPIO.output(led[PIN], 0) GPIO.cleanup()
def cleanup(cls): PWM.stop(PWMA) PWM.stop(PWMB) PWM.cleanup() GPIO.cleanup() GPIO.output(STBY, GPIO.LOW)
def cleanup(self): print "Clean up" self.setPWM([0, 0]) self.robotSocket.close() GPIO.cleanup() PWM.cleanup() # tictocPrint() self.writeBufferToFile()
def test_input(self): GPIO.setup("P8_10", GPIO.IN) #returned as an int type input_value = GPIO.input("P8_10") #value read from the file will have a \n new line value = open('/sys/class/gpio/gpio68/value').read() assert int(value) == input_value GPIO.cleanup()
def set_all_leds(self, state): test_leds = { "USR0": "heartbeat", \ "USR1": "mmc0", \ "USR2": "cpu0", \ "USR3": "mmc1" } for led, name in test_leds.iteritems(): self.set_brightness(state, led, name) GPIO.cleanup()
def __init__(self): if os.path.exists(self.transmitFIFO) : os.unlink(self.transmitFIFO) os.mkfifo(self.transmitFIFO) os.chmod(self.transmitFIFO, 0666) GPIO.cleanup() GPIO.setup(self.pin_out, GPIO.OUT) GPIO.output(self.pin_out,GPIO.LOW)
def finish(): print "Finished" ADC.power_off() ADC.stop() analogue_IO.disable() # disable TX GPIO.cleanup() # free GPIO ports exit(0)
def cleanup(signum, frame): global exitStatus print "\nRollE, signing out." exitStatus = True sleep(0.2) GPIO.cleanup() PWM.cleanup() exit()
def __init__(self): #initialize TRIG and ECHO self.TRIG = "P8_7" self.ECHO = "P8_9" GPIO.cleanup() GPIO.setup(self.TRIG, GPIO.OUT) GPIO.setup(self.ECHO, GPIO.IN) GPIO.output(self.TRIG, GPIO.LOW) self.ready = False self.pulse_start = 0.0
def test_setup_input_name(self): # WARNING: TIMERn syntax is not working on newer kernels # such as 4.4. Originally discovered while testing # Pull Request #152. See issue #156 for details. #GPIO.setup("TIMER6", GPIO.IN) GPIO.setup("P8_10", 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 cleanup(self): sys.stdout.write("Shutting down...") self.setPWM([0, 0]) self.robotSocket.close() GPIO.cleanup() PWM.cleanup() if DEBUG: # tictocPrint() self.writeBuffersToFile() sys.stdout.write("Done\n")
def adafruitlib(): b = [] startTime = time.time() for i in range (10000): st = time.time() state = GPIO.input("P8_12") b.append(time.time() - st) meanb = sum(b)/len(b) print time.time() - startTime, ' mean Adafruit_BBIO', 1/meanb GPIO.cleanup()
def cleanup(self): """ Clean up before shutting down. """ sys.stdout.write("Shutting down...") self.set_pwm([0, 0]) self.robotSocket.close() GPIO.cleanup() PWM.cleanup() if DEBUG: pass # tictocPrint() # self.writeBuffersToFile() sys.stdout.write("Done\n")
def blink(): GPIO.setup('P8_10', GPIO.OUT) GPIO.setup('P8_11', GPIO.OUT) while True: GPIO.output('P8_10', GPIO.LOW) GPIO.output('P8_11', GPIO.HIGH) time.sleep(1) GPIO.output('P8_10', GPIO.HIGH) GPIO.output('P8_11', GPIO.LOW) time.sleep(1) print GPIO.cleanup()
def main(): """ @brief Main """ GPIO.setup("P8_10", GPIO.OUT) while True: GPIO.output("P8_10", GPIO.HIGH) time.sleep(0.5) GPIO.output("P8_10", GPIO.LOW) time.sleep(0.5) GPIO.cleanup()
def main(): t = time.time() lastTrigger = time.time() while True: if not GPIO.input(pin): currTime = time.time() print "Low detected : ",currTime,"Difference ",(currTime - lastTrigger) if (currTime - lastTrigger) > 5: print "Touch that event file here" writeTime() time.sleep(2) lastTrigger = currTime GPIO.cleanup()
def linea_l(x1,y1,x2,y2,disp,a1,b1): dis1=((x1-x2)**2+(y1-y2)**2)**0.5 cv2.line(img,(x1,y1),(x2,y2),(75,50,100),5) if dis1 > disp: disp=dis1 a=((x1+x2)/2) b=((y1+y2)/2) cv2.circle(img,(a,b),5,(45,0,255),1) if (disp<537*480.0/3000.0): print 'Distancia',disp print ("No es vaca") if (disp>=537*480.0/3000.0) and (disp<=543*480.0/3000.0): if a>a1 and b>b1: a1=a b1=b print 'Punto medio',a1,b1 anglew= np.arctan(y2-y1/x2-x1) print 'Angulo',anglew print 'Distancia',disp print ("Solo hay una vaca") GPIO.output("P8_10",GPIO.HIGH) time.sleep(0.5) GPIO.cleanup() if (disp>543*480.0/3000.0): print 'Distancia',disp print ("Hay mas de una vaca") xa=x1+543*480/300*np.cos(np.arctan(y2-y1/x2-x1)) yb=y1+543*480/300*np.sin(np.arctan(y2-y1/x2-x1)) a1=(xa+x1)/2 b1=(yb+y1)/2 print 'Punto medio',a1,b1 return [disp,a1,b1]
def main(): global status status = -1 # up = 1, down = 0 motor = pinConfig() motor.setPin() if GPIO.input(motor.upperSW): # if on upperSW move down print "@Upper switch..." status = motor.moveDOWN() elif GPIO.input(motor.lowerSW): # if on lowerSW move up print "@Lower switch..." status = motor.moveUP() else: print "@Middle..." status = motor.moveUP() # print "GPIO event enabled" GPIO.add_event_detect(motor.upperSW, GPIO.RISING, bouncetime=1000) GPIO.add_event_detect(motor.lowerSW, GPIO.RISING, bouncetime=1000) try: while True: # print status if status == 1: if GPIO.input(motor.upperSW) and GPIO.event_detected(motor.upperSW): print "@Upper switch..." motor.moveStop() print "... ... Sleep ZZZzz" time.sleep(pinConfig.restTIme) status = motor.moveDOWN() elif status == 0: if GPIO.input(motor.lowerSW) and GPIO.event_detected(motor.lowerSW): print "@Lower switch..." motor.moveStop() print "... ... Sleeping ZZZzz" time.sleep(pinConfig.restTIme) status = motor.moveUP() except KeyboardInterrupt: motor.moveStop() GPIO.cleanup()
def main(): print('OpenSprinkler Beagle has started...') GPIO.cleanup() # setup GPIO pins to interface with shift register GPIO.setup(pin_sr_clk, GPIO.OUT) GPIO.setup(pin_sr_noe, GPIO.OUT) disableShiftRegisterOutput() GPIO.setup(pin_sr_dat, GPIO.OUT) GPIO.setup(pin_sr_lat, GPIO.OUT) shiftOut(station_bits) enableShiftRegisterOutput() while True: try: runOSBo() except: pass time.sleep(60) # check every 60 seconds
def __init__(self): self.Tdes=36.25 self.periodo=10.0 self.maxTemp = 36.4 #Emu #37.8 #Gen self.minTemp = 36.1 #Emu #37.6 #Gen self.maxHumi = 29 #Emu #55 #Gen self.minHumi = 26 #Emu #50 #Gen self.stop=1 self.st1='Bombilla ceramica Off' self.st2='Ventiladores Off' self.st3='Humidificador Off' self.SHT15 = BB_SHT15_lib.BB_SHT15() time.sleep(0.5) self.motorDC = motor.motor() time.sleep(0.5) self.iTemp = self.SHT15.temperature() time.sleep(0.5) self.iHumi = self.SHT15.humidity() LOW = 0 HIGH = 1 self.motorDC.preexecute() # Starting PWM for the EN of the motors self.motorDC.motorSpeed(39) GPIO.setup("P8_22", GPIO.OUT) # Motor giro Derecha GPIO.cleanup() GPIO.setup("P8_23", GPIO.OUT) # Motor giro Izquierda GPIO.cleanup() GPIO.setup("P8_26", GPIO.OUT) # RELE TEMP GPIO.cleanup() GPIO.setup("P8_27", GPIO.OUT) # RELE HUMI GPIO.cleanup() GPIO.setup("P8_28", GPIO.OUT) # RELE HUMI GPIO.cleanup() self.lastiTemp=0 self.estado=0 time.sleep(0.5)
def disable(parameters = None): """ Name: disable Desc: This disables the Main Power for the board. Params: parameters (list) None """ global EN for key in PINS.keys(): if key != "MAINPW_EN": GPIO.output(PINS[key], GPIO.LOW) EN = False time.sleep(1) GPIO.output(PINS["MAINPW_EN"], GPIO.LOW) GPIO.cleanup() with open("EN", "wb") as ENFile: ENFile.write("0") print "Main Power Disabled"
def __destroy__(self): self.logger.info("GPIODevice - stopping") GPIO.output(self.pinName, self.gpioOff) time.sleep(0.250) GPIO.cleanup(self.pinName)
global count2 PermFloR2 = (count2 * 0.53 / deltaT2) #print deltaT #print flowrate + 'mL/min' print 'Time(sec)=\t\t%s' % (deltaT) # Time in seconds print 'Time(sec)=\t\t%s' % (deltaT2) print 'F1(mL/min)=\t\t%s' % (PermFloR) # Flow rate in mL/min print 'F1(mL/min)=\t\t%s' % (PermFloR2) # Flow rate in mL/min print time.sleep(0.05) #flow calibration[Test1: 100 drops, 5.28 mL; Test2: 100 drops, 5.3 mL; #Test3: 100 drops, 5.32 mL] #Average vol per drop: 5.3 ml/100 drops = .053 mL/drop try: while True: if GPIO.event_detected(PIPin): countPulse1() timecount() countPulse2() else: time.sleep(0.01) except KeyboardInterrupt: GPIO.cleanup() #elapsed_time = time.time() #deltaT = float(elapsed_time) - float(start_time1)
def close(self): GPIO.cleanup()
def signal_handler(sig, frame): if gpio: gpio.cleanup() exit(0)
def quit(signum, frame): device.ungrab() GPIO.cleanup() print("Bye") exit()
def release_pump(self): GPIO.cleanup()
def __stop(self): GPIO.cleanup() self.serialPort.close()
def cleanup(self): GPIO.cleanup()
def cleanup_gpio(event): """Stuff to do before stopping.""" GPIO.cleanup()
gpio.output(ctrl_pin, gpio.HIGH) elif not (nominal_state and secs < opened_secs) and current_state: rospy.loginfo("Closing the solenoid") current_state = False if gpio: gpio.output(ctrl_pin, gpio.LOW) if __name__ == "__main__": nominal_state = False current_state = False if gpio: gpio.cleanup() rospy.init_node("solenoid_driver", log_level=rospy.DEBUG) name = rospy.get_name() if not gpio: rospy.logwarn( "Failed to import Adafruit_BBIO.gpio, running in desktop mode") try: ctrl_pin = rospy.get_param(name + "/pin") opened_secs = rospy.get_param(name + "/opened") closed_secs = rospy.get_param(name + "/closed") except: rospy.logerr("Failed to retrieve configuration from rosparam server.") rospy.signal_shutdown("Unavailable config.")
def shutdown(): all_low() GPIO.cleanup()
def teardown_module(module): GPIO.cleanup()
motorA.stop() def OFF_callback(channel): if motorA.isRunning: print 'Stopping the motor...' motorA.stop() else: print 'Motor is not currently running...' # The GPIO.add_event_detect() line below set things up so that # when a rising edge is detected, regardless of whatever # else is happening in the program, the function 'my_callback' will be run GPIO.add_event_detect(CWswitch, GPIO.RISING, callback=CW_ON_callback, bouncetime=200) GPIO.add_event_detect(CCWswitch, GPIO.RISING, callback=CCW_ON_callback, bouncetime=200) try: print 'Waiting for button pushes...' while True: time.sleep(0.01) pass except KeyboardInterrupt: GPIO.cleanup() # clean up GPIO on CTRL+C exit GPIO.cleanup() # clean up GPIO on normal exit
def shutdown(self): GPIO.cleanup() PWM.stop(self._pin_en) PWM.cleanup() print "Motor driver shutdown complete"
def clean(): GPIO.cleanup()
def signal_handler(signal, frame): GPIO.cleanup() sys.exit(0)