树莓派基础实验5:激光传感器实验 | 您所在的位置:网站首页 › 树莓派电路图4b解析 › 树莓派基础实验5:激光传感器实验 |
一、介绍
由于其良好的指向性和能量集中性,激光广泛用于医疗军事等领域,顾名思义,激光发射模块是一种可以发射激光的模块。 二、组件★Raspberry Pi 3主板*1 ★树莓派电源*1 ★40P软排线*1 ★激光传感器模块*1 ★面包板*1 ★跳线若干 三、实验原理 四、实验步骤第1步:连接电路。这里激光模块的实物与模块原理图的端口名称不一致,我们按照实物的端口名称来连接。 树莓派T型转接板激光模块GPIO 0GPIO 17SGNDGND-第2步:编程。 #!/usr/bin/env python ##################################################### # # DO NOT WATCH THE LASER DERECTELY IN THE EYE! # ##################################################### import RPi.GPIO as GPIO import time LedPin = 11 # pin11 def setup(): GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location GPIO.setup(LedPin, GPIO.OUT) # Set LedPin's mode is output GPIO.output(LedPin, GPIO.LOW) # Set LedPin LOW(0V) to off led def loop(): while True: print '...Laser off' GPIO.output(LedPin, GPIO.LOW) # led off time.sleep(0.5) print 'Laser on...' GPIO.output(LedPin, GPIO.HIGH) # led on time.sleep(0.5) def destroy(): GPIO.output(LedPin, GPIO.LOW)) # led off GPIO.cleanup() # Release resource if __name__ == '__main__': # Program start from here setup() try: loop() except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed. destroy()有的激光模块端口设置不一样,如下图: VCC端口接5V,SIG端口接GPIO 17,这样GPIO 17信号端是低电平时led on,GPIO 17是高电平时led off,与前面的情况相反。 |
CopyRight 2018-2019 实验室设备网 版权所有 |