Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4504

Python • RFID-RC522 IRQ on Raspberry pi zero w

$
0
0
Hello, I'using the RFID-RC522 module connected with raspberry pi zero w with this connections:

Pin modulo > Pin Raspberry Pi
SDA (SS) > GPIO8 [pin 24] Filo grigio
SCK > GPIO11 [pin 23] Filo blu
MOSI > GPIO10 [pin 19] Filo verde
MISO > GPIO9 [pin 21] Filo arancio
IRQ > GPIO24 [pin 18] Filo ocra
GND > GND [pin 25] Filo nero
RST > GPIO25 [pin 22] Filo viola
3.3V > 3V3 [pin 1] Filo rosso

To detect RF tag I'm using a polling with "while" loop and it works. I'would like to use IRQ but it doesn't work
the is the follow:

import sys
import signal
import time
from gpiozero import Button
from pirc522 import RFID[/code][/code]

# Configura il lettore RFID e il pin IRQ
reader = RFID()
PIN_IRQ = 18 # Modifica questo secondo il tuo pin IRQ

# Crea un pulsante per gestire il pin IRQ
button = Button(PIN_IRQ)

# Funzione per gestire la lettura del tag
def read_tag():
print("Card detected")
(status, uid) = reader.anticoll()
if status == reader.MI_OK:
print("Card read UID: {}".format(", ".join(map(str, uid))))
reader.stop_crypto()

# Gestione dell'uscita del programma
def end_read(signal, frame):
print("Ctrl+C captured, ending read.")
reader.cleanup() # Pulisce le impostazioni di GPIO
sys.exit(0)

# Hook per catturare il segnale di interruzione
signal.signal(signal.SIGINT, end_read)

print("Press Ctrl+C to stop.")
print("Waiting for card...")

try:
# Associa la lettura del tag all'evento di pressione del pulsante
button.when_pressed = read_tag

# Mantieni il ciclo attivo
while True:
time.sleep(1) # Aspetta un secondo, ma rimane attivo in attesa di eventi
except Exception as e:
print(f"Error: {e}")
finally:
reader.cleanup() # Pulisce le impostazioni di GPIO

Code:

[/code]

what could be the problem?
Thanks in advance!

Statistics: Posted by fabiogiustini — Tue Sep 24, 2024 8:59 pm — Replies 0 — Views 20



Viewing all articles
Browse latest Browse all 4504

Trending Articles