i have a question bout MFRC522, how can i counting RFID TAG in each Readers?
For example i have two rfid readers(reader 0 and reader 1) and i have two variables (count0 and count1), count0 for counting tag in readers 0 and count1 for counting tag in readers 1. Then i scan one tag in readers 0 so at count0 it will be 1, and in count1 it will be 0 (because i only scan in readers 0), it does in readers 1 too.
I also tried so hard(bcs im newbie in arduino) but i also failed:(
Pleaseee helpppp its for my final project in my college:(
i use the code from mfrc522 library examples.
/**
* --------------------------------------------------------------------------------------------------------------------
* 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 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_1_PIN 10 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2
#define SS_2_PIN 8 // 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};
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();
}
}
/**
* Main loop.
*/
void loop() {
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
// Look for new cards
if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
Serial.print(F("Reader "));
Serial.print(reader);
// Show some details of the PICC (that is: the tag/card)
Serial.print(F(": Card UID:"));
dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
Serial.println();
Serial.print(F("PICC type: "));
MFRC522::PICC_Type piccType = mfrc522[reader].PICC_GetType(mfrc522[reader].uid.sak);
Serial.println(mfrc522[reader].PICC_GetTypeName(piccType));
mfrc522[reader].PICC_DumpToSerial(&(mfrc522[reader].uid));
// Halt PICC
mfrc522[reader].PICC_HaltA();
// Stop encryption on PCD
mfrc522[reader].PCD_StopCrypto1();
} //if (mfrc522[reader].PICC_IsNewC
} //for(uint8_t reader
}
/**
* Helper routine to dump a byte array as hex values to Serial.
*/
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);
}
}
blh64:
You sketch (which I assume it completely from somewhere else) does not contain a variable called 'count0' or a variable called 'count1'
What is the output of the sketch you posted? Are there 2 RFID readers present with different information?
oh yes, i mean, i wanna create the count0 and count1 variables but i don’t know how to implement that (ive tried couple times but i always failed and i deleted that code:/ ). So in here i give the Examples (from library mfrc522) code as the template that i used for.
blh64:
BS. Don't delete your failed attempts. Post them here and we can help. If you want someone to do it for you, hire a programmer
ahh!! i found my code, but in this code i use array for the counter. In this case, when i scan rfid tag into readers 0 the variable counters[0] will be increasing into 1 and the second times i scan rfid tag into readers 1 the variable counters[1] will be increasing into 2(its increased from counters[0]).
As i wish for the help i want each counter to counting every readers one by one, but the program that i made always counting all the readers, here i attach the serial monitor if u confused of my explanation :D.
/**
* --------------------------------------------------------------------------------------------------------------------
* 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 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 <Wire.h>
#include <SPI.h>
#include <MFRC522.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h> //library penampil LCD
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_1_PIN 10 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2
#define SS_2_PIN 8 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1
#define NR_OF_READERS 2
LiquidCrystal_I2C lcd(0x27,20,4); //0x3f dapat dicari dengan i2c scanner
SoftwareSerial s(5,6);
byte ssPins[] = {SS_1_PIN, SS_2_PIN};
MFRC522 mfrc522[NR_OF_READERS]; // Create MFRC522 instance.
int i = 1;
byte code[10];
int counter[NR_OF_READERS] = {0,0};
//int counter_1 = 0;
String uidString;
//char* reader0[10][13];
//char* reader1[10][13];
//int count0 = 1;
//int count1 = 1;
/**
* Initialize.
*/
void setup() {
s.begin(115200);
Serial.begin(115200); // Initialize serial communications with the PC
while (!Serial);
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();
}
lcd.init();
lcd.init();
lcd.backlight(); //menghidupkan lampu latar LCD
// mfrc522.PCD_Init(); // Init MFRC522
lcd.setCursor (3,0);
lcd.print("Final Project");
delay (2000);
lcd.clear();
}
/**
* Main loop.
*/
void loop() {
lcd.setCursor (0,0);
lcd.print("SCAN RFID");
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
// Look for new cards
// uint8_t reader = 0;
// while(NR_OF_READERS == 0){
if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
Serial.println();
Serial.print(F("Reader "));
Serial.print(reader);
// Show some details of the PICC (that is: the tag/card)
Serial.print(F(": Card UID:"));
dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
Serial.println();
Serial.print(F("PICC type: "));
MFRC522::PICC_Type piccType = mfrc522[reader].PICC_GetType(mfrc522[reader].uid.sak);
Serial.println(mfrc522[reader].PICC_GetTypeName(piccType));
counter[reader] = i++;
lcd.setCursor (0,0);
// lcd.setCursor(0,1);
// lcd.print(counter);
Serial.print("Counter ");
Serial.print(reader);
Serial.print(" : ");
Serial.print(counter[reader]);
// s.write(counter);
// Halt PICC
}
mfrc522[reader].PICC_HaltA();
// Stop encryption on PCD
mfrc522[reader].PCD_StopCrypto1();
// counter = counter-counter;
}
//if (mfrc522[reader].PICC_IsNewC
//for(uint8_t reader
}
/**
* Helper routine to dump a byte array as hex values to Serial.
*/
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);
}
}