Giter Site home page Giter Site logo

circuitpython-mfrc522's Introduction

circuitpython-mfrc522

CircuitPython class to access the MFRC522 RFID reader

Based on the wendlers/micropython-mfrc522 MicroPython library.

Basic class to access RFID readers of the type MFRC522. This is basically a re-write of this Python port for the MFRC522. I tried to strip things down and make them more "pythonic" so the result is small enough to run on CircuitPython boards.

Usage

Put the modules mfrc522.py, examples/read.py, examples/write.py to the root of the flash FS on your board.

I used the following pins for my setup:

Signal GPIO ESP8266 GPIO WiPy Note
sck 0 "GP14"
mosi 2 "GP16"
miso 4 "GP15"
rst 5 "GP22"
cs 14 "GP14" Labeled SDA on most RFID-RC522 boards

Now enter the REPL you could run one of the two examples:

For detecting, authenticating and reading from a card:

import read
read.do_read()

This will wait for a MifareClassic 1k card. As soon the card is detected, it is authenticated, and 16 bytes are read from address 0x08.

For detecting, authenticating and writing to a card:

import write
write.do_write()

This will wait for a MifareClassic 1k card. As soon the card is detected, it is authenticated, and 16 bytes written to address 0x08.

circuitpython-mfrc522's People

Contributors

domdfcoding avatar jr-k avatar wendlers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

circuitpython-mfrc522's Issues

Converting to I2C

I am trying to convert this library to work on an WS12850S that allegedly has the exact same software interface as the MFRC522 but using an I2C interface rather than SPI.

To do this, I replaced two functions:

    def _wreg(self, reg: int, val):
        data = bytearray([val])
        self.i2c.try_lock()
        self.i2c.writeto_then_readfrom(self.i2c_address, bytes([reg]), data)
        self.i2c.unlock()
        return data[0]

    def _rreg(self, reg: int):
        data = bytearray(1)
        self.i2c.try_lock()
        self.i2c.writeto_then_readfrom(self.i2c_address, bytes([reg]), data)
        self.i2c.unlock()
        return data[0]

Looks reasonable so far, for writing single bytes. I'm not sure the readback from _wreg is meaningful.

This kind of works, but I'm a little concerned about this:

    def _tocard(self, cmd: int, send):
       ...
        for c in send:
            self._wreg(0x09, c)

I think the intent there is to write a string of bytes (send) but in I2C I think I would want to do that as a single transaction, similar to what I did with my _wreg but taking an array of values rather than just a single byte. Does this make sense? Do you agree, and do you see other things that would need modification?

Finally ... if this works, is it worth abstracting out the physical interface so that we can re-use your code but select the interface (SPI or I2C) like:

	rdr = MFRC522( spiInterface )
	rdr = MFRC522( i2cInterface )

and both those interfaces include _wreg, _rreg, and possibly _tocard (and maybe more?)

ValueError: GP14 in use

I tried this project, but at first I got the error "AttributeError: 'module' object has no attribute 'SCK'".
Therefore, I directly specified the pin number on line 15 of read.py like "rdr = mfrc522.MFRC522(board.GP14, board.GP16, board.GP15, board.GP22, board.GP14)".
Then, the following error occurred.

Traceback (most recent call last):
File "", line 54, in
File "", line 15, in do_read
File "mfrc522.py", line 34, in init
ValueError: GP14 in use

How can I fix this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.