Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- --------------------------------------------------------------------------------------------------------------------
- Example sketch/program showing how to read data from more than one 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 more than one PICC (that is: a RFID Tag or Card) using a
- MFRC522 based RFID Reader on the Arduino SPI interface.
- Warning: This may not work! Multiple devices at one SPI are difficult and cause many trouble!! Engineering skill
- and knowledge are required!
- @license Released into the public domain.
- 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 1 SDA(SS) ** custom, take a unused pin, only HIGH/LOW required *
- SPI SS 2 SDA(SS) ** custom, take a unused pin, only HIGH/LOW required *
- SPI MOSI(g) MOSI 11 / ICSP-4 51 D11 ICSP-4 16
- SPI MISO(b) 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>
- #include <stdio.h>
- #include <string.h>
- #define RST_PIN 9 //black // Configurable, see typical pin layout above
- #define SS_1_PIN 10 //orange // gelb Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2
- #define SS_2_PIN 14 //brown //8 // blau
- // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1
- #define NR_OF_READERS 2
- byte ssPins[] = {SS_1_PIN, SS_2_PIN};
- byte patent1[18] = {4, 70, 78, 106, 106, 95};
- byte patent2[18] = {4, 30, 78, 106, 106, 95};
- byte waben1[18] = {4, 226, 79, 106, 106, 95};
- byte waben2[18] = {4, 112, 79, 106, 106, 95};
- byte fisch1[18] = {4, 104, 78, 106, 106, 95};
- byte fisch2[18] = {4, 103, 78, 106, 106, 95};
- bool patenta = true;
- bool patentb = true;
- bool fischa = true;
- bool fischb = true;
- bool wabena = true;
- bool wabenb = true;
- MFRC522 mfrc522[NR_OF_READERS]; // Create MFRC522 instance.
- /**
- Initialize.
- */
- 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
- for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
- mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
- Serial.print(F("Reader "));
- Serial.print(reader);
- Serial.print(F(": "));
- mfrc522[reader].PCD_DumpVersionToSerial();
- }
- }
- void dump_byte_array(byte *buffer, byte bufferSize) {
- for (byte i = 0; i < bufferSize; i++) {
- Serial.print(buffer[i] < 0x10 ? " 0" : " ");
- Serial.print(buffer[i], HEX);
- }
- }
- /**
- Main loop.
- */
- void loop() {
- bool patenta = true;
- bool patentb = true;
- bool fischa = true;
- bool fischb = true;
- bool wabena = true;
- bool wabenb = true;
- // Look for new cards
- if (mfrc522[0].PICC_IsNewCardPresent() && mfrc522[0].PICC_ReadCardSerial() && mfrc522[1].PICC_IsNewCardPresent() && mfrc522[1].PICC_ReadCardSerial()) {
- //READER 1
- Serial.print(F("Reader 0"));
- // Show some details of the PICC (that is: the tag/card)
- Serial.print(F(": Card UID:"));
- dump_byte_array(mfrc522[0].uid.uidByte, mfrc522[0].uid.size);
- Serial.println();
- // Try the known default keys
- MFRC522::MIFARE_Key key;
- // Copy the known key into the MIFARE_Key structure
- for (byte i = 0; i < MFRC522::MF_KEY_SIZE; i++) {
- // Serial.println(mfrc522[reader].uid.uidByte[i]); //einkommentieren zum auslesen der tags
- //abfrage patent
- if (mfrc522[0].uid.uidByte[i] != patent1[i] && mfrc522[1].uid.uidByte[i] != patent1[i]) {
- patenta = false;
- }
- if (mfrc522[0].uid.uidByte[i] != patent2[i] && mfrc522[1].uid.uidByte[i] != patent2[i]) {
- patentb = false;
- }
- //abfrage fisch
- if (mfrc522[0].uid.uidByte[i] != fisch1[i] && mfrc522[1].uid.uidByte[i] != fisch1[i]) {
- fischa = false;
- }
- if (mfrc522[0].uid.uidByte[i] != fisch2[i] && mfrc522[1].uid.uidByte[i] != fisch2[i]) {
- fischb = false;
- }
- //abfrage waben
- if (mfrc522[0].uid.uidByte[i] != waben1[i] && mfrc522[1].uid.uidByte[i] != waben1[i]) {
- wabena = false;
- }
- if (mfrc522[0].uid.uidByte[i] != waben2[i] && mfrc522[1].uid.uidByte[i] != waben2[i]) {
- wabenb = false;
- }
- }
- // Halt PICC
- mfrc522[0].PICC_HaltA();
- // Stop encryption on PCD
- mfrc522[0].PCD_StopCrypto1();
- //READER2
- // Show some details of the PICC (that is: the tag/card)
- Serial.print(F("Reader 1"));
- Serial.print(F(": Card UID:"));
- dump_byte_array(mfrc522[1].uid.uidByte, mfrc522[1].uid.size);
- Serial.println();
- for (byte i = 0; i < MFRC522::MF_KEY_SIZE; i++) {
- // Serial.println(mfrc522[reader].uid.uidByte[i]); //einkommentieren zum auslesen der tags
- // übergabe an serial port
- if (patenta == true && patentb == true) {
- Serial.println("Ausgewähltes Modell: Patent");
- break;
- }
- if (fischa == true && fischb == true) {
- Serial.println("Ausgewähltes Modell: Fisch");
- break;
- }
- if (wabena == true && wabenb == true) {
- Serial.println("Ausgewähltes Modell: Waben");
- break;
- }
- else {
- Serial.println("Fehler");
- return;
- }
- }
- }
- else {
- //Serial.println("Es konnten keine zwei Gabelzinken erkannt werden");
- return;
- }
- // Halt PICC
- mfrc522[1].PICC_HaltA();
- // Stop encryption on PCD
- mfrc522[1].PCD_StopCrypto1();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement