无法使用Raspberry Pi向后旋转直流电机

时间:2018-09-11 12:24:48

标签: python-3.x raspberry-pi3 gpio

我正在尝试使用Raspberry Pi 3和Pi Camera的访客监控系统。在此,我使用了以下组件

  • Raspberry Pi
  • Pi相机
  • 按钮
  • 蜂鸣器
  • 带IC的直流电动机
  • LED

我按照以下教程进行操作 https://circuitdigest.com/microcontroller-projects/visitor-monitoring-with-raspberry-pi-and-pi-camera

但是我修改了上面的程序。我使用Adafruit Char LCD库显示消息。我的Python程序如下:

it.firstName

我的所有组件都工作正常。问题是,当我叫import RPi.GPIO as gpio import picamera import time from Adafruit_CharLCD import Adafruit_CharLCD # instantiate lcd and specify pins lcd = Adafruit_CharLCD(rs=26, en=19, d4=13, d5=6, d6=5, d7=11, cols=16, lines=2) m11=17 m12=27 led=21 buz=16 button=20 #lcd BCM pin no RS =26 EN =19 D4 =13 D5 =6 D6 =5 D7 =11 HIGH=1 LOW=0 gpio.setwarnings(False) gpio.setmode(gpio.BCM) gpio.setup(RS, gpio.OUT) gpio.setup(EN, gpio.OUT) gpio.setup(D4, gpio.OUT) gpio.setup(D5, gpio.OUT) gpio.setup(D6, gpio.OUT) gpio.setup(D7, gpio.OUT) gpio.setup(led, gpio.OUT) gpio.setup(buz, gpio.OUT) gpio.setup(m11, gpio.OUT) gpio.setup(m12, gpio.OUT) gpio.setup(button, gpio.IN, pull_up_down=gpio.PUD_UP) #gpio.setup(button, gpio.IN) gpio.output(led , 0) gpio.output(buz , 0) gpio.output(m11 , 0) gpio.output(m12 , 0) data="" def capture_image(): lcd.clear() lcd.message('Please Wait...') data= time.strftime("%d_%b_%Y\%H:%M:%S") camera.start_preview() time.sleep(5) print( data) camera.capture('/home/pi/Desktop/Visitors/%s.jpg'%data) camera.stop_preview() lcd.clear() lcd.message('Image Captured\n successfully') time.sleep(2) def gate(): lcd.clear() lcd.message(" Welcome ") gpio.output(m11, 1) gpio.output(m12, 0) time.sleep(1.5) gpio.output(m11, 0) gpio.output(m12, 0) time.sleep(3) gpio.output(m11, 0) gpio.output(m12, 1) time.sleep(1.5) gpio.output(m11, 0) gpio.output(m12, 0) lcd.clear() lcd.message(" Thank You ") time.sleep(2) lcd.clear() # display text on LCD display \n = new line lcd.message('MSD Gurukul \n Welcomes You') time.sleep(2) lcd.clear() lcd.message('Visitor Monitor\nSystem using RPi') time.sleep(3) lcd.clear() camera = picamera.PiCamera() camera.rotation=180 camera.awb_mode= 'auto' camera.brightness=55 lcd.clear() lcd.message(" Please Press \n Button") time.sleep(2) try: while 1: d= time.strftime("%d %b %Y") t= time.strftime("%H:%M:%S") lcd.clear() lcd.message("Time: %s"%t) lcd.message("\nDate:%s"%d) gpio.output(led, 1) if gpio.input(button)==False: gpio.output(buz, 1) gpio.output(led, 0) time.sleep(0.5) gpio.output(buz, 0) capture_image() gate() time.sleep(0.5) except KeyboardInterrupt: lcd.clear() lcd.message("Thank You\n Visit Again") time.sleep(3) gpio.output(led, 0) ## gpio.cleaup() finally: lcd.clear() exit(0) 时,它打开了门(表示向前运动有效)但无法关闭(意味着向后运动无效)

我将直流电机与Raspberry Pi的GPIO引脚号17,27(BCM引脚)连接。请检查我的gate()并提出帮助。

0 个答案:

没有答案