From 5ada448fc988c3d1e92e7f87c208caa38b7549ba Mon Sep 17 00:00:00 2001 From: Henri de Jong Date: Sun, 6 Jan 2013 19:55:06 +0100 Subject: [PATCH 1/5] A few changes in the examplescript, and renamed it. --- examples/cardRead/cardRead.ino | 94 ++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 examples/cardRead/cardRead.ino diff --git a/examples/cardRead/cardRead.ino b/examples/cardRead/cardRead.ino new file mode 100644 index 0000000..3c128ac --- /dev/null +++ b/examples/cardRead/cardRead.ino @@ -0,0 +1,94 @@ +/** +* Read a card using a mfrc522 reader on your SPI interface +* Pin layout should be as follows (on Arduino Uno): +* MOSI: Pin 11 / ICSP-4 +* MISO: Pin 12 / ICSP-1 +* SCK: Pin 13 / ISCP-3 +* SS: Pin 10 +* RST: Pin 5 +* +* Script is based on the script of Miguel Balboa. +* New cardnumber is printed when card has changed. Only a dot is printed +* if card is the same. +* +* @version 0.1 +* @author Henri de Jong +* @since 06-01-2013 +*/ + +#include +#include + +#define SS_PIN 10 +#define RST_PIN 5 + +RFID rfid(SS_PIN, RST_PIN); + +// Setup variables: + int serNum0; + int serNum1; + int serNum2; + int serNum3; + int serNum4; + +void setup() +{ + Serial.begin(9600); + SPI.begin(); + rfid.init(); + +} + +void loop() +{ + + if (rfid.isCard()) { + if (rfid.readCardSerial()) { + if (rfid.serNum[0] != serNum0 + && rfid.serNum[1] != serNum1 + && rfid.serNum[2] != serNum2 + && rfid.serNum[3] != serNum3 + && rfid.serNum[4] != serNum4 + ) { + Serial.println(" "); + Serial.println("Card found"); + serNum0 = rfid.serNum[0]; + serNum1 = rfid.serNum[1]; + serNum2 = rfid.serNum[2]; + serNum3 = rfid.serNum[3]; + serNum4 = rfid.serNum[4]; + + //Serial.println(" "); + Serial.println("Cardnumber:"); + Serial.print("Dec: "); + Serial.print(rfid.serNum[0],DEC); + Serial.print(", "); + Serial.print(rfid.serNum[1],DEC); + Serial.print(", "); + Serial.print(rfid.serNum[2],DEC); + Serial.print(", "); + Serial.print(rfid.serNum[3],DEC); + Serial.print(", "); + Serial.print(rfid.serNum[4],DEC); + Serial.println(" "); + + Serial.print("Hex: "); + Serial.print(rfid.serNum[0],HEX); + Serial.print(", "); + Serial.print(rfid.serNum[1],HEX); + Serial.print(", "); + Serial.print(rfid.serNum[2],HEX); + Serial.print(", "); + Serial.print(rfid.serNum[3],HEX); + Serial.print(", "); + Serial.print(rfid.serNum[4],HEX); + Serial.println(" "); + } else { + Serial.print("."); + } + } + } + + rfid.halt(); +} + From d02a05cd22c754c2bd8cefc29339014ce628170d Mon Sep 17 00:00:00 2001 From: Henri de Jong Date: Mon, 7 Jan 2013 14:14:18 -0800 Subject: [PATCH 2/5] Create README.md --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..c148c11 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +rfid +==== + +Arduino RFID Library for MFRC522 + +Read a card using a mfrc522 reader on your SPI interface on your Arduino +* Pin layout should be as follows (on Arduino Uno): +* MOSI: Pin 11 / ICSP-4 +* MISO: Pin 12 / ICSP-1 +* SCK: Pin 13 / ISCP-3 +* SS: Pin 10 (Configurable) +* RST: Pin 5 (Configurable) From 8bfb620e421b4a74a7144a81d2878d502856dc4b Mon Sep 17 00:00:00 2001 From: Henri de Jong Date: Sun, 27 Jan 2013 18:11:28 +0100 Subject: [PATCH 3/5] Added extra example to show serial on lcd display --- examples/cardDisplay/cardDisplay.ino | 126 +++++++++++++++++++++++++++ examples/cardRead/cardRead.ino | 6 +- 2 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 examples/cardDisplay/cardDisplay.ino diff --git a/examples/cardDisplay/cardDisplay.ino b/examples/cardDisplay/cardDisplay.ino new file mode 100644 index 0000000..7fb22f3 --- /dev/null +++ b/examples/cardDisplay/cardDisplay.ino @@ -0,0 +1,126 @@ +/** +* Read a card using a mfrc522 reader on your SPI interface +* Pin layout should be as follows (on Arduino Uno): +* MOSI: Pin 11 / ICSP-4 +* MISO: Pin 12 / ICSP-1 +* SCK: Pin 13 / ISCP-3 +* SS: Pin 10 +* RST: Pin 9 +* +* Script is based on the script of Miguel Balboa. +* Serial number is shown on a HD44780 compatible display +* +* The circuit: +* LCD RS pin to digital pin (7) +* LCD Enable pin to digital pin (6) +* LCD D4 pin to digital pin 5 +* LCD D5 pin to digital pin 4 +* LCD D6 pin to digital pin 3 +* LCD D7 pin to digital pin 2 +* LCD R/W pin to ground +* 10K resistor: +* ends to +5V and ground +* wiper to LCD VO pin (pin 3) +* +* @version 0.1 +* @author Henri de Jong +* @since 27-01-2013 +*/ + +#include +#include +#include + +#define SS_PIN 10 +#define RST_PIN 9 + +RFID rfid(SS_PIN, RST_PIN); + +LiquidCrystal lcd(7, 6, 5, 4, 3, 2); + +// Setup variables: + int serNum0; + int serNum1; + int serNum2; + int serNum3; + int serNum4; + +void setup() +{ + Serial.begin(9600); + lcd.begin(16, 2); + SPI.begin(); + rfid.init(); + +} + +void loop() +{ + + if (rfid.isCard()) { + if (rfid.readCardSerial()) { + if (rfid.serNum[0] != serNum0 + && rfid.serNum[1] != serNum1 + && rfid.serNum[2] != serNum2 + && rfid.serNum[3] != serNum3 + && rfid.serNum[4] != serNum4 + ) { + /* With a new cardnumber, show it. */ + Serial.println(" "); + Serial.println("Card found"); + serNum0 = rfid.serNum[0]; + serNum1 = rfid.serNum[1]; + serNum2 = rfid.serNum[2]; + serNum3 = rfid.serNum[3]; + serNum4 = rfid.serNum[4]; + + //Serial.println(" "); + Serial.println("Cardnumber:"); + Serial.print("Dec: "); + Serial.print(rfid.serNum[0],DEC); + Serial.print(", "); + Serial.print(rfid.serNum[1],DEC); + Serial.print(", "); + Serial.print(rfid.serNum[2],DEC); + Serial.print(", "); + Serial.print(rfid.serNum[3],DEC); + Serial.print(", "); + Serial.print(rfid.serNum[4],DEC); + Serial.println(" "); + + Serial.print("Hex: "); + Serial.print(rfid.serNum[0],HEX); + Serial.print(", "); + Serial.print(rfid.serNum[1],HEX); + Serial.print(", "); + Serial.print(rfid.serNum[2],HEX); + Serial.print(", "); + Serial.print(rfid.serNum[3],HEX); + Serial.print(", "); + Serial.print(rfid.serNum[4],HEX); + Serial.println(" "); + + /* Write the HEX code to the display */ + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Cardno (hex):"); + lcd.setCursor(0,1); + lcd.print(rfid.serNum[0], HEX); + lcd.print(','); + lcd.print(rfid.serNum[1], HEX); + lcd.print(','); + lcd.print(rfid.serNum[2], HEX); + lcd.print(','); + lcd.print(rfid.serNum[3], HEX); + lcd.print(','); + lcd.print(rfid.serNum[4], HEX); + } else { + /* If we have the same ID, just write a dot. */ + Serial.print("."); + } + } + } + + rfid.halt(); +} + diff --git a/examples/cardRead/cardRead.ino b/examples/cardRead/cardRead.ino index 3c128ac..4a53eca 100644 --- a/examples/cardRead/cardRead.ino +++ b/examples/cardRead/cardRead.ino @@ -5,7 +5,7 @@ * MISO: Pin 12 / ICSP-1 * SCK: Pin 13 / ISCP-3 * SS: Pin 10 -* RST: Pin 5 +* RST: Pin 9 * * Script is based on the script of Miguel Balboa. * New cardnumber is printed when card has changed. Only a dot is printed @@ -20,7 +20,7 @@ #include #define SS_PIN 10 -#define RST_PIN 5 +#define RST_PIN 9 RFID rfid(SS_PIN, RST_PIN); @@ -50,6 +50,7 @@ void loop() && rfid.serNum[3] != serNum3 && rfid.serNum[4] != serNum4 ) { + /* With a new cardnumber, show it. */ Serial.println(" "); Serial.println("Card found"); serNum0 = rfid.serNum[0]; @@ -84,6 +85,7 @@ void loop() Serial.print(rfid.serNum[4],HEX); Serial.println(" "); } else { + /* If we have the same ID, just write a dot. */ Serial.print("."); } } From f5a654eb4a6b557ce4562e8d98b9aa05f4dddb02 Mon Sep 17 00:00:00 2001 From: Henri de Jong Date: Sun, 27 Jan 2013 19:28:06 +0100 Subject: [PATCH 4/5] Added a small todo list --- TODO.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 TODO.md diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..5e936bf --- /dev/null +++ b/TODO.md @@ -0,0 +1,6 @@ +TODO: + +Create Examples: +- Read more stuff than the serial number +- Write to a card +- Do some ethernet stuff (with an ethernet module) From 4fb35513573d7871656f4fb993140d470b91649b Mon Sep 17 00:00:00 2001 From: Henri de Jong Date: Sun, 27 Jan 2013 19:30:09 +0100 Subject: [PATCH 5/5] Update README.md Change RST pin --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c148c11..0ab1546 100644 --- a/README.md +++ b/README.md @@ -9,4 +9,4 @@ Read a card using a mfrc522 reader on your SPI interface on your Arduino * MISO: Pin 12 / ICSP-1 * SCK: Pin 13 / ISCP-3 * SS: Pin 10 (Configurable) -* RST: Pin 5 (Configurable) +* RST: Pin 9 (Configurable)