本文整理汇总了Python中RPi.GPIO.cleanup方法的典型用法代码示例。如果您正苦于以下问题:Python GPIO.cleanup方法的具体用法?Python GPIO.cleanup怎么用?Python GPIO.cleanup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RPi.GPIO
的用法示例。
在下文中一共展示了GPIO.cleanup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_spi
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import cleanup [as 别名]
def get_spi(self):
spi = None
try:
spi = spidev.SpiDev()
bus = 0
device = 0
spi.open(bus, device)
spi.max_speed_hz = 10000000
spi.mode = 0b00
spi.lsbfirst = False
except Exception as e:
print(e)
GPIO.cleanup()
if spi:
spi.close()
spi = None
return spi
# https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md
# https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=19489
示例2: get_spi
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import cleanup [as 别名]
def get_spi(self):
spi = None
try:
spi = spidev.SpiDev()
bus = 0
device = 0
spi.open(bus, device)
spi.max_speed_hz = 10000000
spi.mode = 0b00
spi.lsbfirst = False
except Exception as e:
print(e)
GPIO.cleanup()
if spi:
spi.close()
spi = None
return spi
# https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md
# https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=19489
示例3: saks_gpio_init
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import cleanup [as 别名]
def saks_gpio_init(self):
#print 'saks_gpio_init'
GPIO.setwarnings(False)
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
GPIO.setup(PINS.BUZZER, GPIO.OUT)
GPIO.output(PINS.BUZZER, GPIO.HIGH)
for p in [PINS.IC_TM1637_DI, PINS.IC_TM1637_CLK, PINS.IC_74HC595_DS, PINS.IC_74HC595_SHCP, PINS.IC_74HC595_STCP]:
GPIO.setup(p, GPIO.OUT)
GPIO.output(p, GPIO.LOW)
for p in [PINS.BUZZER, PINS.TACT_RIGHT, PINS.TACT_LEFT, PINS.DIP_SWITCH_1, PINS.DIP_SWITCH_2]:
GPIO.setup(p, GPIO.OUT)
GPIO.output(p, GPIO.HIGH)
for p in [PINS.TACT_RIGHT, PINS.TACT_LEFT, PINS.DIP_SWITCH_1, PINS.DIP_SWITCH_2]:
GPIO.setup(p, GPIO.IN, pull_up_down = GPIO.PUD_UP)
示例4: init_process
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import cleanup [as 别名]
def init_process():
print " "
print "MSG - [S100, T110 CO2 Sensor Driver on RASPI2, Please check log file : ", LOG_PATH
print "MSG - now starting to read SERIAL PORT"
print " "
# HW setup, GPIO
GPIO.setwarnings(False)
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
GPIO.setup(23, GPIO.OUT)
GPIO.setup(24, GPIO.OUT)
GPIO.setup(25, GPIO.OUT)
logger.info(' *start* GPIO all set, trying to open serial port, SW starting ')
rledAllOn()
######################################################################
# START Here. Main
######################################################################
# set logger file
示例5: main
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import cleanup [as 别名]
def main():
try:
while True:
for led in LEDS:
for idx, pin in enumerate(led):
if pin == O:
GPIO.setup(PINS[idx], GPIO.IN)
else:
GPIO.setup(PINS[idx], GPIO.OUT)
GPIO.output(PINS[idx], pin)
time.sleep(.1)
except KeyboardInterrupt:
pass
finally:
GPIO.cleanup()
示例6: main
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import cleanup [as 别名]
def main():
global pulses
## We're using BCM Mode
GPIO.setmode(GPIO.BCM)
## Setup coin interrupt channel
GPIO.setup(6, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# GPIO.setup(PIN_COIN_INTERRUPT,GPIO.IN)
GPIO.add_event_detect(6, GPIO.FALLING, callback=coinEventHandler)
while True:
time.sleep(0.5)
if (time.time() - lastImpulse > 0.5) and (pulses > 0):
if pulses == 1:
print("Coin 1")
pulses = 0
GPIO.cleanup()
# handle the coin event
示例7: user_shutdown
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import cleanup [as 别名]
def user_shutdown(channel):
global safe_mode
shutdown_delay = 10 # seconds
# in Safe Mode, wait 2 mins before actually shutting down
if(safe_mode):
cmd = "sudo wall 'System shutting down in 2 minutes - SAFE MODE'"
os.system(cmd)
time.sleep(120)
cmd = "sudo wall 'System shutting down in %d seconds'" % shutdown_delay
os.system(cmd)
time.sleep(shutdown_delay)
# Log message is added to /var/log/messages
os.system("sudo logger -t 'pi_power' '** User initiated shut down **'")
GPIO.cleanup()
os.system("sudo shutdown now")
# Shutdown system because of low battery
示例8: low_battery_shutdown
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import cleanup [as 别名]
def low_battery_shutdown():
global safe_mode
shutdown_delay = 30 # seconds
# in Safe Mode, wait 2 mins before actually shutting down
if(safe_mode):
cmd = "sudo wall 'System shutting down in 2 minutes - SAFE MODE'"
os.system(cmd)
time.sleep(120)
cmd = "sudo wall 'System shutting down in %d seconds'" % shutdown_delay
os.system(cmd)
time.sleep(shutdown_delay)
# Log message is added to /var/log/messages
os.system("sudo logger -t 'pi_power' '** Low Battery - shutting down now **'")
GPIO.cleanup()
os.system("sudo shutdown now")
# MAIN -----------------------
示例9: simple_on_of
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import cleanup [as 别名]
def simple_on_of(debug, port, on_t):
if debug:
set_debug()
fan_on = turn_port_in(port)
try:
while True:
temperature = get_cpu_temp()
if temperature >= on_t:
if not fan_on:
logging.debug("Temperature {0} CPU fan on.".format(temperature))
fan_on = turn_port_out(port)
else:
if fan_on:
logging.debug("Temperature {0} CPU fan off.".format(temperature))
fan_on = turn_port_in(port)
sleep(10)
except Exception:
logging.exception("Error occurs while tune fan status:")
GPIO.cleanup()
示例10: tearDown
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import cleanup [as 别名]
def tearDown(self):
GPIO.cleanup()
#def test_software_spi_initialize(self):
#"""Checks to see if the sensor can initialize on the software SPI interface.
#Will fail if it cannot find the MAX31856 library or any dependencies.
#Test only checks to see that the sensor can be initialized in Software, does not check the
#hardware connection.
#"""
#_logger.debug('test_software_SPI_initialize()')
## Raspberry Pi software SPI configuration.
#software_spi = {"clk": 25, "cs": 8, "do": 9, "di": 10}
#sensor = MAX31856(software_spi=software_spi)
#if sensor:
#self.assertTrue(True)
#else:
#self.assertTrue(False)
示例11: main
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import cleanup [as 别名]
def main():
try:
gpioSetup()
with SC.serPort(serName=SERNAME) as mySerialPort:
mySerialPort.send("\r\n")
mySerialPort.send(" GPIO Serial Control\r\n")
mySerialPort.send(" -------------------\r\n")
mySerialPort.send(" CMD PIN STATE "+
"[GPIO Pin# ON]\r\n")
while running==True:
print ("Waiting for command...")
mySerialPort.send(">>")
cmd = mySerialPort.receive(terminate="\r\n")
response=handleCmd(cmd)
mySerialPort.send(response)
mySerialPort.send(" Finished!\r\n")
except OSError:
print ("Check selected port is valid: %s" %serName)
except KeyboardInterrupt:
print ("Finished")
finally:
GPIO.cleanup()
开发者ID:PacktPublishing,项目名称:Raspberry-Pi-3-Cookbook-for-Python-Programmers-Third-Edition,代码行数:24,代码来源:serialMenu.py
示例12: cleanup
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import cleanup [as 别名]
def cleanup(self):
if not self.corrupted:
try:
GPIO.cleanup(self.gpio_pin)
except ValueError as ve: # GPIO pin number is not in valid range
logging.error("Buzzer: The given pin number is not in a valid range: %s" % ve)
else:
logging.debug("Buzzer: Cleaned up buzzer action")
示例13: cleanup_sensor
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import cleanup [as 别名]
def cleanup_sensor(self):
try:
GPIO.remove_event_detect(self.gpio)
GPIO.cleanup(self.gpio)
except ValueError as ve: # GPIO pin number is not in valid range
logging.error("GPIOSensor: The given pin number is not in a valid range: %s" % ve)
logging.debug("GPIOSensor: Removed sensor at pin %s!" % self.gpio)
# callback for alarm
示例14: cleanup
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import cleanup [as 别名]
def cleanup(self):
"""Stop updating clock, turn off display, and cleanup GPIO"""
self.StopClock()
self.Clear()
IO.cleanup()
示例15: cleanup
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import cleanup [as 别名]
def cleanup(self):
print "Cleanup"
self.light.off()
self.redled.off()
self.yellowled.off()
self.motor.stop()
GPIO.cleanup()