Advertisement
Guest User

Untitled

a guest
May 14th, 2015
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf8 -*-
  3.  
  4.  
  5. import RPi.GPIO as GPIO
  6. import MFRC522
  7. import signal
  8. continue_reading = True
  9.  
  10.  
  11. # Capture SIGINT for cleanup when the script is aborted
  12. def end_read(signal,frame):
  13.     global continue_reading
  14.     print "Ctrl+C captured, ending read."
  15.     continue_reading = False
  16.     GPIO.cleanup()
  17.  
  18.  
  19. # Hook the SIGINT
  20. signal.signal(signal.SIGINT, end_read)
  21.  
  22.  
  23. # Create an object of the class MFRC522
  24. MIFAREReader = MFRC522.MFRC522()
  25.  
  26.  
  27. # Welcome message
  28. print "Welcome to the MFRC522 data read example"
  29. print "Press Ctrl-C to stop."
  30.  
  31.  
  32.  
  33. while continue_reading:
  34.     # Scan for cards
  35.     (status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
  36.  
  37.     # Print Status
  38.     print "Status: "+status
  39.     print "Type:   "+TagType
  40.  
  41.     """
  42.     # If a card is found
  43.     if status == MIFAREReader.MI_OK:
  44.         print "Card detected"
  45.     """
  46.  
  47.     # Get the UID of the card
  48.     (status,uid) = MIFAREReader.MFRC522_Anticoll()
  49.  
  50.     # If we have the UID, continue
  51.     if status == MIFAREReader.MI_OK:
  52.         # Print UID
  53.         print "Leitura cartao/chaveiro RFID OK!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement