user79507: I have, one program with only using printing array and other with serial write and print function for the array, while using serial write and print function I get these extra characters between the data as shown below, can anyone help me with this
Printing the array with print function
uint8_t a[13] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0X77, 0x88,
                 0x01, 0x02, 0x03, 0x04, 0x05};
int i;

void Print_Hexa(uint8_t num) {
  char Hex_Array[2];

  sprintf(Hex_Array, "%02X", num);
  Serial.print(Hex_Array);
}

void setup() {
  Serial.begin(9600);
}

void loop() {
  for (i = 0; i <= 12; i++) {
    //Serial.write(a[i]);
    Print_Hexa(a[i]);
  }
  Serial.println();
  delay(100);
}


Using with serial write and print function for array
uint8_t a[13] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0X77, 0x88,
                 0x01, 0x02, 0x03, 0x04, 0x05};
int i;

void Print_Hexa(uint8_t num) {
  char Hex_Array[2];

  sprintf(Hex_Array, "%02X", num);
  Serial.print(Hex_Array);
}

void setup() {
  Serial.begin(9600);
}

void loop() {
  for (i = 0; i <= 12; i++) {
    Serial.write(a[i]);
    Print_Hexa(a[i]);
  }
  Serial.println();
  delay(100);
}



user4143: To store a 2 character string you need a 3 byte array, not a 2 byte array. This is because in C a string consists of the actual string data and a zero ("NULL") byte at the end to indicate where the end of the string is.
So you would need:
char Hex_Array[3];

so it can store, for the number 0x69: 69\0. Otherwise you overrun the array and corrupt other data that follows in the stack, and changing that other data corrupts your string by changing the "end of string" marker to some other random ASCII character.

user7508: Serial.write(some_byte) writes a byte on the serial output. The
Arduino serial monitor tries to interpret the bytes it receives as text:

0x11 is a control character, displayed as “□”
0x22 is the ASCII code for the double quote (")
0x33 is the ASCII code for the digit 3.
0x44 is the ASCII code for the uppercase letter “D”
etc.


79507: <p>I have, one program with only using printing array and other with serial write and print function for the array, while using serial write and print function I get these extra characters between the data as shown below, can anyone help me with this</p>
<p>Printing the array with print function</p>
<pre class="lang-cpp prettyprint-override"><code>uint8_t a[13] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0X77, 0x88,
                 0x01, 0x02, 0x03, 0x04, 0x05};
int i;

void Print_Hexa(uint8_t num) {
  char Hex_Array[2];

  sprintf(Hex_Array, &quot;%02X&quot;, num);
  Serial.print(Hex_Array);
}

void setup() {
  Serial.begin(9600);
}

void loop() {
  for (i = 0; i &lt;= 12; i++) {
    //Serial.write(a[i]);
    Print_Hexa(a[i]);
  }
  Serial.println();
  delay(100);
}
</code></pre>
<p><a href="https://i.stack.imgur.com/VFLIa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VFLIa.png" alt="Using Print Function" /></a></p>
<p>Using with serial write and print function for array</p>
<pre class="lang-cpp prettyprint-override"><code>uint8_t a[13] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0X77, 0x88,
                 0x01, 0x02, 0x03, 0x04, 0x05};
int i;

void Print_Hexa(uint8_t num) {
  char Hex_Array[2];

  sprintf(Hex_Array, &quot;%02X&quot;, num);
  Serial.print(Hex_Array);
}

void setup() {
  Serial.begin(9600);
}

void loop() {
  for (i = 0; i &lt;= 12; i++) {
    Serial.write(a[i]);
    Print_Hexa(a[i]);
  }
  Serial.println();
  delay(100);
}
</code></pre>
<p><a href="https://i.stack.imgur.com/HUDLP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HUDLP.png" alt="Using Serial write and Print function for array" /></a></p>
 4143: <p>To store a 2 character string you need a 3 byte array, not a 2 byte array. This is because in C a string consists of the actual string data <em>and</em> a zero (&quot;NULL&quot;) byte at the end to indicate where the end of the string is.</p>
<p>So you would need:</p>
<pre><code>char Hex_Array[3];
</code></pre>
<p>so it can store, for the number 0x69: <code>69\0</code>. Otherwise you overrun the array and corrupt other data that follows in the stack, and changing that other data corrupts your string by changing the &quot;end of string&quot; marker to some other random ASCII character.</p>
 7508: <p><code>Serial.write(some_byte)</code> writes a byte on the serial output. The
Arduino serial monitor tries to interpret the bytes it receives as text:</p>
<ul>
<li><code>0x11</code> is a control character, displayed as “□”</li>
<li><code>0x22</code> is the ASCII code for the double quote (&quot;)</li>
<li><code>0x33</code> is the ASCII code for the digit 3.</li>
<li><code>0x44</code> is the ASCII code for the uppercase letter “D”</li>
<li>etc.</li>
</ul>
