Arduino: Get EPC into a char array

Alright I’ve finally figured it out :sweat_smile:

The key was to use sprintf and the %X and now it’s working as expected!

      char epcHex[30];
      epcHex[0] = '\0';
      for (byte x = 0 ; x < tagEPCBytes ; x++)
      { 
        if ((x % 2 == 0) && (x != 0)){ //Add - between every 4 digits
          strcat(epcHex,"-");
        }     
        if (rfidModule.msg[31 + x] < 0x10){
          Serial.print(F("0")); //Pretty print
          strcat(epcHex,"0");
        } 
 
        Serial.print(rfidModule.msg[31 + x], HEX);
        Serial.print(F(" "));

        char buf[5];
        sprintf(buf, "%x", rfidModule.msg[31 + x]);
        strcat(epcHex,buf);
      }

      strcat(epcHex,'/0');
      Serial.print(F("]"));
      tft.setCursor(0, 40);
      tft.setTextSize(2);
      tft.print(epcHex);

1 Like