2014-10-07 87 views
0

那裏。 我打算讓腳本通過使用開關來運行,以打開和關閉工作循環。Python RuntimeError GPIO

'開關引腳'是引腳13.有了這個輸入,已經有'GPIO.setup(13,GPIO,IN)'的設置,我可以打開循環。 但是當我想要在循環內獲得輸入時,我會得到一個runtimerror(下面的代碼和回溯)。

while True: 
    d = datalogger(devmode) 
    d.set_sheet() 


    GPIO.setmode(GPIO.BOARD) 
    GPIO.setup(23, GPIO.IN) 
    GPIO.setup(3, GPIO.IN) 
    GPIO.setup(13, GPIO.IN) 
    GPIO.setup(22, GPIO.IN) 
    GPIO.setup(7, GPIO.OUT) 
    GPIO.output(7, GPIO.LOW) 
    print 'Ready !' 
    break 

while 1: 
    if GPIO.input(13) == False: 
    d.runner(True) 
    break 
    else: 
     pass 


while d.running: 

    GPIO.setup(13, GPIO.IN) 
    GPIO.add_event_detect(23, GPIO.FALLING, callback=d.hall_sens) 

    d.time_lauf() 
    d.abrieb_a() 
    d.read_temp() 
    d.clear_temp_log() 
    d.write_sheet() 
    d.print_data() 
    d.loop_break(looptime) 

    s = GPIO.input(13) 

    if s == 1: 
    d.runner(False) 
    else: 
    pass 

    GPIO.remove_event_detect(23) 

Traceback (most recent call last): 
file "file.py", line 260, in <module> 
s = GPIO.input(13) 
RuntimeError: You must setup() the GPIO channel first 

,但我沒有

感謝您的幫助

回答

0

使用BCM的編號,而不是板的編號,然後再宣佈你的腳。