Пример #1
0
 def __init__(self):
     spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
     cs_pin = DigitalInOut(board.D5)
     self.device = PN532_SPI(spi, cs_pin, debug=False)
     self.device.SAM_configuration()
     ic, ver, rev, support = self.device.firmware_version
     print("Found PN532 with firmware version: {0}.{1}".format(ver, rev))
Пример #2
0
 def _configure(self):
     self.pin = DigitalInOut(getattr(board, self.pin_number))
     self.spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
     self.pn532 = PN532_SPI(self.spi, self.pin, debug=self.debug)
     self.pn532.SAM_configuration()
     ic1, ver1, rev1, support1 = self.pn532.get_firmware_version()
     logging.debug(
         f'Found PN532 for {self.pin._pin} with firmware version: {ver1}.{rev1}'
     )
Пример #3
0
def initSPI():
	# SPI connection:
	spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
	cs_pin = DigitalInOut(board.D5)
	pn532 = PN532_SPI(spi, cs_pin, debug=False)
	ic, ver, rev, support = pn532.get_firmware_version()
	print('Found PN532 with firmware version: {0}.{1}'.format(ver, rev))
	# Configure PN532 to communicate with MiFare cards
	pn532.SAM_configuration()
	return pn532
Пример #4
0
    def __init__(self):
        # SPI connection:
        spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
        cs_pin = DigitalInOut(board.D5)
        self.pn532 = PN532_SPI(spi, cs_pin, debug=False)
        ic, ver, rev, support = self.pn532.firmware_version
        log.info(f"Found PN532 with firmware version: {ver}.{rev}")

        # Configure PN532 to communicate with MiFare cards
        self.pn532.SAM_configuration()
Пример #5
0
    def __init__(self, timeout: timedelta):
        # Delay loading board module until a reader object is constructed
        # to allow testing on non-supported devies
        import board

        spi = busio.SPI(board.SCLK, board.MOSI, board.MISO)
        cs_pin = DigitalInOut(board.D5)
        self.pn532 = PN532_SPI(spi, cs_pin, debug=False)

        ic, ver, rev, support = self.pn532.get_firmware_version()
        logger.info('Found PN532 with firmware version: {0}.{1}'.format(ver, rev))

        self.pn532.SAM_configuration()

        self.timeout = timeout
        self.card_timeouts = {}
Пример #6
0
def main():
    # Initialize SPI connection:
    spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
    cs_pin = DigitalInOut(board.CE0)
    pn532 = PN532_SPI(spi, cs_pin, debug=False)

    # Check to make sure PN532 Exists:
    pn532.get_firmware_version(
    )  # This call will throw if it cannot find PN532

    # Configure PN532 to communicate with MiFare cards
    pn532.SAM_configuration()

    lastCharID = None  # Keep track of last charID to prevent spam of same ID

    # Enter scanning loop:
    while True:
        # Check if a card is available to read
        try:
            uid = pn532.read_passive_target(timeout=0.5)
        except RuntimeError:
            # This occurs when more than one card or incompatible card is detected.
            # Tell amiibrOS that the scanned card could not be identified:
            pass  #TODO Remove and do as the above comment says

        # Try again if no card is available
        if uid == None:
            continue

        try:
            charID = pn532.ntag2xx_read_block(CHAR_ID_BLOCK)
        except TypeError:
            # A bug in PN532_SPI will try to subscript a NoneType when the tag read
            #   becomes garbled (usually because an amiibo was lifted off of the
            #   scanner)
            continue  # If this happens, we just try again.

        # Try again if no ID is available
        if charID == None:
            continue

        # Note sys.argv[1] has the pipe's file descriptor if this program is called
        #   from amiibrOS.
        # Tell amiibrOS the hex charID we found:
        if charID != lastCharID:  # But only if it is not the same as previous
            os.write(int(sys.argv[1]), charID)
            lastCharID = charID
