Perhaps this: void setup() {   Serial.begin(9600); } void loop() { int n;   for (int n = 0; n <= 16; n++)   {     Serial.print("0x");     Serial.print(n < 16 ? "0" : "");     Serial.print(n, HEX);     Serial.print(" ");   }   Serial.println(); } Answer from econjack on forum.arduino.cc
🌐
Hackster.io
hackster.io › Hack-star-Arduino › how-to-print-hexadecimal-and-binary-on-to-serial-monitor-5e5d11
How to print hexadecimal and Binary on to Serial Monitor? - Hackster.io
December 26, 2022 - In this article, I am using the Wokwi Arduino simulator. I have shared the links for all the projects I have created for this demonstration. 🧩 · In this project, you will print the characters onto the serial terminal. You will print a series of numbers in decimal, Octal, Hexadecimal as well as in binary.
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Serial.print(Value,HEX); - Programming - Arduino Forum
June 9, 2017 - HI, I wanted to test the serial.print(value,HEX) function to make sure, that the output from the routine always are 2 chars long ( eg: 0x00 --> 00 and 0xFF --> FF). so I wrote the following test code: void setup() { …
Discussions

Printing Hex into Serial Port
I am trying to print out the hexidecimal value exactly as it is shown. char msgString[128]; void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.println(" "); } void loop() { // put your main code here, to run repeatedly: uint64_t receivedMsg = 0x1000000100000000; ... More on forum.arduino.cc
🌐 forum.arduino.cc
11
0
January 17, 2024
uart - Send HEX number over serial - Arduino Stack Exchange
I have a RS232 device that I am able to communicate with using RealTerm on a windows PC. The device is expecting a hex string like AA BB 03 01 03 EE How would I send the equivalent string from an a... More on arduino.stackexchange.com
🌐 arduino.stackexchange.com
Arduino: why does Serial.println(int, HEX) display 4 bytes? - Electrical Engineering Stack Exchange
Some implementations of the Print class, include printf (Like Adafruit's, see here). In that case, you just do Serial.printf("X", x). More on electronics.stackexchange.com
🌐 electronics.stackexchange.com
How to use Serial.print returning full HEX value?
Hi guys - I've been looking through documentation, and the forums, and Google, and I can't seem to find out how to do what I want to do. So, I'm asking for help 🙂 I'm working with Serial.print, and I am not getting the desired output that I want. Regardless of what data type I pass to ... More on forum.arduino.cc
🌐 forum.arduino.cc
4
1
May 2, 2009
🌐
Arduino
arduino.cc › en › Serial › Print
Serial.print() | Arduino Documentation
Prints data to the serial port as human-readable ASCII text. This command can take many forms. Numbers are printed using an ASCII character for each digit. Floats are printed similarly to ASCII digits, defaulting to two decimal places. Bytes are sent as a single character.
🌐
TutorialsPoint
tutorialspoint.com › print-hexadecimal-values-in-arduino
Print hexadecimal values in Arduino
March 23, 2021 - In order to print hexadecimal equivalents of numbers or characters, adding 'HEX' as the second argument of Serial.print() will be sufficient. The following code demonstrates this − Example
Top answer
1 of 2
3

As noticed by jsotola in a comment, your device doesn't seem to be expecting HEX at all, but rather plain binary. Serial.print() is not appropriate, as it is designed for sending ASCII text. For binary data, you should prefer Serial.write(). More specifically, for sending arbitrary binary data, the proper method is

size_t Print::write(const uint8_t *buffer, size_t size)

Applying this to your example gives:

const size_t packet_length = 6;
uint8_t packet[packet_length] = {0xaa, 0xbb, 0x03, 0x01, 0x03, 0xee};
Serial.write(packet, packet_length);
2 of 2
0

if device expects actual numbers, then it does not receive them in hex format or decimal, but in binary. in which case you would need an array of numbers and then go with them using for loop (or purpouse made function.

byte sequence[]={0xAA, 0xBB, 0x03, 0x01, 0x01, 0xEE};
for(byte i=0; i<sizeof(sequence);i++) Serial.write(sequence[i]);

if you have to send it as a HEX, then its most likely a case of hex representation and you can use printf for that

Serial.printf("0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X", 0xAA, 0xBB, 0x03, 0x01, 0x01, 0xEE);

Another think is that you should be careful using println when communicating with other devices. println ads extra character (number) for new line, after the data you wish to send. if you only want to send data you wish to send, then use print instead

Edit: Thanks for the note from Edgar Bonet, I was warned that printf is still not a standard instruction outside of the ESP core. Its well worth adding it up by yourself. Look for a guide on arduino playground.

Find elsewhere
🌐
Arduino Forum
forum.arduino.cc › forum 2005-2010 (read only) › software › syntax & programs
How to use Serial.print returning full HEX value? - Syntax & Programs - Arduino Forum
May 2, 2009 - Hi guys - I've been looking through documentation, and the forums, and Google, and I can't seem to find out how to do what I want to do. So, I'm asking for help 🙂 I'm working with Serial.print, and I am not getting the desired output that I want. Regardless of what data type I pass to ...
🌐
Arduino Forum
forum.arduino.cc › projects › programming
How get a HEX number from the Serial Monitor - Programming - Arduino Forum
March 29, 2020 - I have written a sketch that will get an integer from the Serial Monitor and do something with it. I want to be able to get a HEX number from the Serial Monitor and retain it as a HEX number. If I do a Serial parse int and enter a 0xff on the serial monitor, the sketch doesn't seem to receive ...
🌐
Phanderson
phanderson.com › arduino › arduino_display.html
Display Routines - Arduino - Peter H. Anderson
// PRINT_HEX - Arduino ATMega168 // // Illustrates how to display a hexadecimal number with a fixed width. // // copyright, Peter H Anderson, Baltimore, MD, Nov, '07 void setup() // run once, when the sketch starts { Serial.begin(9600); } void loop() { while(1) { print_hex(1024+256+63, 13); Serial.println(); delay(1000); } } void print_hex(int v, int num_places) { int mask=0, n, num_nibbles, digit; for (n=1; n<=num_places; n++) { mask = (mask << 1) | 0x0001; } v = v & mask; // truncate v to specified number of places num_nibbles = num_places / 4; if ((num_places % 4) != 0) { ++num_nibbles; } do { digit = ((v >> (num_nibbles-1) * 4)) & 0x0f; Serial.print(digit, HEX); } while(--num_nibbles); }
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Serial.print(char, HEX) with value of -1 displays a long value FFFFFFFF - Programming - Arduino Forum
June 25, 2017 - Serial.print(char, HEX) a char with a negative value -1 ~ -128 displays a long value rather than the byte value. This took me for a whirl thinking I had a coding problem. void setup() { // put your setup code here, to run once: Serial.begin(115200); char C; byte B; Serial.println("Printing Chars"); for (int x = 0; x
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Hex formatting - Programming - Arduino Forum
October 13, 2012 - when printing to serial port like below byte x = 255 Serial.print(x, HEX); outputs FF as expected but if x is 0 to 15 the output is 0 to F is there as easy way to make the output 00 to 0F thanks
🌐
Arduino Forum
forum.arduino.cc › community › suggestions for the arduino project
Serial.print, HEX and indent - Suggestions for the Arduino Project - Arduino Forum
November 27, 2016 - I had a need to work with 64-bit unsigned integers. However, printing on serial port is not available and printing 32-bit parts can not be indent. I'm missing the point to print hex numbers without indent according it physical length. Simple printing this way require custom code and additional string buffer to override this.
🌐
Reddit
reddit.com › r/arduino › sending and receiving hex over serial
r/arduino on Reddit: Sending and Receiving HEX over serial
February 28, 2015 -

I am attempting to send messages over serial usb via HEX (yes, I'm aware there are other posts similar to this one, but I feel I'm missing something).

Ultimately I will be sending messages back and forth from the pc to arduino mega. Right now when I send a message in hex I don't see the hex message appear in the serial monitor.

Right now I am sending 0x55 and 0xff, which comes out of the serial monitor as Uÿ. Shouldn't it show as a hex value, is there something else I need to add? The reason for using hex is to try to be somewhat efficient with sending/receiving the signal.

Here is the code that I am using:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  
}

void loop() {
  // put your main code here, to run repeatedly:
  byte message[2]={0x55,0xff};
  Serial.write(message,sizeof(message));
  delay(5000);
  
}
🌐
TechOverflow
techoverflow.net › 2021 › 12 › 03 › how-to-print-byte-as-two-hex-digits-in-arduino
How to print byte as two hex digits in Arduino | TechOverflow
April 16, 2026 - In embedded programming, you often ... = 14;, you intend to print 0x0E. In Arduino you can do that using Serial.printf() with x as format specifier:...
🌐
Arduino Forum
forum.arduino.cc › forum 2005-2010 (read only) › software › development
Print hex with leading zeroes - Development - Arduino Forum
July 19, 2010 - You can print hex using the serial library with Serial.print(data,HEX), but it does not include leading zeroes, so 0x01 will come out as 1, etc. This can get confusing if you print an array, so I put together some simple functions to include ...
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Serial print data in HEX or DEC not coming. - Programming - Arduino Forum
February 24, 2016 - i am sending array data which is ... 01100010 on serial port window. i want to it in DECimal or HEXadecoimal. for that i am using instruction Serial.print(data*,HEX) for hex and DEC for decimal value. but i am not getting output in HEX or DEC. i am getting the same as binary0 ...
🌐
GitHub
github.com › arduino › ArduinoCore-API › issues › 40
Serial.print as HEX should ALWAYS print 2 chars per byte; it omits leading zeroes [imported] · Issue #40 · arduino/ArduinoCore-API
November 15, 2012 - 1.If byte or integer variables are printed with serial.print or serial.println with the HEX output format option leading zeroes are not printed: byte reading5 = 0x0F; byte reading6 = 0x00; byte reading7 = 0xF0; .............
Author   arduino