2

I am a realative RPi noob so forgive me if this is a simple problem.

I am making a keycard system with the RC522 reader, and I have everything wired up correctly. It works with writing and reading cards. But for some reason when I try to compare the data, it always returns false

EX: Card is written with text "Keycard"

from mfrc522 import SimpleMFRC522
reader = SimpleMFRC522()
while True:
try:
    id, text = reader.read()
except:
    pass
print(text)
if text == "Keycard":
    print("opening")
else:
    print("Unauthorized card")

Now, it outputs

Keycard
Unauthorized card

Why does it not recognize text = keycard?

  • 1
    Perhaps there are some spaces, i.e. "Keycard " – joan Jun 15 at 22:42
  • Thank you so much!! changed 'print(text)' to 'print(text + ",")' and it outputted '"Keycard ,"' Now i just have to count all of the spaces... – GaryFlermen Jun 15 at 22:48
  • print the length of the variable text – jsotola Jun 16 at 1:14
3

As joan pointed out in the comments above, there were extra spaces after "Keycard"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.