rfid reader convert hex to dec

This is the code that I have so far. I hope I get some more time to finish it. Right now it prints the first part of the code in decimal as the old reader, and the rest is hex. Also I need to add a 0 to the second byte info that is translated into decimal as that’s usually 0 and I need it to be 00 in the final tag data. Then there’s the problem that the message “Scan the tag” repeats itself every 2 seconds, I need it to be once on the screen and after I get the tag to show up again. These are details that I’ll deal with later when I have the chance.

#include <Wire.h>
  byte data[5];    //define array to hold tag data
  void setup()
{
  Wire.begin();     //Initiate the Wire library and join the I2C bus as a master or slave       
  Serial.begin(115200);    //initiate com on serial with baud rate
}
 void loop()
{
      Wire.beginTransmission(0x41);     //Begin a transmission to the I2C slave device with the given address (0x41 in this case)
      Wire.write(0x10);       //read command array
      Wire.write(0x03);      //read command array
      Wire.write(0x02);      //read command array
      Wire.write(0x00);      //read command array
      Wire.write(0x00);      //read command array
      Wire.write(0x00);      //read command array
      Wire.write(0x00);      //read command array
      Wire.write(0x15);      //read command array
      Wire.endTransmission(); //Ends a transmission to a slave device that was begun by beginTransmission() and transmits the bytes that were queued by write().
      Wire.requestFrom(0x41, 1);   //Used by the master to request bytes from a slave device (in this case I request 1 byte from 0x41 device)
      while(Wire.available() == 0);  // slave may send less than requested
      byte z = Wire.read();      // here we put the answered token into z
    if (z == 0x6B)         //if the token is 0x6B it means the device is in read mode
      {
           Serial.println("Scan the tag"); 
      }
  
    if (z == 0x6E)        //0x6E is the "I've read the tag and I'm waiting for further instructions" token
      {
      Wire.beginTransmission(0x41);  //we begin another transmission with the 0x41 device
      Wire.write(0x52);              //we send the "send me the tag data" command
      Wire.endTransmission();        //we end transmission with the device
      Wire.requestFrom(0x41, 5);     //we request 5 bytes of data
      data[0] = Wire.read();        //we receive 1st byte
      data[1] = Wire.read();        //we receive 2nd byte
      data[2] = Wire.read();         //we receive 3rd byte
      data[3] = Wire.read();         //we receive 4th byte
      Wire.read();                   //we read the 5th byte but don't do anything with it, it's just the info informing us that there's another 5 byte packet available
      Wire.beginTransmission(0x41);   //we begin another transmission with the 0x41 device
      Wire.write(0x52);              //we send the "send me the tag data" command
      Wire.endTransmission();        //we end transmission with the device
      Wire.requestFrom(0x41, 5);    //we request 5 bytes of data
      data[4] = Wire.read();        //we receive 1st byte, this is the last byte from the 5 byte tag data
      Wire.read();                    //we read the rest of data bytes but don't do anything with them, the 2nd 3rd and 4th are empty bytes and the last one is "there's no more data" byte.
      Wire.read();
      Wire.read();
      Wire.read();
      Serial.print("0");              //I need to put a 0 in front of the code so it matches the ones that came out of my old rfid reader
      Serial.print(data[0], DEC);    // this command converts the first byte from the tag from HEX to decimal.
      Serial.print(data[1], DEC);    // this command converts the second byte from the tag from HEX to decimal.
      Serial.print(data[2], HEX);    //temporary for testing purposes
      Serial.print(data[3], HEX);    //temporary for testing purposes
      Serial.print(data[4], HEX);        //temporary for testing purposes
      Serial.println();               //prints a new line
      }      
    delay(2000);                      //a delay of 2 seconds between scans.
 
}

Well, it’s done!
This is the final code and it works perfect, I get the same codes as the old reader. I tested cards from different batches and the results are consistent.
This is the final code. I removed the text showing on console, I only need the code. Thank you all for your help.

