Search code examples
arduinoethernet

Taking data from serial monitor in hex form in Arduino


My Serial Monitor is showing 13315212969217 this type of numbers when i show my card to RFID522 instead of Hex number. How do i get to convert it to hex? This is my card number getting code

 if (rfid.isCard())
     {    if (rfid.readCardSerial())
          {    String id = "";
               id += rfid.serNum[0];
               id += rfid.serNum[1];
               id += rfid.serNum[2];
               id += rfid.serNum[3];
               id += rfid.serNum[4];
               //lcd.setCursor(0, 0);
               //lcd.print(id);
               //delay(7000);
               Serial.println(id);

Thanks


Solution

  • if (rfid.isCard())  {
             if (rfid.readCardSerial()) {
                 for(int i=0; i<5; i++) {
                    Serial.print(rfid.serNum[i], HEX);
                 }
                 Serial.println();
             }
     }
    

    There's no need to build a big String up first to print it. That uses a lot more resources than just printing it in chunks.