python树莓派红外反射传感器
本文实例为大家分享了python树莓派红外反射传感器的程序,供大家参考,具体内容如下
1、工具
rpi3,微雪ARPI600,Infrared Reflective Sensor
2、基本原理
Infrared Reflective Sensor 输出数字和模拟信号
模拟信号通过ARPI600上的AD转换芯片TLC1543进行转换
TLC1543通信使用rpi的GPIO口,模拟SPI,进行模拟信号输入端口选择,和输出读取
程序通过读取DOUT判断与障碍物接近和远离
在接近障碍物时读取AD转换数值
3、连接实物
4、python程序(根据ARPI600提供程序修改)
#!/usr/bin/python # -*- coding:utf-8 -*- import RPi.GPIO as GPIO import time Clock = 16 Address = 20 DataOut = 21 DOUT = 17 def ADC_Read(channel): value = 0; for i in range(0,4): if((channel >> (3 - i)) & 0x01): GPIO.output(Address,GPIO.HIGH) else: GPIO.output(Address,GPIO.LOW) GPIO.output(Clock,GPIO.HIGH) GPIO.output(Clock,GPIO.LOW) for i in range(0,6): GPIO.output(Clock,GPIO.HIGH) GPIO.output(Clock,GPIO.LOW) time.sleep(0.001) for i in range(0,10): GPIO.output(Clock,GPIO.HIGH) value <<= 1 if(GPIO.input(DataOut)): value |= 0x01 GPIO.output(Clock,GPIO.LOW) return value GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(Clock,GPIO.OUT) GPIO.setup(Address,GPIO.OUT) GPIO.setup(DataOut,GPIO.IN,GPIO.PUD_UP) GPIO.setup(DOUT,GPIO.IN) lastdata = 2 try: while True: data = GPIO.input(DOUT) if lastdata and (lastdata == 1): continue if data == 0: print 'Near the Obstacles' print 'AD: %d ' % ADC_Read(6) if data == 1: print 'Far the Obstacles' lastdata = data time.sleep(0.1) except: GPIO.cleanup()
相关推荐
LeeHDsniper 2020-11-05
橄榄 2020-11-03
wanshiyingg 2020-09-29
andonliu 2020-09-03
嵌入式开发爱好者 2020-08-28
lu00kill 2020-08-17
tianyayi 2020-08-16
LIEVEZ 2020-08-09
ohhardtoname 2020-07-25
LeeHDsniper 2020-07-19
shenxiuwen 2020-07-16
wzxxtt0 2020-06-25
mattraynor 2020-06-25
咏月东南 2020-06-10
wangz 2020-06-03
wanxuncpx 2020-06-01
tianyayi 2020-05-18
wanxuncpx 2020-05-15
mattraynor 2020-05-12
wzxxtt0 2020-05-12
LIEVEZ 2020-05-04
mattraynor 2020-05-01
LIEVEZ 2020-05-01
LIEVEZ 2020-05-01
LowisLucifer 2020-04-23
OathKeeper 2020-04-22
zcabcd 2020-04-18
wanxuncpx 2020-04-16
returnspace 2020-04-16
mattraynor 2020-04-14
tianyayi 2020-03-28
clamzxf 2020-03-28
Summer的小屋 2020-03-26
lu00kill 2020-03-17
yuancr 2020-03-04
wzxxtt0 2020-02-21
xinhao 2020-02-20
LIEVEZ 2020-02-17
wzxxtt0 2020-02-15
zhufu 2020-02-10