Пример #7
0
def connect():

    import board
    import busio
    from digitalio import DigitalInOut
    from adafruit_pn532.spi import PN532_SPI

    # SPI connection:
    spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
    cs_pin = DigitalInOut(board.D4)
    pn532 = PN532_SPI(spi, cs_pin, debug=False)

    #ic, ver, rev, support = pn532.get_firmware_version()
    #print('Found PN532 with firmware version: {0}.{1}'.format(ver, rev))

    # Configure PN532 to communicate with MiFare cards
    pn532.SAM_configuration()

    return pn532
Пример #8
0
def readIDs(ids):
    spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
    cs_pin = DigitalInOut(board.D5)
    pn532 = PN532_SPI(spi, cs_pin, debug=False)

    #ic, ver, rev, support = pn532.get_firmware_version()
    #print('Found PN532 with firmware version: {0}.{1}'.format(ver, rev))

    pn532.SAM_configuration()

    f = open("transfers/rfids.txt")
    """
    ids = []
    for line in f:
        line = line.replace("[","").replace("]","").replace("\n","")
        id = line.split(", ")
        ids.append(id)
    print(ids)
    """

    foundIDs = []

    print('Waiting for RFID/NFC card...')
    while True:
        # Check if a card is available to read
        uid = pn532.read_passive_target(timeout=0.5)
        #print('.', end="")

        # Try again if no card is available.
        if uid is None:
            continue

        foundID = [hex(i) for i in uid]
        #print('Found card with UID:', foundID)

        if foundID in ids:
            print("Found card with UID:", foundID)
            foundIDs.append(foundID)
            return foundID
        else:
            return None
Пример #9
0
# Non-hardware
#pn532 = PN532_I2C(i2c, debug=False)

# With I2C, we recommend connecting RSTPD_N (reset) to a digital pin for manual
# harware reset
# reset_pin = DigitalInOut(board.D6)
# On Raspberry Pi, you must also connect a pin to P32 "H_Request" for hardware
# wakeup! this means we don't need to do the I2C clock-stretch thing
# req_pin = DigitalInOut(board.D12)
# pn532 = PN532_I2C(i2c, debug=False, reset=reset_pin, req=req_pin)

# SPI connection:
spi = busio.SPI(board.SCLK, board.MOSI, board.MISO)
cs_pin = DigitalInOut(board.D5)
pn532 = PN532_SPI(spi, cs_pin, debug=True)

# UART connection
#uart = busio.UART(board.TX, board.RX, baudrate=115200, timeout=100)
#pn532 = PN532_UART(uart, debug=False)

ic, ver, rev, support = pn532.get_firmware_version()
print('Found PN532 with firmware version: {0}.{1}'.format(ver, rev))

# Configure PN532 to communicate with MiFare cards
pn532.SAM_configuration()

print('Waiting for RFID/NFC card...')
while True:
    # Check if a card is available to read
    uid = pn532.read_passive_target(timeout=0.5)
# Non-hardware
#pn532 = PN532_I2C(i2c, debug=False)

# With I2C, we recommend connecting RSTPD_N (reset) to a digital pin for manual
# harware reset
#reset_pin = DigitalInOut(board.D6)
# On Raspberry Pi, you must also connect a pin to P32 "H_Request" for hardware
# wakeup! this means we don't need to do the I2C clock-stretch thing
#req_pin = DigitalInOut(board.D12)
#pn532 = PN532_I2C(i2c, debug=False, reset=reset_pin, req=req_pin)

# SPI connection:
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
cs_pin = DigitalInOut(board.D5)
pn532 = PN532_SPI(spi, cs_pin, debug=False)

# UART connection
#uart = busio.UART(board.TX, board.RX, baudrate=115200, timeout=100)
#pn532 = PN532_UART(uart, debug=False)

ic, ver, rev, support = pn532.get_firmware_version()
print('Found PN532 with firmware version: {0}.{1}'.format(ver, rev))

# Configure PN532 to communicate with MiFare cards
pn532.SAM_configuration()

print('Waiting for RFID/NFC card...')
while True:
    # Check if a card is available to read
    uid = pn532.read_passive_target(timeout=0.5)