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 Jun 15 '19 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 '19 at 22:48
  • print the length of the variable text – jsotola Jun 16 '19 at 1:14

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

| improve this answer | |

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.