ASCII to Text on Arduino

Hi guys i have a MFRC522 set up and reading blocks from it and writing to serial using Serial.write()

but i want to convert this ASCII bytes to Text

like

065 114 100 117 105 110 111

to Text

Arduino

on the board it self is there any way to do this using a library
please help me in this

Use Serial.print() ?

sterretje:
Use Serial.print() ?

Serial.write() gives

Arduino

Serial.print() gives

065 114 100 117 105 110 111

Sorry for misunderstanding.

Store the bytes in an array, add a ‘\0’ (nul terminator) and print. Something like below

byte data[] = {65, 114, 100, 117, 105, 110, 111};

void setup()
{
  Serial.begin(57600);

  // text buffer
  char text[sizeof(data) + 1];
  // clear if (fill with nul terminators)
  memset(text, '\0', sizeof(text));


  // copy data to text
  memcpy(text, data, sizeof(data));
  // print it
  Serial.println(text);
}

void loop()
{
  // put your main code here, to run repeatedly:

}

sterretje:
Sorry for misunderstanding.

Store the bytes in an array, add a '\0' (nul terminator) and print. Something like below

byte data[] = {65, 114, 100, 117, 105, 110, 111};

void setup()
{
  Serial.begin(57600);

// text buffer
  char text[sizeof(data) + 1];
  // clear if (fill with nul terminators)
  memset(text, '\0', sizeof(text));

// copy data to text
  memcpy(text, data, sizeof(data));
  // print it
  Serial.println(text);
}

void loop()
{
  // put your main code here, to run repeatedly:

}

i had to remove the operator + and trim to get the right result
Thank You it helped me a lot

thanks again

Serial.write() gives

Arduino

Serial.print() gives

065 114 100 117 105 110 111

065 is ASCII ‘5’

TheMemberFormerlyKnownAsAWOL:
065 is ASCII ‘5’

Mmmm, maybe in octal, but then octal would not show as plain “111” would it?
[

Expand<](http://www.asciitable.com/index/asciifull.gif)

Mmmm definitely 065 (==5310 == 0x65) is ‘5’

akash614:
i had to remove the operator + and trim to get the right result
Thank You it helped me a lot

thanks again

You shouldn't. You need one byte more for a terminating nul character in the text. You can't print a text (c-ctring) without a terminating nul; you are lucky it works but it is wrong without it.

sterretje:
You shouldn't. You need one byte more for a terminating nul character in the text. You can't print a text (c-ctring) without a terminating nul; you are lucky it works but it is wrong without it.

i had made few changes to the code and it works flawless and meets my requirement so thanks all of you guys for responding to this topic

and Sorry for late reply

Thank You all Once Again