1

I'm working on a project where I'm trying to turn a 5V servo motor (9g) when RFID RC522 detects a card. I'm using a Raspberry Pi 3 B+, Python RPi.GPIO lib and another lib: SimpleMFRC522 for the card reader.

I run into a problem where I can't set pins for the servo because of the SimpleMFRC522. I'm getting this error:

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'

Is there any ways to change the GPIO setup and using the servo together with the SimpleMFRC522 lib?

#!/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()
Michael Roland
  • 39,663
  • 10
  • 99
  • 206

1 Answers1

0

The setup method is named GPIO.setup() and not GPIO.SETUP() (note the lower-case characters!).

So changing the method unlock_cooler to this should solve the error that you got:

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)
    p.stop()
    GPIO.cleanup()

Note that you would probably aslo want to call stop() on the PWM instance.

Michael Roland
  • 39,663
  • 10
  • 99
  • 206