Uncategorized

MFR522 RFID discussion notes

#!/usr/bin/env python

import os
import time
import RPi.GPIO as GPIO

from mfrc522 import SimpleMFRC522

import array as arr

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

pinList = [5,24,0,2,3,4,27,25]

rfidList = [1081714680121, 871849641659, 504025229752,

                   275844158012, 648722309022, 118668796333, 737282492797]

id = 0

while True:

reader = SimpleMFRC522()
id, text = reader.read()
print(id)

if id:
if id == 828191200458:

for i in pinList:
os.system(“sudo gpio mode “+str(i)+” out”)
time.sleep(0.5)

for i in pinList:
os.system(“sudo gpio mode “+str(i)+” in”)
time.sleep(0.5)

for i in range(len(rfidList)):

if id == rfidList[i]:
os.system(“sudo gpio mode “+str(pinList[i])+” out”)
time.sleep(3.5)
os.system(“sudo gpio mode “+str(pinList[i])+” in”)
GPIO.cleanup()
time.sleep(0.5)

.END

SimpleMFRC522 stop reading after some time

Asked 
Active yesterday
Viewed 17 times
0

My code stack after some time (example 1 day) after reading MFRC522 in loop mode. At the beginning it works without problems, after some time is not working anymore. I can’t figure out why. Can you help me?

#!/usr/bin/env python

import os
import time
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
import array as arr

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
pinList = [5,24,0,2,3,4,27,25]
rfidList = [1081714680121,871849641659,504025229752,275844158012,648722309022,118668796333,737282492797]
id  = 0

while True:
    reader = SimpleMFRC522()
    id, text = reader.read()
    print(id)
    if id:
        if id == 828191200458:
            for i in pinList:
                os.system("sudo gpio mode "+str(i)+" out")
            time.sleep(0.5)

            for i in pinList:
                os.system("sudo gpio mode "+str(i)+" in")
            time.sleep(0.5)

        for i in range(len(rfidList)):
            if id == rfidList[i]:
                os.system("sudo gpio mode "+str(pinList[i])+" out")
            time.sleep(3.5)
            os.system("sudo gpio mode "+str(pinList[i])+" in")
    GPIO.cleanup()
    time.sleep(0.5)

Thank You!

The link of MFRC522 is HERE

 New contributor
  • 1
    How exactly is it “not working”? Does it crash? does it get stuck? Where? – Dmitry Grigoryev yesterday
  • 1
    The code works great for 1 day. Reads every card, really, but after 1 day or after 5 hours, i don’t know exactly when, stops reading without error or anything else. It simply stops reading, if i reboot the raspberry get back to work again, i can’t figure out why – Simon D. yesterday
0

At a guess it is because the code runs out of memory.

The code reader = SimpleMFRC522() creates a new object every time around the loop. I suspect the old copy is hanging around in memory and not being garbage collected.

That line should be before the while loop.

Also the call to GPIO.cleanup() is almost certainly wrong and should probably be removed.

  • If i put outside the reader = SimpleMFRC522(), after 30 minutes it stops reading. The GPIO.cleanup() is for refresh. It’s wrong? – Simon D. yesterday
  • The whole structure seems suspect to me. However to find out I would need to look at SimpleMFRC522 which I’m not going to do (and you haven’t provided a link to it anyway). – joan yesterday
  • The SimpleMFRC522 is the classic SimpleMFRC522 [here] (github.com/pimylifeup/MFRC522-python/blob/master/mfrc522/…) but if you’re not going to watch it, i can just thank you for the reply and the interest. – Simon D. yesterday
  • You should really add that information to your question. – joan yesterday
.END

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: