Page 1 of 1
RFID RC522
Posted: Sun Dec 20, 2015 12:13 pm
by adamboho
Hi all, anyone know how to change this code
https://github.com/mxgxw/MFRC522-python to code that will be compatible with byboard. Thank you.
Re: RFID RC522
Posted: Sun Dec 20, 2015 12:56 pm
by Turbinenreiter
1. List all the libraries imported by the Original Code
2. Check if they are available on micropython (github.com/micropython/micropython-lib)
3. If not, check what those libraries are used for and find the micropython libraries that do the same
For example:
1.
RPi.GPIO as GPIO
spi
signal
time
2.
RPi.GPIO as GPIO is not available
spi is not available
signal is not available
time is available
3.
RPi.GPIO as GPIO and spi are used for SPI. Micropythons
SPI module replicates that functionality.
signal is used to hook up signals. There is no real micropython equivalent I know of. However, it is not used in MFRC522.py and you may not need it at all.
So what you have to do is simply replace the RPi.GPIO as GPIO and spi modules and it's functions with the SPI module linked above and the function that class provides.
For example:
Code: Select all
def __init__(self, dev='/dev/spidev0.0', spd=1000000):
spi.openSPI(device=dev,speed=spd)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(22, GPIO.OUT)
GPIO.output(self.NRSTPD, 1)
self.MFRC522_Init()
def Write_MFRC522(self, addr, val):
spi.transfer(((addr<<1)&0x7E,val))
could become
Code: Select all
from pyb import SPI
def __init__(self,):
spi = SPI(1, SPI.MASTER, baudrate=600000, polarity=1, phase=0, crc=0x7)
self.MFRC522_Init()
def Write_MFRC522(self, val):
spi.send(val)
You will have to read the documentation of the RPi SPI module and the micropython SPI module to translate the code.
Re: RFID RC522
Posted: Sun Dec 20, 2015 2:45 pm
by adamboho
Thank you for the replay. The thing is that I don't know python good enough to do so.

Re: RFID RC522
Posted: Sun Dec 20, 2015 5:14 pm
by adamboho
Or maybe someone know how to use the RFID RC522 with pyboard?
Re: RFID RC522
Posted: Sun Dec 20, 2015 6:01 pm
by Turbinenreiter
When I started out with micropython, I didn't know much about programming either. Especially not hardware programming. But I sat down, took the micropython documentation and the data-sheet of the part I wanted to use and within a week I wrote drivers for two sensors. All that with great help from the people in the forums.
You can do that, too. You can either adapt the module you linked or you can start from scratch with just the datasheet.
If you are not willing to do that, you will either have to pay someone else to do it, or you will have to wait until someone else also needs that part, does the work and then shares it with us.
I know data-sheets are scary. But in the end, you will either have to learn or to hope someone else writes the code for you.
If you are going to try, we are help to help as good as we can.
Re: RFID RC522
Posted: Sun Dec 20, 2015 6:34 pm
by adamboho
That's what I already do, studying documentation, but it will take long time, which i don't have.