You can’t print an array in that way.
If you want to print an array of hexadecimal value (with two digits), you have to use sprintf function and change declaration of b array.
uint8_t b[]= {0x7E, 0x00, 0x1C, 0x90, 0x00, 0x13, 0XA2, 0x00,
0x41, 0x58, 0x1C, 0xCB, 0xFF, 0xFE, 0xC1, 0x7C,
0x00, 0x0F, 0x00, 0x01, 0x00, 0x00, 0x37, 0x46,
0x46, 0x46, 0x00, 0x00, 0x00, 0xE7};
int i;
void printHex(uint8_t num) {
char hexCar[2];
sprintf(hexCar, "%02X", num);
Serial.print(hexCar);
}
void setup() {
Serial.begin(9600);
}
void loop() {
for(i=0; i<sizeof(b); i++){
printHex(b[i]);
}
Serial.println();
delay(500);
}
The output produced is:
Answer from leoc7 on Stack Exchange7E001C900013A20041581CCBFFFEC17C000F0001000037464646000000E7 7E001C900013A20041581CCBFFFEC17C000F0001000037464646000000E7 7E001C900013A20041581CCBFFFEC17C000F0001000037464646000000E7
Top answer 1 of 13
1
Danois90:
No, since that would compare the memory location, not the contents of the arrays. You need a for loop or memcmp for such a compare.
You guys are magicians! Works like a charm now :slight_smile:
byte buffer[6];
byte MINUS1[6] = {0x44,0x06,0x02,0x00,0x02,0xFF}; //example data
byte PLUS…
2 of 13
0
You need a loop for that:
for (int i = 0; i < 6; i++) Serial.print(buffer[i], HEX);
Serial.println();
EDIT: "i<=6" should be "i<6" or "i
How to print all the 8 bits of a byte on serial monitor, if they are all zero
Hi all, As per title... Assuming I have this variable: mybyte = 00000000. Whenever I print Serial.println(mybyte, BIN); I get 0 on the serial monitor. How would I change this so as to print the values of all the 8 bits? Thanks More on forum.arduino.cc
arduino - How to `Serial.print()` "full" hexadecimal bytes? - Stack Overflow
I am programming Arduino and I am trying to Serial.print() bytes in hexadecimal format "the my way" (keep reading for more information). That is, by using the following code byte byte1 = 0xA2; byte More on stackoverflow.com
How to serial print an array?
I've been trying to find a way to print an array with the Serial.print command. So far the code I've got looks like so (everything in the loop before the floats is fairly irrelevant): template inline Print &operator More on forum.arduino.cc
How to coerce Serial.print to print bytes as ASCII characters
How can I coerce Serial.Print to print a byte as an ASCII character rather than a decimal number ? #define My_SW_Ver 'e'; Serial.println(My_SW_Ver); works as intended - the result is 'e' if I do: byte SW_Ver; SW_Ver = My_SW_Ver; Serial.println(SW_Ver); the result is: '101' which is the decimal ... More on forum.arduino.cc
Videos
Arduino Forum
forum.arduino.cc › projects › general guidance
Print and Write data using 13 byte array - General Guidance - Arduino Forum
July 29, 2021 - 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,0...
Arduino Forum
forum.arduino.cc › projects › programming
How to print all the 8 bits of a byte on serial monitor, if they are all zero - Programming - Arduino Forum
January 27, 2016 - Hi all, As per title... Assuming I have this variable: mybyte = 00000000. Whenever I print Serial.println(mybyte, BIN); I get 0 on the serial monitor. How would I change this so as to print the values of all the 8 b…
Top answer 1 of 6
10
Simple brute force method, is to write a routine as:
void p(char X) {
if (X < 16) {Serial.print("0");}
Serial.println(X, HEX);
}
And in the main code:
p(byte1); // etc.
2 of 6
6
The lowest footprint in Memory, Code and runtime would be classic bit playing
byte b;
Serial.print(b>>4, HEX);
Serial.print(b&0x0F,HEX);
Which is working fine on any 8bit type. For any other mask also the first line to
Serial.print((b>>4)&0x0F, HEX);
Arduino Forum
forum.arduino.cc › projects › programming
How to serial print an array? - Programming - Arduino Forum
April 16, 2016 - I've been trying to find a way to print an array with the Serial.print command. So far the code I've got looks like so (everything in the loop before the floats is fairly irrelevant): template<class T> inline Print &op…
TutorialsPoint
tutorialspoint.com › string-to-bytearray-in-arduino
String to byteArray in Arduino
July 24, 2021 - ArduinoHardwareSoftware & Coding · The getBytes() function helps copy the content of a String to a byte array. The syntax is − · string1.getBytes(buf,len) where, string1 is the string whose content you want to copy to a byte array, buf is the byte array, and · len is the length of content ...
Arduino Forum
forum.arduino.cc › forum 2005-2010 (read only) › hardware › interfacing
How to print byte array to lcd screen....???HELP - Interfacing - Arduino Forum
July 2, 2010 - Anyone that can help me and explain what is happening · Problem SOLVED! I am posting the code I used, so someone else who is experiencing with the same problem will get some help from here · The code prints the DECIMAL values stored in the array of dhtll_dat into our LCD!
Arduino Forum
forum.arduino.cc › forum 2005-2010 (read only) › software › syntax & programs
How to print byte as string? - Syntax & Programs - Arduino Forum
November 21, 2010 - Hi, I save some values in EEPROM, so I save them as byte. When I want to print these values I somehow need to convert the to a string... Is there a function to do this?
Raspberry Pi Forums
forums.raspberrypi.com › board index › hardware and peripherals › hats and other add-ons
Byte Array from Arduino To Raspberry Pi - Raspberry Pi Forums
Serial.print(roll); Serial.print(","); Serial.print(pitch); Serial.print(","); Serial.println(heading); Or even wrap some JSON round it with https://github.com/bblanchon/ArduinoJson
Arduino
arduino.cc › en › Serial › Write
Serial.write() | Arduino Documentation
Writes binary data to the serial port. This data is sent as a byte or series of bytes; to send the characters representing the digits of a number use the print() function instead.
Starting Electronics
startingelectronics.org › software › arduino › learn-to-program-course › 17-arrays
Arrays in Arduino Sketches
A for loop is used to get the contents of each element in the array in turn and print the values to the Serial Monitor window.
Arduino Forum
forum.arduino.cc › projects › programming
How to store and read a byte from an Array (Arduino Uno) - Programming - Arduino Forum
December 5, 2015 - Dear community, Please help, I'm trying to write a smal program to make the arduino drive a shift register. I would like the program to read the the values stored in myArray and store them in the variable "code" I can't manage to do so, the values are translated automatically to decemal values.
Arduino Forum
forum.arduino.cc › projects › interfacing w/ software on the computer
Receiving Byte Array over serial - Interfacing w/ Software on the Computer - Arduino Forum
February 6, 2022 - Hi all! I am currently struggling to receive a 4 byte array, containing 3 values and a sync byte (S, or 0x53). All values stay at 0, even though it is receiving serial data... I'm sending this byte array every 10ms. Here below is my code: byte RGB[3] = {0, 0, 0}; boolean newData = false; void setup() { Serial.begin(9600); Serial.println(" 0) { byte val = Serial.read(); if (val == 'S') { while (!Seri...