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)
Pergunta
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)
Solução
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)