def __init__(self, **kwargs): # Setup all required hardware self.reader = pirc522.RFID(pin_irq=None, antenna_gain=3) wiringpi.wiringPiSetupGpio() # Setup the motor wiringpi.pinMode(PIN_MOTOR, wiringpi.GPIO.PWM_OUTPUT) wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS) wiringpi.pwmSetClock(192) wiringpi.pwmSetRange(2000) # Setup the LEDs for name, pin in LEDS.items(): wiringpi.pinMode(pin, wiringpi.GPIO.OUTPUT) wiringpi.digitalWrite(pin, LOW) # Setup IR RX and IR TX wiringpi.pinMode(PIN_IR_RX, wiringpi.GPIO.INPUT) self.set_led('ir', HIGH) self.set_led('reader', HIGH) # Setup initial state self.coin_presences = collections.deque(maxlen=6) self.players = {} self.player_details = {} self.game = { 'is_empty': False, } # Setup Firestore self.db = firestore.Client.from_service_account_json( '/boot/firebase-credentials.json') self.area_ref = self.db.collection('areas').document(AREA) self.player_ref = self.db.collection('players') # We set our version self.area_ref.set( { 'version': dispenser.__version__, 'is_update': False, 'ip': get_ip(), 'is_align': False, }, merge=True) # Add our watches self.job_check_watch() # Finally start alignment self.align_rotor()
def __init__(self, **kwargs): self.register_event_type("on_present") self.register_event_type("on_remove") super(RFID, self).__init__(**kwargs) self.t_RFID_stop = threading.Event() self.q_RFID = queue.Queue() try: global pirc522 import pirc522 as pirc522 self._reader = pirc522.RFID(pin_irq=None, antenna_gain=7) Logger.debug("RFID: using pirc522") except ImportError: Logger.debug("RFID: Error importing pirc522. Will listen for UDP") except: Logger.debug("RFID: Error importing pirc522 Will listen for UDP")
def __init__(self): self.device = pirc522.RFID()
#!/usr/bin/env python import pirc522 if __name__ == '__main__': try: reader = pirc522.RFID(pin_irq=None, antenna_gain=3) while True: uid = reader.read_id(True) if uid is not None: print(f'UID: {uid:X}') except KeyboardInterrupt: pass finally: reader.cleanup()
if type(card[key]) is dict: action = card[key] ACTION_MAP[action["type"]](action) return execute_curl(card[key]) # welcome message logging.info("Welcome to MFRC522-trigger!") logging.info("Press Ctrl-C to stop.") # create a reader reader = pirc522.RFID() current_tag = '' last_tag = '' count = 0 polling = False # This loop keeps checking for chips. If one is near it will get the UID and authenticate while True: try: # wait for reader to send an interrupt if not polling: reader.wait_for_tag() count += 1 logging.debug("Reader loop %d", count)