I apologize in advance for my English, I am French.
I need your help for a small problem I currently have. My Arduino Mega is connected in such a way as to recover an RS232 frame from a machine. The frame I get is in hexadecimal. However, some "0" do not seem to be read .. Have you any advice?
I would like to be able to recover the entire frame without loss of "0" and be able to send it in hexadecimal in the same way.
I hope to have been clear and have posted in the good topic ^^
Rixem:
The frame I get is in hexadecimal. However, some "0" do not seem to be read
Your English is excellent.
As you have not posted your program I can only guess at the problem.
I wonder if, in fact, it is receiving the data correctly but leading zeroes are not being displayed when your print the data. For example with this code
byte testNum = 000123;
Serial,println(testNum);
you would not see the leading zeroes - and you would not expect to see them.
If that is not a correct guess then have a look at the examples in Serial Input Basics - simple reliable ways to receive data.
This is exactly the problem .. But these "0s" are very important for my frame since the machine with which I want to communicate is sensitive to the position of the bytes. I am looking for a solution to solve this problem. Moreover, the solution of transmitting this data in ASCII is impossible. I need to send this data in hexadecimal.
This is exactly the problem .. But these "0s" are very important for my frame since the machine with which I want to communicate is sensitive to the position of the bytes. I am looking for a solution to solve this problem. Moreover, the solution of transmitting this data in ASCII is impossible. I need to send this data in hexadecimal.
So there is no problem. The fact that Serial.print strips leading zeroes when it prints numbers is a non-issue. Serial.print anyway converts numeric variables to text (ASCII), so is the wrong choice if you don't want ASCII.
Thank you all for your quick answers and thank you for taking the time to explain! It seems clear to me now!
However it is my fault, I should have looked at the difference between the "Serial.Write" and "Serial.print". I will try the solution of Sterretje and I come back to you if the solution has worked.
Your problem was to display the leading 0s of the upcoming numeric data on the Serial
Monitor of Arduino IDE.
You are saying that you have solved the problem, but you have not posted your codes which
could enrich our experiences.
You said that you would be testing the codes of sterretje, but you have not reported the
outcome. Do these codes print leading 0s of the upcoming numeric data?
I have worked on this issue; I have found a way of displaying leading 0s of the upcoming
numeric data based on the following principle of the ASCII type Serial Monitor of Arduino IDE:
The Serial Monitor is designed to suppress the leading 0s of the upcoming numeric data (do we
know why?); however, it does not suppress the literal character, meaning that the Monitor will show
0 (zero) if the upcoming data byte is 0x30 (0011 0000 = ASCII code of character 0).
The implementation of this principle demands that the digits of the array of the hexadecimal data
byte (s) must be converted into their corresponding ASCII codes.
Setup of my Test Bench:
(a) When we gently press K1, the numeric data goes upward towards IBMPC.
(b) Literate characters that we send from the Serial Monitor are displayed on the LCD.