3

I am running the following python script on my Raspberry Pi:

http://www.skpang.co.uk/dl/rfid.py

I've modified the script towards the end to access the GPIO pin 15 and turn it on and off. Here is my code at the bottom:

def example():

rfid = SL030()
fw = rfid.get_firmware()
print("RFID reader firmware:" + fw)
print()

GPIO.setmode(GPIO.BOARD)
GPIO.setup(15, GPIO.OUT)
GPIO.output(15,True)


while True:
    rfid.wait_tag()
    print("card present")

    if rfid.select_mifare():
        type = rfid.get_type()
        print("type:" + rfid.get_typename(type))

        id = rfid.get_uidstr()
        try:
            user = cards[id]
            print(user)
            #os.system("aplay " + user)
        except KeyError:
            print("Unknown card:" + id)

    rfid.wait_notag()
    print("card removed")
    print()

Problem i am facing is that although it operates pin 15, the script halts with the following error:

Traceback (most recent call last):
  File "./rfid.py", line 212, in <module>
    example()
  File "./rfid.py", line 182, in example
rfid.wait_tag()
  File "./rfid.py", line 45, in wait_tag
while not self.tag_present():
  File "./rfid.py", line 40, in tag_present
    return GPIO.input(CFG_TAG_DETECT) == False
    RPi.GPIO.InvalidChannelException: The channel sent is invalid on a Raspberry Pi

Any ideas what can be wrong?

Thanks

UPDATE

If i put the GPIO code just below the def example(): and above the rfid = SL030() like below, then it seems to work without error:

def example():

    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(15, GPIO.OUT)
    GPIO.output(15,True)

    rfid = SL030()

*UPDATE - SOLUTION*

Thanks to André, i changed:

GPIO.setmode(GPIO.BOARD)

to: GPIO.setmode(GPIO.BCM)

and then changed the port to match the BCM port like this:

GPIO.setup(22, GPIO.OUT)
GPIO.output(22,True)
0

1 Answer 1

6

From this question, it looks like there are two modes for GPIO : GPIO.BCM and GPIO.BOARD... try using the other one :

GPIO.setmode(GPIO.BCM)
Sign up to request clarification or add additional context in comments.

3 Comments

perfect, i changed it to GPIO.BCM and its all working now. Only thing is that i needed the change the port number to match the BCM number which is 22
Thats odd, because board 15 is the same as bcm 22... ?
Yes, setting the right mode helps, especially with a cheatsheet like raspi.tv/download/RPi.GPIO-Cheat-Sheet.pdf there are other available.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.