Hi, I am trying to send and print the 13 bytes of data using serial communication using Arduino Uno board, when I use print function the data is not matching with that of actual data present in the array, how to properly print the data present in the array in binary format with 13 bytes of data
byte data_out[] = {0b00000000,0b00000001,0b00000010,0b00000011,0b00000100,0b00000101,
0b00000110,0b00000111,0b00001000,0b00001001,0b00001010,0b00001011,
0b00001100,0b00001101};
int i;
void setup() {
Serial.begin(9600);
}
void loop() {
for (i=0; i < 13; i++) {
Serial.write(data_out[i]);
Serial.print(data_out[i], BIN);
Serial.print("\n");
//delay(100);
}
// Serial.println(data_out[i]);
}
-----------------------Update-----------------------
Thank you all for the responses, I have made changes in the program one 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
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 the Serial write and print function for the 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);
}