Skip to content

Instantly share code, notes, and snippets.

@ypelletier
Last active December 11, 2018 22:59
Show Gist options
  • Save ypelletier/665059eb61d391c7b04f1d56f7626721 to your computer and use it in GitHub Desktop.
Save ypelletier/665059eb61d391c7b04f1d56f7626721 to your computer and use it in GitHub Desktop.
Lecture de l'UID d'un tag RFID au moyen d'un module RC522 branché à un Rapberry Pi.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Lecture de l'UID d'un tag RFID au moyen
d'un module RC522 branché à un Rapberry Pi.
Une LED verte s'allume si le tag est accepté,
sinon c'est une LED rouge qui s'allume.
Utilisation de la bibliothèque pi-rc522.
Pour plus d'informations:
https://electroniqueamateur.blogspot.com/2017/04/module-rfid-rc522-et-raspberry-pi-python.html
'''
from pirc522 import RFID # pour le RFID
import time # pour les delais
import RPi.GPIO as GPIO # pour l'allumage des LEDs
bonUID = [144,207,148,117] # a remplacer par l'UID correct
LEDverte = 15 # LED verte branchee pin 15
LEDrouge = 16 # LED rouge branchee pin 16
rc522 = RFID()
GPIO.setup(LEDverte,GPIO.OUT)
GPIO.setup(LEDrouge,GPIO.OUT)
while True:
refus = 0
rc522.wait_for_tag()
(error, tag_type) = rc522.request()
if not error:
(error, uid) = rc522.anticoll()
if not error:
for i in range(0, 4):
if uid[i] != bonUID[i]:
refus = refus + 1
if refus == 0:
GPIO.output(LEDverte,GPIO.HIGH)
time.sleep(2)
GPIO.output(LEDverte,GPIO.LOW)
else:
GPIO.output(LEDrouge,GPIO.HIGH)
time.sleep(2)
GPIO.output(LEDrouge,GPIO.LOW)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment