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);
}
Serial.write(a[i]);
sends a character but not all values are readable characterssnprintf(Hex_Array, sizeof(Hex_Array), "%02X", num);
. More info here and here. Also be aware that the Arduino versions don't support the%f
format specifier.