Up テスト 作成: 2021-03-25
更新: 2021-03-27




テストに使用するプログラム:
#!/usr/bin/env python import RPi.GPIO as GPIO from time import sleep TransmitterPin = 18 ReceiverPin = 16 delayTime = 1 def setup(): # Set the GPIO pins as numbering GPIO.setmode(GPIO.BOARD) # Set the ReceiverPin's mode is input, and (Detected→) ON→ LOW GPIO.setup(ReceiverPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set the TransmitterPin's mode is output GPIO.setup(TransmitterPin, GPIO.OUT) # Set the TransmitterPin high(+3.3V) GPIO.output(TransmitterPin, GPIO.HIGH) def loop(): while True: if GPIO.input(ReceiverPin's) == GPIO.HIGH: print 'No obstacle' sleep(delayTime) else: print 'Obstacle detected' sleep(delayTime) def destroy(): # Release resource GPIO.cleanup() # The Program will start from here if __name__ == '__main__': setup() try: loop() # When control c is pressed child program destroy() will be executed. except KeyboardInterrupt: destroy()


    $ vi ky_032.py

    $ chmod +x ky_032.py

    $ ./ky_032.py
      white No obstacle No obstacle No obstacle No obstacle No obstacle No obstacle ^C
    Obstacle detected にならない。
    IR Transmitter (LED) が壊れているのかも。

#!/usr/bin/env python import RPi.GPIO as GPIO TransmitterPin = 18 ReceiverPin = 16 def setup(): # Set the GPIO pins as numbering GPIO.setmode(GPIO.BOARD) # Set the ReceiverPin's mode is input, and (Detected→) ON→ LOW GPIO.setup(ReceiverPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set the TransmitterPin's mode is output GPIO.setup(TransmitterPin, GPIO.OUT) # Set the TransmitterPin high(+3.3V) GPIO.output(TransmitterPin, GPIO.HIGH) def destroy(): # Release resource GPIO.cleanup() def loop(): while True: if GPIO.input(ReceiverPin) == GPIO.LOW: destroy() print 'Obstacle detected' break # The Program will start from here if __name__ == '__main__': setup() try: loop() # When control c is pressed child program destroy() will be executed. except KeyboardInterrupt: destroy()


    $ vi ky_032_a.py

    $ chmod +x ky_032_a.py

    $ ./ky_032_a.py