-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
482 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# RFIDtoEEPROM | ||
|
||
<p align="left"> | ||
<a href="https://github.com/GogoVega/RFIDtoEEPROM/releases/latest"> | ||
<img src="https://img.shields.io/github/v/release/GogoVega/RFIDtoEEPROM.svg?include_prereleases" alt="GitHub Release Version" /> | ||
</a> | ||
<a href="https://registry.platformio.org/libraries/gogovega/RFID to EEPROM"> | ||
<img src="https://badges.registry.platformio.org/packages/gogovega/library/RFID to EEPROM.svg" alt="PlatformIO Registry" /> | ||
</a> | ||
<a href="https://discord.gg/rYgzexA9u4"> | ||
<img src="https://img.shields.io/discord/928317454516641802?color=8ed6fb&label=Discord&logo=discord" alt="ArduiChar Discord" /> | ||
</a> | ||
</p> | ||
|
||
Library to write an RFID Code in the [EEPROM](https://docs.arduino.cc/learn/built-in-libraries/eeprom) in order to check if the Code corresponds to a Code already saved. | ||
|
||
## Feature | ||
|
||
- Compatibility with I2C EEPROM. | ||
|
||
## Usage | ||
|
||
This library is used for saving an RFID Code to your Arduino's **internal EEPROM** rather than your Code to avoid **showing your RFID Code**. To then check if the Code corresponds to a Code already registered. | ||
|
||
## How To Use | ||
|
||
Go to the Libraries Manager on [PlatformIO](https://platformio.org/platformio-ide) and search for `RFID to EEPROM`. Then you just have to install it in your project. | ||
|
||
![PlatformIO](https://raw.githubusercontent.com/GogoVega/RFIDtoEEPROM/master/docs/platformio.png) | ||
|
||
Or use `platformIO Core CLI` and paste the following command: | ||
|
||
```bash | ||
pio lib install "gogovega/RFID to EEPROM@^1.0.0" | ||
``` | ||
|
||
## How It Works | ||
|
||
This library contains several functions: | ||
| Name | Description | | ||
|---|---| | ||
| `CardNumber()` | Returns the number of Cards already registered. | | ||
| `SaveCard()` | Stores the RFID Code of a Card in the EEPROM. Returns `true` if the write succeeds. Otherwise returns `false` and restores the old Card. | | ||
| `CardCheck()` | Checks if the Code received corresponds to a Code already stored in the EEPROM. Returns `true` if a Card matches. | | ||
| `ClearCardNumber()` | Resets the number of recorded Cards to 0. | | ||
| `EraseAllCards()` | Resets all Cards to 0. | | ||
| `MaxCards()` | Returns the maximum number of recordable Cards. Currently **set to 255**. | | ||
|
||
**Note:** The EEPROM memory has a specified life of 100,000 write/erase cycles, so you may need to be careful about how often you write to it. | ||
|
||
## License | ||
|
||
MIT |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* This library is used to save an RFID Code in the EEPROM and Check if the Code | ||
* corresponds to a Code already saved. | ||
* | ||
* It can be very useful if you use an RFID reader to lock / unlock your Arduino. | ||
* | ||
* This is a basic example that will allow you to: | ||
* - Know the Number of registered Cards | ||
* - Save a New Card to EEPROM | ||
* - Check if the Code provided corresponds to a Code already saved | ||
* - Reset the Number of Cards to 0 | ||
* - Erase all Cards. | ||
* | ||
* Warning: you must use the same number of bytes in your functions as defined | ||
* in the constructor! | ||
* | ||
* Create april 2022 | ||
* | ||
* Copyright (c) 2022 Gauthier Dandele | ||
* | ||
* MIT License | ||
*/ | ||
|
||
#include <RFIDtoEEPROM.h> | ||
|
||
#define NUMBYTES 4 | ||
// By default, the Number of Bytes of ID = 4 | ||
RFIDtoEEPROM myCard(NUMBYTES); | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
|
||
// Erase all Cards | ||
// myCard.EraseAllCards(); | ||
|
||
// Reset the Number of Cards | ||
myCard.ClearCardNumber(); | ||
|
||
// Print the Number of Saved Cards | ||
Serial.print("Number of Saved Cards: "); | ||
Serial.println(myCard.CardNumber()); | ||
|
||
// Print the Number of Recordable Cards | ||
Serial.print("Number of Recordable Cards: "); | ||
Serial.println(myCard.MaxCards()); | ||
|
||
// Register a new Card | ||
byte Code[4] = {217, 90, 119, 158}; | ||
Serial.print("UID Cards is: "); | ||
Serial.print(Code[0], HEX); | ||
Serial.print(Code[1], HEX); | ||
Serial.print(Code[2], HEX); | ||
Serial.println(Code[3], HEX); | ||
|
||
Serial.println("Card registration..."); | ||
|
||
if (myCard.SaveCard(Code)) { | ||
Serial.println("Card saved successfully"); | ||
} else { | ||
Serial.println("Failure during writing!"); | ||
} | ||
|
||
// Print the Number of Saved Cards | ||
Serial.print("Number of Saved Cards: "); | ||
Serial.println(myCard.CardNumber()); | ||
|
||
Serial.println("Checking Card Matches..."); | ||
|
||
// Checks if the Card Matches | ||
if (myCard.CardCheck(Code)) { | ||
Serial.println("The Card Matches"); | ||
} else { | ||
Serial.println("The Card Not Matches!"); | ||
} | ||
} | ||
|
||
void loop() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* This library is used to save an RFID Code in the EEPROM and Check if the Code | ||
* corresponds to a Code already saved. | ||
* | ||
* It can be very useful if you use an RFID reader to lock / unlock your Arduino. | ||
* | ||
* This is an example with MFRC522 library to retrieve the Code from your Card. | ||
* | ||
* A button will be used to request a Card recording. | ||
* | ||
* Typical pin layout used: | ||
* ----------------------------------------------------------------------------------------- | ||
* MFRC522 Arduino Arduino Arduino Arduino Arduino | ||
* Reader/PCD Uno/101 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 | ||
* | ||
* More pin layouts for other boards can be found here: https://github.com/miguelbalboa/rfid#pin-layout | ||
* | ||
* | ||
* Warning: you must use the same number of bytes in your functions as defined | ||
* in the constructor! | ||
* | ||
* Create april 2022 | ||
* | ||
* Copyright (c) 2022 Gauthier Dandele | ||
* | ||
* MIT License | ||
*/ | ||
|
||
#include <MFRC522.h> | ||
#include <RFIDtoEEPROM.h> | ||
|
||
#define SS_PIN 6 | ||
#define RST_PIN 7 | ||
#define BUTTONPIN 8 | ||
|
||
MFRC522 rfid(SS_PIN, RST_PIN); | ||
|
||
// By default, the Number of Bytes of ID = 4 | ||
RFIDtoEEPROM myCard; | ||
|
||
byte Code[4]; | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
|
||
SPI.begin(); | ||
rfid.PCD_Init(); | ||
|
||
// Reset the Number of Cards | ||
// myCard.ClearCardNumber(); | ||
|
||
// Erase all Cards | ||
// myCard.EraseAllCards(); | ||
} | ||
|
||
void loop() { | ||
if (rfid.PICC_IsNewCardPresent()) { | ||
if (rfid.PICC_ReadCardSerial()) { | ||
for (int i = 0; i < 4; i++) { | ||
Code[i] = rfid.uid.uidByte[i]; | ||
} | ||
|
||
Serial.println("Card Detected"); | ||
|
||
Serial.print("Number of Saved Cards: "); | ||
Serial.println(myCard.CardNumber()); | ||
|
||
Serial.print("UID Cards is: "); | ||
Serial.print(Code[0], HEX); | ||
Serial.print(Code[1], HEX); | ||
Serial.print(Code[2], HEX); | ||
Serial.println(Code[3], HEX); | ||
|
||
if (digitalRead(BUTTONPIN)) { | ||
Serial.println("Registration Request"); | ||
Serial.println("Registration..."); | ||
|
||
if (myCard.SaveCard(Code)) { | ||
Serial.println("New Card Saved"); | ||
Serial.print("Number of Saved Cards: "); | ||
Serial.println(myCard.CardNumber()); | ||
} else { | ||
Serial.println("Failure during writing!"); | ||
Serial.println("Start Again..."); | ||
} | ||
} else { | ||
if (!myCard.CardNumber()) { | ||
Serial.println("No Card added!"); | ||
} else { | ||
Serial.println("Checking Card Matches..."); | ||
|
||
if (myCard.CardCheck(Code)) { | ||
Serial.println("Card Matches"); | ||
} else { | ||
Serial.println("Card Not Matches!"); | ||
} | ||
} | ||
} | ||
|
||
Serial.println(); | ||
|
||
rfid.PICC_HaltA(); | ||
rfid.PCD_StopCrypto1(); | ||
} | ||
} | ||
|
||
delay(50); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "RFID to EEPROM", | ||
"version": "1.0.0", | ||
"description": "Library to write an RFID code in the EEPROM in order to check if the code corresponds to a code already saved.", | ||
"keywords": ["rfid", "eeprom"], | ||
"repository": | ||
{ | ||
"type": "git", | ||
"url": "https://github.com/GogoVega/RFIDtoEEPROM.git" | ||
}, | ||
"authors": | ||
{ | ||
"name": "Gauthier Dandele", | ||
"url": "https://github.com/GogoVega", | ||
"maintainer": true | ||
}, | ||
"license": "MIT", | ||
"frameworks": "arduino", | ||
"platforms": "atmelavr" | ||
} |
Oops, something went wrong.