#include <Wire.h>
  byte data[2];    //define array to hold tag data
  byte t[3];
  unsigned long red = 0;
  void setup()
{
  Wire.begin();     //Initiate the Wire library and join the I2C bus as a master or slave       
  Serial.begin(115200);    //initiate com on serial with baud rate
}
 
 void loop()
{
      Wire.beginTransmission(0x41);     //Begin a transmission to the I2C slave device with the given address (0x41 in this case)
      Wire.write(0x10);       //read command array
      Wire.write(0x03);      //read command array
      Wire.write(0x02);      //read command array
      Wire.write(0x00);      //read command array
      Wire.write(0x00);      //read command array
      Wire.write(0x00);      //read command array
      Wire.write(0x00);      //read command array
      Wire.write(0x15);      //read command array
      Wire.endTransmission(); //Ends a transmission to a slave device that was begun by beginTransmission() and transmits the bytes that were queued by write().
      Wire.requestFrom(0x41, 1);   //Used by the master to request bytes from a slave device (in this case I request 1 byte from 0x41 device)
      while(Wire.available() == 0);  // slave may send less than requested
      byte z = Wire.read();      // here we put the answered token into z

      if (z == 0x6E)        //0x6E is the "I've read the tag and I'm waiting for further instructions" token
          {
              Wire.beginTransmission(0x41);  //we begin another transmission with the 0x41 device
              Wire.write(0x52);              //we send the "send me the tag data" command
              Wire.endTransmission();        //we end transmission with the device
              Wire.requestFrom(0x41, 5);     //we request 5 bytes of data
              data[0] = Wire.read();        //we receive 1st byte
              data[1] = Wire.read();        //we receive 2nd byte
              t[0] = Wire.read();         //we receive 3rd byte
              t[1] = Wire.read();         //we receive 4th byte
              Wire.read();                   //we read the 5th byte but don't do anything with it, it's just the info informing us that there's another 5 byte packet available
              Wire.beginTransmission(0x41);   //we begin another transmission with the 0x41 device
              Wire.write(0x52);              //we send the "send me the tag data" command
              Wire.endTransmission();        //we end transmission with the device
              Wire.requestFrom(0x41, 5);    //we request 5 bytes of data
              t[2] = Wire.read();        //we receive 1st byte, this is the last byte from the 5 byte tag data
              Wire.read();                    //we read the rest of data bytes but don't do anything with them, the 2nd 3rd and 4th are empty bytes and the last one is "there's no more data" byte
              Wire.read();
              Wire.read();
              Wire.read();
              red = (unsigned char) t[0];
              red = red * 0x100;
              red = red + (unsigned char) t[1];
              red = red * 0x100;
              red = red + (unsigned char) t[2];
              Serial.print("0");              //I need to put a 0 in front of the code so it matches the ones that came out of my old rfid reader
              if (data[0] < 16) Serial.print("0");   ////if the first byte's decimal value is lower than 0 then add prefix 0
              Serial.print(data[0], DEC);    // this command converts the first byte from the tag from HEX to decimal
              if (data[1] < 16) Serial.print("0"); //if the second byte's decimal value is lower than 0 then add prefix 0
              Serial.print(data[1], DEC);    // this command converts the second byte from the tag from HEX to decimal
              if (red < 10000000) Serial.print("0");   //if the last 3 byte's decimal value is lower than 10.000.000 add prefix 0
              Serial.print(red, DEC);    //prints the decimal value of the last 3 bytes from the tag data
              Serial.println();               //prints a new line
           }      
      delay(500);                      //a delay of half second between scans.
 
}

Well done. :)

You can test readers using small RFID tags who have ID number (in DEC format) printed from the producer. RFID reader send the same number but in HEX format. When you put HEX number in Windows Calculator and convert to DEC format the number is the same as printed.

charles1023: You can test readers using small RFID tags who have ID number (in DEC format) printed from the producer. RFID reader send the same number but in HEX format. When you put HEX number in Windows Calculator and convert to DEC format the number is the same as printed.

No RFID readers do. It send data in decimal or hex format. Like everything else in computing it sends data in binary format one bit at a time. It is only once it is inside a computer that the format matters, and that is only when you come to output thnks.