#!/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
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
-
1How exactly is it “not working”? Does it crash? does it get stuck? Where? – Dmitry Grigoryev yesterday
-
1The 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
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.
-
-
-
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
-
Categories: Uncategorized