# How to covert data RFID from string to char

**URL:** <https://forum.arduino.cc/t/how-to-covert-data-rfid-from-string-to-char/1012070>\
**Category:** Programming\
**Created:** [July 13, 2022, 9:33am UTC](https://forum.arduino.cc/t/how-to-covert-data-rfid-from-string-to-char/1012070 "2022-07-13T09:33:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![fakhmyra](https://avatars.discourse-cdn.com/v4/letter/f/ce7236/32.png) [@fakhmyra](https://forum.arduino.cc/u/fakhmyra)\
**Post date:** [July 13, 2022, 9:33am UTC](https://forum.arduino.cc/t/how-to-covert-data-rfid-from-string-to-char/1012070/1 "2022-07-13T09:33:54Z")

</div>

Bare with me. I’m not very good at english and writing in Arduino/C.  
I don't know how to convert uid string to char. I want to send the data to antares and that need char

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [July 13, 2022, 9:47am UTC](https://forum.arduino.cc/t/how-to-covert-data-rfid-from-string-to-char/1012070/2 "2022-07-13T09:47:18Z")

</div>

Welcome to the forum

Your topic was **MOVED** to its current forum category as it is more suitable than the original

Please post your sketch (use code tags when you do) that reads the RFID tag so that we can see what you have done so far

---

<div class="post-metadata">

**Author:** ![fakhmyra](https://avatars.discourse-cdn.com/v4/letter/f/ce7236/32.png) [@fakhmyra](https://forum.arduino.cc/u/fakhmyra)\
**Post date:** [July 13, 2022, 10:50am UTC](https://forum.arduino.cc/t/how-to-covert-data-rfid-from-string-to-char/1012070/3 "2022-07-13T10:50:44Z")

</div>

```cpp
#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9

MFRC522 rfid(SS_PIN, RST_PIN);
MFRC522::MIFARE_Key key;

String strID;

void setup() {
  SPI.begin();
  rfid.PCD_Init();
  Serial.begin(9600);
  Serial.println("I am waiting for card...");
}

void loop(){
  if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial())
    return ;

  // Serial.print(F("PICC type: "));
  MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
  // Serial.println(rfid.PICC_GetTypeName(piccType));

  strID = "";
  for (byte i = 0; i <rfid.uid.size; i++) {
    strID +=
      (rfid.uid.uidByte[i] < 0x10 ? "0" : "") +
      String(rfid.uid.uidByte[i], HEX) +
      (i != rfid.uid.size-1 ? ":" : "");
  }

  strID.toUpperCase();
  Serial.print("ID : ");
  Serial.print(strID);
  delay(1000);
}

```

---

<div class="post-metadata">

**Author:** ![cotestatnt](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cotestatnt/32/238781_2.png) [@cotestatnt](https://forum.arduino.cc/u/cotestatnt)\
**Post date:** [July 13, 2022, 10:53am UTC](https://forum.arduino.cc/t/how-to-covert-data-rfid-from-string-to-char/1012070/4 "2022-07-13T10:53:45Z")

</div>

You can use the [c\_str() method](https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/c_str/).

```cpp

void functionThatNeedChar(const char* myCharPt) {
  Serial.println(myCharPt);
}

void loop(){
  ....
  strID.toUpperCase();
  Serial.print("ID : ");
  Serial.print(strID);
  
  functionThatNeedChar(strID.c_str());

  delay(1000);
}

```

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [July 13, 2022, 11:05am UTC](https://forum.arduino.cc/t/how-to-covert-data-rfid-from-string-to-char/1012070/5 "2022-07-13T11:05:43Z")

</div>

> [@fakhmyra](#):
>
> I want to send the data to antares and that need char

What exactly does Antares need ?

It seems odd that it should require a zero terminated array of chars that represent a number in HEX format. What datatype is the target field and why can't it be just an integer ?

---

<div class="post-metadata">

**Author:** ![fakhmyra](https://avatars.discourse-cdn.com/v4/letter/f/ce7236/32.png) [@fakhmyra](https://forum.arduino.cc/u/fakhmyra)\
**Post date:** [July 13, 2022, 11:34am UTC](https://forum.arduino.cc/t/how-to-covert-data-rfid-from-string-to-char/1012070/6 "2022-07-13T11:34:38Z")

</div>

Antares need char, it's like database. I found this code in internet, and i don't really understand about it. so what should i do to be able to send the id in char form?

---

<div class="post-metadata">

**Author:** ![KASSIMSAMJI](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kassimsamji/32/261751_2.png) [@KASSIMSAMJI](https://forum.arduino.cc/u/KASSIMSAMJI)\
**Post date:** [July 13, 2022, 11:59am UTC](https://forum.arduino.cc/t/how-to-covert-data-rfid-from-string-to-char/1012070/7 "2022-07-13T11:59:04Z")

</div>

did you try what's in post #4 ?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [January 9, 2023, 11:59am UTC](https://forum.arduino.cc/t/how-to-covert-data-rfid-from-string-to-char/1012070/8 "2023-01-09T11:59:34Z")

</div>

Closed on January 9, 2023, 11:59am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
