I want to read data from a NFC tag with my RC522 connected to a raspberry pi. I like c# programming much more then Python so i decided to use the dotnet/iot library Mfrc522 (https://github.com/dotnet/iot/tree/main/src/devices/Mfrc522).
But with the Mfrc522 Library i do not get any card information.
int pinReset = 22;
board = Board.Create();
GpioController gpioController = board.CreateGpioController();
SpiConnectionSettings connection = new(0, 1);
// Here you can use as well MfRc522.MaximumSpiClockFrequency which is 10_000_000
// Anything lower will work as well
connection.ClockFrequency = 5_000_000;
SpiDevice spi = board.CreateSpiDevice(connection);
mfrc522 = new(spi, pinReset, gpioController, false);
bool res;
Console.WriteLine("Start Listening");
Data106kbpsTypeA card;
do
{
res = mfrc522.ListenToCardIso14443TypeA(out card, TimeSpan.FromSeconds(2));
Thread.Sleep(res ? 0 : 200);
}
while (!res);
Console.WriteLine("CardFound");
Console.WriteLine();
if (UltralightCard.IsUltralightCard(card.Atqa, card.Sak))
{
Console.WriteLine("Ultralight card detected, running various tests.");
ProcessUltralight();
}
else
{
Console.WriteLine("Mifare card detected, dumping the memory.");
ProcessMifare();
}
but
res = mfrc522.ListenToCardIso14443TypeA(out card, TimeSpan.FromSeconds(2));
is always false, i tried different cards and tags. In the documentation they set 4 for pinReset, this didn't work, so i tried 22 because RST is Pin 22 but without success
The wiring is correct because if i run the python script
#!/usr/bin/env python
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
reader = SimpleMFRC522()
try:
id, text = reader.read()
print(id)
print(text)
finally:
GPIO.cleanup()
Everything works without problems.
I use a Raspberry 3 B+ and RC522 (https://joy-it.net/de/products/SBC-RFID-RC522).
thanks