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:
    id, text = reader.read()
if text == "Keycard":
    print("Unauthorized card")

Now, it outputs

Unauthorized card

Why does it not recognize text = keycard?

  • 1
    Perhaps there are some spaces, i.e. "Keycard "
    – joan
    Commented Jun 15, 2019 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... Commented Jun 15, 2019 at 22:48
  • print the length of the variable text
    – jsotola
    Commented Jun 16, 2019 at 1:14

1 Answer 1


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 and acknowledge you have read our privacy policy.

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