Here you are. The brackets are changed
But still I get following output
Tag detected...
ID in HEX: 2A7D128800028
Tag_id: 2800808127d2a195c2800
#include <SoftwareSerial.h>
SoftwareSerial NFCserial(2, 3); //RX, TX
//const int rs = 13, en = 12, d4 = 11, d5 = 10, d6 = 9, d7 = 8;
const int lock_pin = 2;
uint8_t echo_command[1] = {0x55};
uint8_t info_command[2] = {0x01, 0x00};
uint8_t detect_command_iso14443a_1[6] = {0x09, 0x04, 0x68, 0x01, 0x07, 0x10};
uint8_t detect_command_iso14443a_2[6] = {0x09, 0x04, 0x68, 0x01, 0x07, 0x00};
uint8_t detect_command_iso14443a_3[6] = {0x02, 0x04, 0x02, 0x00, 0x02, 0x80};
uint8_t detect_command_iso14443a_4[6] = {0x09, 0x04, 0x3A, 0x00, 0x58, 0x04};
uint8_t detect_command_iso14443a_5[6] = {0x09, 0x04, 0x68, 0x01, 0x01, 0xD3};
uint8_t detect_command_iso14443a_6[4] = {0x04, 0x02, 0x26, 0x07};
uint8_t detect_command_iso14443a_7[5] = {0x04, 0x03, 0x93, 0x20, 0x08};
//uint8_t detect_command_iso14443a_6[4] = {0x02, 0x02, 0x01, 0x0D};
//uint8_t detect_command_iso14443a_7[5] = {0x04, 0x03, 0x26, 0x01, 0x00};
uint8_t received_data[256];
uint8_t received_buf_pos;
uint8_t response_byte;
uint8_t data_len;
boolean received_complete;
String tag_id = "";
char Byte_In_Hex[3];
struct tag{
String Card;
int Access;
};
tag Tags[3] = {{"xxxx",0},
{"yyyy",1},
{"zzzz",1}};
void serial_receive(){
uint8_t received_char;
while(NFCserial.available()!=0){
received_char = char (NFCserial.read());
//the first byte of the received message is the response
if(received_buf_pos == 0){
response_byte = received_char;
}
//second byte of the received data is the data length
else if(received_buf_pos == 1){
data_len = received_char;
}
else if(received_buf_pos == 2){
}
else if(received_buf_pos == 3){
}
// Proximity card number starts at the fourth byte
else{
received_data[received_buf_pos-4] = received_char;
sprintf(Byte_In_Hex,"%x", received_char);
tag_id += Byte_In_Hex; //adding to a string
}
received_buf_pos++;
if(received_buf_pos >= data_len){
received_complete = true;
}
}
}
void scan_tag(){
received_buf_pos = 0;
received_complete = false;
tag_id="";
Serial.println("Searching new card...");
NFCserial.write(detect_command_iso14443a_6, 4);
delay(200);
NFCserial.write(detect_command_iso14443a_7, 5);
delay(300);
if(NFCserial.available()) serial_receive();
else return;
if(response_byte == 0x80){
Serial.println("Tag detected...");
Serial.print("ID in HEX: ");
for(int pos=7; pos>=0; pos--){
Serial.print(received_data[pos], HEX);
}
Serial.println("");
Serial.print("Tag_id: ");
Serial.println(tag_id);
delay(2000); //this is important
}
else{
Serial.println("No tag detected.");
delay(2000);
}
}
void setup() {
Serial.begin(9600);
delay(1000);
NFCserial.begin(57600);
delay(1000);
//Displaying RFID serial number
Serial.println("RFID mudule:");
NFCserial.write(info_command, 2);
delay(100);
show_serial_data();
Serial.println("");
delay(2000);
//Initialising the module to read iso14443a proximity cards
NFCserial.write(echo_command, 1);
NFCserial.write(detect_command_iso14443a_1, 6);
delay(200);
NFCserial.write(detect_command_iso14443a_2, 6);
delay(200);
NFCserial.write(detect_command_iso14443a_3, 6);
delay(200);
NFCserial.write(detect_command_iso14443a_4, 6);
delay(200);
NFCserial.write(detect_command_iso14443a_5, 6);
delay(1000);
show_serial_data();
}
void loop() {
scan_tag();
// for (int i=0;sizeof(Tags)-1; i++){
// delay(1000);
// Serial.println(Tags[i].Card);
// }
//delay(100);
}
// this display the debug message
void show_serial_data()
{
while(NFCserial.available()!=0) /* If data is available on serial port */
Serial.print(NFCserial.read(), HEX); /* Print character received on to the serial monitor */
}