【发布时间】:2019-01-12 21:29:48
【问题描述】:
我正在做一个项目,我试图在 RFID RC522 检测到卡时转动 5V 伺服电机 (9g)。我正在使用 Raspberry Pi 3 B+、Python RPi.GPIO 库和另一个库:SimpleMFRC522 用于读卡器。
我遇到了一个问题,由于 SimpleMFRC522,我无法为伺服设置引脚。我收到此错误:
File "test.py", line 39, in <module>
unlock_cooler()
File "test.py", line 21, in unlock_cooler
GPIO.SETUP(7, GPIO.OUT)
AttributeError: 'module' object has no attribute 'SETUP'
有什么方法可以更改 GPIO 设置并将伺服与 SimpleMFRC522 库一起使用?
#!/usr/bin/env python
import RPi.GPIO as GPIO
import SimpleMFRC522
import re
rfid = 0
def read_RFID():
reader = SimpleMFRC522.SimpleMFRC522()
id, text = reader.read()
clean_text = re.findall('\d+', text)
match = int(clean_text[0])
rfid = match
GPIO.cleanup()
def unlock_cooler():
GPIO.SETUP(7, GPIO.OUT)
p = GPIO.PWM(7, 50)
p.start(2.5)
p.ChangeDutyCycle(7.5)
time.sleep(3)
p.ChangeDutyCycle(2.5)
time.sleep(1)
GPIO.cleanup()
read_RFID()
print(rfid)
if rfid == 6:
unlock_cooler()
GPIO.cleanup()
【问题讨论】:
标签: python raspberry-pi3 gpio rfid servo