nanoFramework.Iot.Device.Mfrc522
1.2.606
Prefix Reserved
See the version list below for details.
dotnet add package nanoFramework.Iot.Device.Mfrc522 --version 1.2.606
NuGet\Install-Package nanoFramework.Iot.Device.Mfrc522 -Version 1.2.606
<PackageReference Include="nanoFramework.Iot.Device.Mfrc522" Version="1.2.606" />
paket add nanoFramework.Iot.Device.Mfrc522 --version 1.2.606
#r "nuget: nanoFramework.Iot.Device.Mfrc522, 1.2.606"
// Install nanoFramework.Iot.Device.Mfrc522 as a Cake Addin #addin nuget:?package=nanoFramework.Iot.Device.Mfrc522&version=1.2.606 // Install nanoFramework.Iot.Device.Mfrc522 as a Cake Tool #tool nuget:?package=nanoFramework.Iot.Device.Mfrc522&version=1.2.606
MFRC522 - RFID reader
MFRC522 is a very cheap RFID/NFC reader for Iso 14443 Type A cards. Part of those cars are the Mifare and Ultralight family. This reader implement the proprietary Mifare cryptography protocol and can be used transparently.
Documentation
- MFRC5222 Datasheet
Usage
MFRC522 supports SPI, I2C and UART (Serial Port). You can create the reader with any of those protocols.
Note: most of the popular boards you'll buy are SPI only. This documentation will focus on SPI. You have in the samples more information on how to setup I2C and UART.
GpioController gpioController = new GpioController();
// adjust the GPIO used for the hard reset
int pinReset = 21;
// Default on ESP32:
// GPIO23 = MOSI; GPIO25 = MISO; GPIO19 = Clock
// Uncomment for SPI
SpiConnectionSettings connection = new(1, 22);
// 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 = SpiDevice.Create(connection);
MfRc522 mfrc522 = new(spi, pinReset, gpioController, false);
The code will create an instance of MFRC522 and will use the pin GPIO21 as the hardware rest pin and will create an GpioController automatically from the default driver. Check the detailed [samples] for more elements. More detailed examples shows how to use other type or cards.
You can get the version using the Version
property.
Debug.WriteLine($"Version: {mfrc522.Version}, version should be 1 or 2. Some clones may appear with version 0");
Keep in mind that having a version which is 0.0 doesn't necessary means that your reader is not working properly, if you bought a cheap copy of an original MFRC522, the internal version may not be recognized.
MFRC522 only supports ISO 14443 Type A. You can pull a card like this:
bool res;
Data106kbpsTypeA card;
do
{
res = mfrc522.ListenToCardIso14443TypeA(out card, TimeSpan.FromSeconds(2));
Thread.Sleep(res ? 0 : 200);
}
while (!res);
As soon as a card will be detected, it will get out a Data106kbpsTypeA
class which is a card. You will have the Unique Identifier from the card as well as the rest of the elements to help identifying it.
You can then create a Mifare card and fo operation on it:
var mifare = new MifareCard(mfrc522, 0);
mifare.SerialNumber = card.NfcId;
mifare.Capacity = MifareCardCapacity.Mifare1K;
mifare.KeyA = MifareCard.DefaultKeyA;
mifare.KeyB = MifareCard.DefaultKeyB;
mifare.BlockNumber = 0;
mifare.Command = MifareCardCommand.AuthenticationB;
ret = mifare.RunMifareCardCommand();
if (ret < 0)
{
mifare.ReselectCard();
Debug.WriteLine($"Error reading bloc: {mifare.BlockNumber}");
}
else
{
mifare.Command = MifareCardCommand.Read16Bytes;
ret = mifare.RunMifareCardCommand();
if (ret >= 0)
{
if (mifare.Data is object)
{
Debug.WriteLine($"Bloc: {mifare.BlockNumber}, Data: {BitConverter.ToString(mifare.Data)}");
}
}
else
{
mifare.ReselectCard();
Debug.WriteLine($"Error reading bloc: {mifare.BlockNumber}");
}
}
Important: you have to do the ReselectCard()
operation every time you have a failure in reading or authentication. By default the card will stop responding. This behavior is wanted by design to make is longer to brute force the authentication mechanism. The samples shows a way how to find a key from known keys for NDEF scenarios for example. Note that the sample is not fully optimize, it is to help understanding what as the mechanism behind.
Other notes
- The SPI implementation has been deeply tested.
- The I2C and UART has been barely tested due to lack of hardware support. So please open issues if you have any issue.
- When using I2C, the address can be setup using the hardware pin, it's the reason why there is no default address.
- If you are using UART, it is more than strongly recommended to use as high as possible serial baud transfer.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net is compatible. |
-
- nanoFramework.CoreLibrary (>= 1.15.5)
- nanoFramework.Iot.Device.Card (>= 1.2.605)
- nanoFramework.Logging (>= 1.1.108)
- nanoFramework.Runtime.Events (>= 1.11.18)
- nanoFramework.Runtime.Native (>= 1.6.12)
- nanoFramework.System.Buffers.Binary.BinaryPrimitives (>= 1.2.586)
- nanoFramework.System.Device.Gpio (>= 1.1.41)
- nanoFramework.System.Device.I2c (>= 1.1.16)
- nanoFramework.System.Device.Spi (>= 1.3.52)
- nanoFramework.System.Diagnostics.Stopwatch (>= 1.2.586)
- nanoFramework.System.IO.Ports (>= 1.1.86)
- nanoFramework.System.IO.Streams (>= 1.1.59)
- nanoFramework.System.Text (>= 1.2.54)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.2.673 | 77 | 10/23/2024 |
1.2.662 | 79 | 10/11/2024 |
1.2.656 | 95 | 10/3/2024 |
1.2.635 | 92 | 8/30/2024 |
1.2.631 | 83 | 8/28/2024 |
1.2.606 | 63 | 8/2/2024 |
1.2.595 | 71 | 7/24/2024 |
1.2.590 | 90 | 7/17/2024 |
1.2.570 | 100 | 6/14/2024 |
1.2.560 | 107 | 5/29/2024 |
1.2.552 | 108 | 5/17/2024 |
1.2.548 | 104 | 5/15/2024 |
1.2.536 | 129 | 4/15/2024 |
1.2.486 | 145 | 2/2/2024 |
1.2.483 | 100 | 1/31/2024 |
1.2.479 | 103 | 1/27/2024 |
1.2.446 | 265 | 11/17/2023 |
1.2.436 | 136 | 11/10/2023 |
1.2.416 | 125 | 11/8/2023 |
1.2.329 | 230 | 5/26/2023 |
1.2.313 | 171 | 5/12/2023 |
1.2.298 | 161 | 5/5/2023 |
1.2.297 | 171 | 5/3/2023 |
1.2.253 | 303 | 2/22/2023 |
1.2.243 | 267 | 2/20/2023 |
1.2.215 | 339 | 1/6/2023 |
1.2.212 | 323 | 1/5/2023 |
1.2.205 | 303 | 12/30/2022 |
1.2.203 | 313 | 12/28/2022 |
1.2.161 | 371 | 11/15/2022 |
1.2.159 | 364 | 11/14/2022 |
1.2.155 | 364 | 11/6/2022 |
1.2.153 | 396 | 11/5/2022 |
1.2.141 | 429 | 10/25/2022 |
1.2.128 | 415 | 10/22/2022 |
1.2.122 | 468 | 10/12/2022 |
1.2.118 | 438 | 10/11/2022 |
1.2.117 | 418 | 10/10/2022 |
1.2.114 | 402 | 10/8/2022 |
1.2.95 | 448 | 9/22/2022 |
1.2.89 | 434 | 9/16/2022 |
1.2.87 | 499 | 9/15/2022 |
1.2.73 | 430 | 9/8/2022 |
1.2.40 | 441 | 8/6/2022 |
1.2.35 | 423 | 8/4/2022 |
1.2.5 | 474 | 7/13/2022 |
1.2.0 | 366 | 11/2/2022 |
1.1.141.41205 | 452 | 7/6/2022 |
1.1.116.8772 | 473 | 6/24/2022 |
1.1.113.2032 | 466 | 6/23/2022 |
1.1.111.5739 | 462 | 6/17/2022 |
1.1.109.32999 | 453 | 6/16/2022 |
1.1.99.36719 | 464 | 6/14/2022 |
1.1.97.17326 | 465 | 6/13/2022 |
1.1.92.53000 | 464 | 6/8/2022 |
1.1.67.25390 | 469 | 5/27/2022 |
1.1.48.19401 | 456 | 5/19/2022 |
1.1.38 | 486 | 5/4/2022 |
1.1.27 | 472 | 4/26/2022 |
1.1.20 | 466 | 4/21/2022 |
1.1.3 | 473 | 4/15/2022 |
1.1.1 | 472 | 4/14/2022 |
1.0.300 | 474 | 3/31/2022 |
1.0.278-preview.125 | 139 | 3/25/2022 |
1.0.278-preview.124 | 126 | 3/25/2022 |
1.0.278-preview.115 | 114 | 3/22/2022 |
1.0.278-preview.111 | 121 | 3/19/2022 |
1.0.278-preview.109 | 120 | 3/18/2022 |
1.0.278-preview.105 | 132 | 3/15/2022 |
1.0.278-preview.104 | 126 | 3/15/2022 |
1.0.278-preview.101 | 118 | 3/11/2022 |
1.0.278-preview.98 | 121 | 3/10/2022 |
1.0.278-preview.97 | 123 | 3/8/2022 |
1.0.278-preview.84 | 130 | 2/25/2022 |
1.0.278-preview.76 | 126 | 2/18/2022 |
1.0.278-preview.70 | 122 | 2/11/2022 |
1.0.278-preview.64 | 119 | 2/9/2022 |
1.0.278-preview.62 | 126 | 2/8/2022 |
1.0.278-preview.61 | 134 | 2/5/2022 |
1.0.278-preview.59 | 140 | 2/4/2022 |
1.0.278-preview.52 | 144 | 1/31/2022 |
1.0.278-preview.40 | 141 | 1/28/2022 |
1.0.278-preview.31 | 138 | 1/27/2022 |
1.0.278-preview.29 | 140 | 1/27/2022 |
1.0.278-preview.16 | 144 | 1/24/2022 |
1.0.278-preview.14 | 137 | 1/21/2022 |
1.0.278-preview.12 | 142 | 1/21/2022 |
1.0.278-preview.1 | 141 | 1/14/2022 |
1.0.272 | 173 | 1/10/2022 |
1.0.259 | 340 | 12/9/2021 |
1.0.221 | 169 | 10/19/2021 |
1.0.219 | 174 | 10/19/2021 |
1.0.218 | 203 | 10/18/2021 |
1.0.217 | 204 | 10/16/2021 |
1.0.209 | 193 | 10/12/2021 |
1.0.194 | 209 | 10/1/2021 |
1.0.193 | 175 | 9/30/2021 |
1.0.191 | 176 | 9/29/2021 |
1.0.146 | 182 | 7/22/2021 |
1.0.140 | 183 | 7/20/2021 |
1.0.138 | 203 | 7/18/2021 |