Ejemplo n.º 1
0
    def __init__(self):
        # i2c bus configuration
        self.i2c = busio.I2C(board.SCL, board.SDA)

        # PN532 creation
        self.pn532 = PN532_I2C(self.i2c, debug=False)

        # Configure PN532 to communicate with MiFare cards
        self.pn532.SAM_configuration()
Ejemplo n.º 2
0
GPIO.setmode(GPIO.BCM)

import board
import busio
from digitalio import DigitalInOut

from adafruit_pn532.i2c import PN532_I2C

# I2C connection:
i2c = busio.I2C(board.SCL, board.SDA)

# keep trying to initialise the sensor
while True:
    try:
        # Non-hardware reset/request with I2C
        pn532 = PN532_I2C(i2c, debug=False)
        ic, ver, rev, support = pn532.firmware_version
        print("Found PN532 with firmware version: {0}.{1}".format(ver, rev))
        break
    except:
        print("failed to start RFID")
        sleep(1)

# this delay avoids some problems after wakeup
sleep(0.5)

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

non_poisoned_cards = ['PSB', 'PDT', 'PZK', 'PTB']
poisoned_cards = ['PVM', 'PSV']
# from adafruit_pn532.spi import PN532_SPI
# from adafruit_pn532.uart import PN532_UART

# I2C connection:
i2c = busio.I2C(board.SCL, board.SDA)

# 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=0.1)
# pn532 = PN532_UART(uart, debug=False)

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

# Configure PN532 to communicate with MiFare cards
pn532.SAM_configuration()
Ejemplo n.º 4
0
import board
import busio
from digitalio import DigitalInOut
from adafruit_pn532.i2c import PN532_I2C
import feathers2
import time

feathers2.enable_LDO2(True)
i2c = busio.I2C(board.SCL, board.SDA)
irq_pin = DigitalInOut(board.D19)
pn532 = PN532_I2C(i2c, debug=False, reset=DigitalInOut(board.D18), irq=irq_pin)
pn532.SAM_configuration()

foo = pn532.listen_for_passive_target()
current = None
print("Waiting for RFID/NFC card...")
step = 0
while True:
    # Check if a card is available to read
    if irq_pin.value == 0:
        uid = pn532.get_passive_target()
        if current != uid:
            print("")
            print("Found card with UID:", [hex(i) for i in uid])
            data = bytearray()
            try:
                for x in range(40):
                    incoming = pn532.ntag2xx_read_block(x)
                    for byt in incoming:
                        data.append(byt)
            except:
Ejemplo n.º 5
0
 def __init__(self):
     self._reader = PN532_I2C(busio.I2C(board.SCL, board.SDA))
     self._reader.SAM_configuration()
Ejemplo n.º 6
0
import board
import busio
import hx711
import websockets
from adafruit_pn532.i2c import PN532_I2C

# Constants
REFERENCE_UNIT = -2053.4638810934416
NFC_PIN_1 = 5
NFC_PIN_2 = 6
NR_SCALE_READS = 5
API_URL = 'ws://89.212.198.159:8000/ws/'

# Setup nfc reader
i2c = busio.I2C(board.SCL, board.SDA)
pn532 = PN532_I2C(i2c)
pn532.SAM_configuration()

# Setup scale sensor.
hx = hx711.HX711(NFC_PIN_1, NFC_PIN_2)
hx.set_reading_format("MSB", "MSB")
hx.reset()
hx.tare()
hx.set_reference_unit(REFERENCE_UNIT)


# Connect to server with socket
async def loop():
    async with websockets.connect(API_URL) as sock:
        while True:
            # Read tag and weight.