Commit 4898c62d authored by Ondřej Kučera's avatar Ondřej Kučera
Browse files

add rfid lib

parent c2fb8f10
language: python
python:
- "2.7"
# Cache PlatformIO packages using Travis CI container-based infrastructure
sudo: false
cache:
directories:
- "~/.platformio"
env:
# add examples here and define which boards should be tested (only compile test)
- PLATFORMIO_CI_SRC=examples/ChangeUID/ChangeUID.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/DumpInfo/DumpInfo.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/firmware_check/firmware_check.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/FixBrickedUID/FixBrickedUID.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/MifareClassicValueBlock/MifareClassicValueBlock.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/MinimalInterrupt/MinimalInterrupt.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/ReadAndWrite/ReadAndWrite.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/ReadUidMultiReader/ReadUidMultiReader.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/rfid_default_keys/rfid_default_keys.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/rfid_write_personal_data/rfid_write_personal_data.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/Ntag216_AUTH/Ntag216_AUTH.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/ReadNUID/ReadNUID.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/servo_motor/servo_motor.ino TESTBOARD=arduino_avr,teensy
- PLATFORMIO_CI_SRC=examples/RFID-Cloner/RFID-Cloner.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
install:
- pip install -U platformio
script:
# short the string comparison
- stringContain() { [ -z "${2##*$1*}" ]; }
# selectable board tests @Rotzbua
- board="arduino_avr"; if stringContain "$board" "$TESTBOARD"; then echo "check board $board"; platformio ci --lib=. --board=uno --board=megaatmega1280; else echo "skip board test of $board"; fi
- board="arduino_arm"; if stringContain "$board" "$TESTBOARD"; then echo "check board $board"; platformio ci --lib=. --board=due --board=zero; else echo "skip board test of $board"; fi
- board="teensy"; if stringContain "$board" "$TESTBOARD"; then echo "check board $board"; platformio ci --lib=. --board=teensy31; else echo "skip board test of $board"; fi
- board="esp"; if stringContain "$board" "$TESTBOARD"; then echo "check board $board"; platformio ci --lib=. --board=d1_mini; else echo "skip board test of $board"; fi
This diff is collapsed.
This diff is collapsed.
# Makefile for MFRC522 library
#
all: package
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " clean to clean the project (e.g. remove process files)"
@echo " package to package the library (into a zip file)"
clean:
rm ./MFRC522.zip
@echo
@echo "Clean finished."
package:
zip -o ./MFRC522.zip ./MFRC522.h ./MFRC522.cpp
MFRC522
=======
.. image:: https://travis-ci.org/miguelbalboa/rfid.svg?branch=master
:target: https://travis-ci.org/miguelbalboa/rfid
Arduino library for MFRC522 and other RFID RC522 based modules.
Read and write different types of Radio-Frequency IDentification (RFID) cards
on your Arduino using a RC522 based reader connected via the Serial Peripheral
Interface (SPI) interface.
Set the UID, write to sector 0, and unbrick Chinese UID changeable MIFARE cards.
.. _compatible boards:
Compatible boards
----------
This library is compatible to Teensy and ESP8266, but not all examples are available for every board. Also you have to change pins, see `pin layout`_.
.. _pin layout:
Pin Layout
----------
The following table shows the typical pin layout used:
+-----------+----------+---------------------------------------------------------------+--------------------------+
| | PCD | Arduino | Teensy |
| +----------+-------------+---------+---------+-----------------+-----------+--------+--------+--------+
| | MFRC522 | Uno | Mega | Nano v3 |Leonardo / Micro | Pro Micro | 2.0 | ++ 2.0 | 3.1 |
+-----------+----------+-------------+---------+---------+-----------------+-----------+--------+--------+--------+
| Signal | Pin | Pin | Pin | Pin | Pin | Pin | Pin | Pin | Pin |
+===========+==========+=============+=========+=========+=================+===========+========+========+========+
| RST/Reset | RST | 9 [1]_ | 5 [1]_ | D9 | RESET / ICSP-5 | RST | 7 | 4 | 9 |
+-----------+----------+-------------+---------+---------+-----------------+-----------+--------+--------+--------+
| SPI SS | SDA [3]_ | 10 [2]_ | 53 [2]_ | D10 | 10 | 10 | 0 | 20 | 10 |
+-----------+----------+-------------+---------+---------+-----------------+-----------+--------+--------+--------+
| SPI MOSI | MOSI | 11 / ICSP-4 | 51 | D11 | ICSP-4 | 16 | 2 | 22 | 11 |
+-----------+----------+-------------+---------+---------+-----------------+-----------+--------+--------+--------+
| SPI MISO | MISO | 12 / ICSP-1 | 50 | D12 | ICSP-1 | 14 | 3 | 23 | 12 |
+-----------+----------+-------------+---------+---------+-----------------+-----------+--------+--------+--------+
| SPI SCK | SCK | 13 / ICSP-3 | 52 | D13 | ICSP-3 | 15 | 1 | 21 | 13 |
+-----------+----------+-------------+---------+---------+-----------------+-----------+--------+--------+--------+
.. [1] Configurable, typically defined as RST_PIN in sketch/program.
.. [2] Configurable, typically defined as SS_PIN in sketch/program.
.. [3] The SDA pin might be labeled SS on some/older MFRC522 boards.
.. _hardware:
Hardware
--------
There are three hardware components involved:
1. **Micro Controller**:
* An `Arduino`_ or compatible executing the Sketch using this library.
* Prices vary from USD 7 for clones, to USD 75 for "starter kits" (which
might be a good choice if this is your first exposure to Arduino;
check if such kit already includes the Arduino, Reader, and some Tags).
2. **Proximity Coupling Device (PCD)**:
* The PCD is the actual RFID **Reader** based on `NXP MFRC522`_ Contactless
Reader Integrated Circuit).
* Readers can be found on `eBay`_ for around USD 5: search for *"rc522"*.
* You can also find them at several web stores, they are often included in
*"starter kits"*; so check your favourite electronics provider as well.
3. **Proximity Integrated Circuit Card (PICC)**:
* The PICC is the RFID **Card** or **Tag** using the `ISO/IEC 14443A`_
interface, for example Mifare or NTAG203.
* One or two might be included with the Reader or *"starter kit"* already.
.. _protocol:
Protocols
---------
1. The micro controller and the reader use SPI for communication.
* The protocol is described in the `NXP MFRC522`_ datasheet.
* See the `Pin Layout`_ section for details on connecting the pins.
2. The reader and the tags communicate using a 13.56 MHz electromagnetic field.
* The protocol is defined in ISO/IEC 14443-3:2011 Part 3 Type A.
* Details are found in chapter 6 *"Type A – Initialization and anticollision"*.
* See http://wg8.de/wg8n1496_17n3613_Ballot_FCD14443-3.pdf for a free version
of the final draft (which might be outdated in some areas).
* The reader does not support ISO/IEC 14443-3 Type B.
.. _security:
Security
-------
This library only supports crypto1-encrypted communication. Crypto1 has been known as `broken`_ for a few years, so it does NOT offer ANY security, it is virtually unencrypted communication. **Do not use it for any security related applications!**
This library does not offer 3DES or AES authentication used by cars like the Mifare DESFire, it may be possible to be implemented because the datasheet says there is support. We hope for pull requests :).
.. _troubleshooting:
Troubleshooting
-------
* **I don't get input from reader** or **WARNING: Communication failure, is the MFRC522 properly connected?**
#. Check your connection, see `Pin Layout`_ .
#. Check voltage. Most breakouts work with 3.3V.
#. SPI only works with 3.3V, most breakouts seem 5V tollerant, but try a level shifter.
#. According to reports #101, #126 and #131, there may be a problem with the soldering on the MFRC522 breakout. You could fix this on your own.
* **Sometimes I get timeouts** or **sometimes tag/card does not work.**
#. Try other side of the antenna.
#. Try to decrease distance between MFRC522.
#. Increase antenna gain per firmware: ``mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max);``
#. Use better power supply.
#. Hardware may be corrupted, most products are from china and sometimes the quality is really poor. Contact your seller.
* **My tag/card doesn't work.**
#. Distance between antenna and token too large (>1cm).
#. You got the wrong type PICC. Is it really 13.56 MHz? Is it really a Mifare Type A?
#. NFC tokens are not supported. Some may work.
#. Animal RFID tags are not supported. They use a different frequency (125 kHz).
#. Hardware may be corrupted, most products are from china and sometimes the quality is really poor. Contact your seller.
#. Newer versions of Mifare cards like DESFire/Ultralight maybe not work according to missing authentification, see `security`_ or different `protocol`_.
* **My mobile phone doesn't recognize the MFRC522** or **my MFRC522 can't read data from other MFRC522**
#. Card simmulation is not supported.
#. Communication with mobile phones is not supported.
#. Peer to peer communication is not supported.
* **I need more features.**
#. If software: code it and make a pull request.
#. If hardware: buy a more expensive like PN532 (supports NFC and many more, but costs about $15)
.. _license:
License
-------
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to http://unlicense.org/
History
-------
The MFRC522 library was first created in Jan 2012 by Miguel Balboa (from
http://circuitito.com) based on code by Dr. Leong (from http://B2CQSHOP.com)
for *"Arduino RFID module Kit 13.56 Mhz with Tags SPI W and R By COOQRobot"*.
It was translated into English and rewritten/refactored in the fall of 2013
by Søren Thing Andersen (from http://access.thing.dk).
It has been extended with functionality to alter sector 0 on Chinese UID changeable MIFARE card in Oct 2014 by Tom Clement (from http://tomclement.nl).
.. _arduino: https://arduino.cc/
.. _ebay: http://www.ebay.com/
.. _iso/iec 14443a: https://en.wikipedia.org/wiki/ISO/IEC_14443
.. _iso/iec 14443-3\:2011 part 3:
.. _nxp mfrc522: http://www.nxp.com/documents/data_sheet/MFRC522.pdf
.. _broken: http://eprint.iacr.org/2008/166
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
\ No newline at end of file
11 Feb 2016, v1.1.8
- Added examples/MinimalInterrupt/MinimalInterrupt.ino example, Interrupt example @lmmeng
- Added .gitignore file allows the project to be more easily used as a subproject. @BenWiederhake
- Added Added Teensy 2.0 & Tensy++ 2.0 pinouts to README.rst @jkutianski
16 Jan 2016, v1.1.7
- README.rst Spelling and Grammar Tweak @cuthbertnibbles
- Added examples/servo_motor/servo_motor.ino example, Arduino RFID Access Control with a Servo Motor @techied
- Added examples/RFID-Cloner/RFID-Cloner.ino Copy from rfid cards with standard authentication @stefanblommaert
- Fix compile error at examples/RFID-Cloner/RFID-Cloner.ino, using MFRC522:::PICC_Type, @Rotzbua
06 Jan 2016, v1.1.6
- Fixed compilation error for examples/ReadNUID/ReadNUID.ino example. @Rotzbua
04 Jan 2016, v1.1.5
- Use settings functions on SPI libraries, setSPIConfig was deleted, now the library use SPI.beginTransaction() and SPI.endTransaction() @sophiekovalevsky
- Added examples/ReadNUID/ReadNUID.ino example, showing how to read new NUID from a PICC to serial. @sophiekovalevsky
03 Jan 2016, v1.1.4
- Added Authentication with Ntag 213,215,216 returns the pACK MFRC522::PCD_NTAG216_AUTH @Gargantuanman
- Starting to use versions http://semver.org/
- Continuous Integration @ivankravets
- functions return MFRC522::StatusCode and MFRC522::PICC_Type instead of generic byte @rotzbua
- removed int-values of MFRC522::StatusCode and MFRC522::PICC_Type @rotzbua
05 Dec 2015
- recognize infineon cards correctly @mayatforest
- added multi reader support, see example @lmmeng
10 Nov 2014
- Updated the changelog.
- Added makefile.
24 Oct 2014
- Added PlatformIO-based manifest file.
17 Jul 2014
- Written documentation for the library.
- Added rfid_default_keys example.
11 Jun 2014
- Updated example: ReadAndWrite.
14 Apr 2014
- Updated examples: DumpInfo, MifareClassicValueBlock, and ReadAndWrite.
12 Feb 2014
- Fixed resetPowerDownPin initial state.
29 Jan 2014
- Fixed chipSelectPin initial state.
30 Nov 2013
- Examples put in their own folders.
- Updated the keywords.txt file.
12 Nov 2013
- Updated examples: DumpInfo, MifareClassicValueBlock, and ReadAndWrite.
20 Oct 2013
- All constants, functions and parameters are now commented in English.
- Code refactored, most function names have changed.
- Support ISO-14443-3 anti collission and 4/7/10 byte UIDs (cascade levels).
- Added functions for MIFARE Classic Decrement/Increment/Restore/Transfer
and MIFARE Ultralight Write.
- New examples written.
19 Oct 2013
- Renamed library from RFID to MFRC522 (RFID seemed to generic).
- Register names changed to comply with datasheet.
- Global defines moved into class.
24 Sep 2013
- Turn off encryption when tag is halted.
27 Jan 2013
- Added README and small TODO list.
- Added example to show Serial on LCD display.
09 Sep 2012
- Initial commit to GitHub.
/*
* --------------------------------------------------------------------------------------------------------------------
* Example to change UID of changeable MIFARE card.
* --------------------------------------------------------------------------------------------------------------------
* This is a MFRC522 library example; for further details and other examples see: https://github.com/miguelbalboa/rfid
*
* This sample shows how to set the UID on a UID changeable MIFARE card.
* NOTE: for more informations read the README.rst
*
* @author Tom Clement
* @license Released into the public domain.
*
* Typical pin layout used:
* -----------------------------------------------------------------------------------------
* MFRC522 Arduino Arduino Arduino Arduino Arduino
* Reader/PCD Uno Mega Nano v3 Leonardo/Micro Pro Micro
* Signal Pin Pin Pin Pin Pin Pin
* -----------------------------------------------------------------------------------------
* RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
* SPI SS SDA(SS) 10 53 D10 10 10
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
*/
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
/* Set your new UID here! */
#define NEW_UID {0xDE, 0xAD, 0xBE, 0xEF}
MFRC522::MIFARE_Key key;
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println(F("Warning: this example overwrites the UID of your UID changeable card, use with care!"));
// Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
}
// Setting the UID can be as simple as this:
//void loop() {
// byte newUid[] = NEW_UID;
// if ( mfrc522.MIFARE_SetUid(newUid, (byte)4, true) ) {
// Serial.println("Wrote new UID to card.");
// }
// delay(1000);
//}
// But of course this is a more proper approach
void loop() {
// Look for new cards, and select one if present
if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
delay(50);
return;
}
// Now a card is selected. The UID and SAK is in mfrc522.uid.
// Dump UID
Serial.print(F("Card UID:"));
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
}
Serial.println();
// Dump PICC type
// MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
// Serial.print(F("PICC type: "));
// Serial.print(mfrc522.PICC_GetTypeName(piccType));
// Serial.print(F(" (SAK "));
// Serial.print(mfrc522.uid.sak);
// Serial.print(")\r\n");
// if ( piccType != MFRC522::PICC_TYPE_MIFARE_MINI
// && piccType != MFRC522::PICC_TYPE_MIFARE_1K
// && piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
// Serial.println(F("This sample only works with MIFARE Classic cards."));
// return;
// }
// Set new UID
byte newUid[] = NEW_UID;
if ( mfrc522.MIFARE_SetUid(newUid, (byte)4, true) ) {
Serial.println(F("Wrote new UID to card."));
}
// Halt PICC and re-select it so DumpToSerial doesn't get confused
mfrc522.PICC_HaltA();
if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
return;
}
// Dump the new memory contents
Serial.println(F("New UID and contents:"));
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
delay(2000);
}
/*
* --------------------------------------------------------------------------------------------------------------------
* Example sketch/program showing how to read data from a PICC to serial.
* --------------------------------------------------------------------------------------------------------------------
* This is a MFRC522 library example; for further details and other examples see: https://github.com/miguelbalboa/rfid
*
* Example sketch/program showing how to read data from a PICC (that is: a RFID Tag or Card) using a MFRC522 based RFID
* Reader on the Arduino SPI interface.
*
* When the Arduino and the MFRC522 module are connected (see the pin layout below), load this sketch into Arduino IDE
* then verify/compile and upload it. To see the output: use Tools, Serial Monitor of the IDE (hit Ctrl+Shft+M). When
* you present a PICC (that is: a RFID Tag or Card) at reading distance of the MFRC522 Reader/PCD, the serial output
* will show the ID/UID, type and any data blocks it can read. Note: you may see "Timeout in communication" messages
* when removing the PICC from reading distance too early.
*
* If your reader supports it, this sketch/program will read all the PICCs presented (that is: multiple tag reading).
* So if you stack two or more PICCs on top of each other and present them to the reader, it will first output all
* details of the first and then the next PICC. Note that this may take some time as all data blocks are dumped, so
* keep the PICCs at reading distance until complete.
*
* @license Released into the public domain.
*
* Typical pin layout used:
* -----------------------------------------------------------------------------------------
* MFRC522 Arduino Arduino Arduino Arduino Arduino
* Reader/PCD Uno Mega Nano v3 Leonardo/Micro Pro Micro
* Signal Pin Pin Pin Pin Pin Pin
* -----------------------------------------------------------------------------------------
* RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
* SPI SS SDA(SS) 10 53 D10 10 10
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
*/
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
/*
* --------------------------------------------------------------------------------------------------------------------
* Example sketch/program to fix a broken UID changeable MIFARE cards.
* --------------------------------------------------------------------------------------------------------------------
* This is a MFRC522 library example; for further details and other examples see: https://github.com/miguelbalboa/rfid
*
* This sample shows how to fix a broken UID changeable MIFARE cards that have a corrupted sector 0.
*
* @author Tom Clement
* @license Released into the public domain.
*
* Typical pin layout used:
* -----------------------------------------------------------------------------------------
* MFRC522 Arduino Arduino Arduino Arduino Arduino
* Reader/PCD Uno Mega Nano v3 Leonardo/Micro Pro Micro
* Signal Pin Pin Pin Pin Pin Pin
* -----------------------------------------------------------------------------------------
* RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
* SPI SS SDA(SS) 10 53 D10 10 10
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
*/
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
MFRC522::MIFARE_Key key;
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println(F("Warning: this example clears your mifare UID, use with care!"));
// Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
}
void loop() {
if ( mfrc522.MIFARE_UnbrickUidSector(false) ) {
Serial.println(F("Cleared sector 0, set UID to 1234. Card should be responsive again now."));
}
delay(1000);
}
/**
* ----------------------------------------------------------------------------
* This is a MFRC522 library example; see https://github.com/miguelbalboa/rfid
* for further details and other examples.
*
* NOTE: The library file MFRC522.h has a lot of useful info. Please read it.
*
* Released into the public domain.
* ----------------------------------------------------------------------------
* This sample shows how to setup blocks on a MIFARE Classic PICC (= card/tag)
* to be in "Value Block" mode: in this mode the operations Increment/Decrement,
* Restore and Transfer can be used.
*
* BEWARE: Data will be written to the PICC, in sector #1 (blocks #4 to #7).
*
*
* Typical pin layout used: