I'm creating a code to transfer data from an RFID reader connected to an Arduino Mega to another Arduino via XBee, including the access status (granted or denied). The communication is established, and the data along with the access status are transmitted successfully. However, I'm facing difficulty in transferring the data matrix, which includes detailed information about the RFID card. I'm using the function MFRC522Debug::PICC_DumpToSerial(mfrc522, Serial, &(mfrc522.uid)); to print the data matrix to the Serial monitor, but I haven't been able to find a way to transfer it to Arduino 2. I tried implementing some functions in the code, but they caused issues and had to be removed. Does anyone know of a method to achieve this? Thanks for your time.
this is the code for the transmiter
#include <MFRC522v2.h>
#include <MFRC522DriverSPI.h>
#include <MFRC522DriverPinSimple.h>
#include <MFRC522Debug.h>
// Create MFRC522 instance.
// MFRC522 mfrc522(SS_PIN, RST_PIN);
// Configurable, see typical pin layout above.
MFRC522DriverPinSimple ss_pin(53);
// Create SPI driver.
MFRC522DriverSPI driver{ss_pin};
// Create MFRC522 instance.
MFRC522 mfrc522{driver};
void setup() {
// Initiate a serial communication
Serial.begin(9600);
// Initiate serial for arduino 2
Serial3.begin(9600);
// Initiate SPI bus
SPI.begin();
// Initiate MFRC522
mfrc522.PCD_Init();
// Show details of PCD - MFRC522 Card Reader details
Serial.println("show your card to the ready");
Serial.println();
MFRC522Debug::PCD_DumpVersionToSerial(mfrc522, Serial);
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
// Show details of PCD - MFRC522 Card Reader details
// MFRC522Debug::PCD_DumpVersionToSerial(mfrc522, Serial3);
}
void loop() {
if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
// Print UID tag
Serial.print("UID tag :");
String content= "";
byte letter;
// hexadecimal converter
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
content.toUpperCase();
// Check if UID matches the desired one
if (content.substring(1) == "23 7F 8C 16") { //UID CARD to compare
Serial3.print("A");
Serial.println("Authorized access");
Serial.println();
delay(1000);
} else {
Serial3.println("P");
Serial.println(" Access denied");
delay(1000);
}
// Dump card details to Serial
MFRC522Debug::PICC_DumpToSerial(mfrc522, Serial, &(mfrc522.uid));
// MFRC522Debug::PICC_DumpToSerial(mfrc522, Serial3, &(mfrc522.uid));
delay(300);
}
}
// Function declaration to read serial data
String readSerialData();
void setup() {
Serial.begin(9600); // Initialize Serial communication
Serial3.begin(9600); // Initialize Serial3 communication
Serial.println("Present your card"); // Prompt message
}
void loop() {
// Check if there is data available on Serial3
if (Serial3.available() > 0) {
// Read the received character from Serial3
char receivedChar = Serial3.read();
// Check the received character
if (receivedChar == 'A') {
Serial.println("Access Granted"); // Print message for Access Granted
} else if (receivedChar == 'P') {
Serial.println("Access Denied"); // Print message for Access Denied
}
}
}
}
*/
In the provided code, data from the RFID reader is successfully transmitted to Arduino 2 based on access status. However, the issue lies in transferring the detailed data matrix to Arduino 2. You may try uncommenting the line MFRC522Debug::PICC_DumpToSerial(mfrc522, Serial3, &(mfrc522.uid)); to send the data matrix to Arduino 2 via Serial3. If this doesn't work, further troubleshooting or alternative methods may be necessary.
My guess is that you sending more data than what the Xbee can handle in one lump.
The workaround is to chop the data into smaller pieces and send one piece at a time with a time gap in between. Alternatively use the flow control pin as per the documentation to signal the Arduino when it's OK to send data.
"I made a mistake, I was putting the wrong command MFRC522Debug::PICC_DumpToSerial(mfrc522, Serial3, &(mfrc522.uid)); // send to Arduino 2 , so it's working now. But I can't find a way for the data to show in both serial communications without losing data." , i tried using millis, but still losing data one way o another.
still , there is no any form to show the rfid data in both serial, is show me good in serial 3 but in serial 1 is like
15 63 PCD_Authenticate() failed: Timeout in communication.
14 59 PCD_Authenticate() failed: Timeout in communication.
13 55 PCD_Authenticate() failed: Timeout in communication.
12 51 PCD_Authenticate() failed: Timeout in communication.
11 47 PCD_Authenticate() failed: Timeout in communication.
10 43 PCD_Authenticate() failed: Timeout in communication.
9 39 PCD_Authenticate() failed: Timeout in communication.
8 35 PCD_Authenticate() failed: Timeout in communication.
7 31 PCD_Authenticate() failed: Timeout in communication.
6 27 PCD_Authenticate() failed: Timeout in communication.
5 23 PCD_Authenticate() failed: Timeout in communication.
4 19 PCD_Authenticate() failed: Timeout in communication.
3 15 PCD_Authenticate() failed: Timeout in communication.
2 11 PCD_Authenticate() failed: Timeout in communication.
1 7 PCD_Authenticate() failed: Timeout in communication.
0 3 PCD_Authenticate() failed: Timeout in communication.
i already used milis and delay and still losing communication