Serial.println question

Hello,

When I write:

Serial.println("1243");

The Arduino sends 4 characters? Or more? Or less? What I mean is does it have a certain space for Serial.println(), so it sends for example 10 characters whatever I include up to 10 characters, and then resends another batch of 10 characters or it uses space only for the 4 characters I include to send?

Thank you...

For println, the arduino transmits as many characters as you pass to the function plus a CR and LF.

As to memory use, there are two 64 byte buffers, one for send, one for receive.

To make it more clear, if I use Serial1 for

Serial1.print("1234");

and attach on Serial1 a Xbee Zigbee module. What I get on the receiver on the other end is 4 characters' size? So 4*8bytes = 32 bytes? or more data?

wildbill: For println, the arduino transmits as many characters as you pass to the function plus a CR and LF.

Does that mean that Serial.println("1234"); command sends the following 6 ASCII codes one after another?

0x31, 0x32 0x33, and 0x34 for the characters 1, 2 3 and 4.

0x0D for the non-printable character 'Carriage return (CR)'.

0x0A for the non-printable character 'Newline/line feed (LF)'.

alex5678: To make it more clear, if I use Serial1 for

Serial1.print("1234");

and attach on Serial1 a Xbee Zigbee module. What I get on the receiver on the other end is 4 characters' size? So 4*8bytes = 32 bytes? or more data?

Your calculation is not correct! Correct calculation should begin from the understanding of: 1. In UART communication, information exchange happens as 'one character' at a time.

2. One character information in an 8-bit (1-byte) data in the form of ASCII code (and not binary code). For example: 2 is transmitted as 00110010 (0x32 = ASCII code) and not as 00000010 (0x02 = binary code).

3. At the receiver end, you would collect 4-byte data when the transmitter executes this code: Serial1.print("1234");.

Does that mean that Serial.println("1234"); command sends the following 6 ASCII codes one after another?

You're the self-proclaimed expert on everything Arduino. I would have thought you'd have had a 6 page explanation with dozens of incomprehensible pictures explaining just why this was so, putting everyone to sleep.

Yes, that is exactly what happens.

PaulS:
Yes, that is exactly what happens.

To put faith on some of your opinions, we have to do experiments.

sm92.png

I checked the Xbees on XCT-U. I have one attached to the Arduino that sends:

922

and it also displays the ASCII that are:

39 32 32

and the other connected to the laptop and receives,

but… does the Xbee Zigbee also send any other characters that are for control flow for example etc and they are not displayeable on X-CTU? Because from the basic knowledge I have over protocols they try to fix the header and rest of the packet to a certain size with padding (?) (ex. TCP/IP). That is what I am asking…

Thank you…

but... does the Xbee Zigbee also send any other characters that are for control flow etc and they are not displayeable on X-CTU?

An XBee is a microcontroller with a radio. The radio only sends what it is told to send. What the microcontroller does, if anything, depends on how you have configured the XBee, which you have not explained.

According to the wikipedia page:

The XBees can operate either in a transparent data mode or in a packet-based application programming interface (API) mode.

GolamMostafa:
To put faith on some of your opinions, we have to do experiments.

It isn’t really opinion, which is based on one’s arbitrary beliefs.
println() sending and is based on what the code actually does.
Experiments are not needed. Just read the code.

— bill

alex5678: I checked the Xbees on XCT-U. I have one attached to the Arduino that sends:

922

and it also displays the ASCII that are:

39 32 32

and the other connected to the laptop and receives,

but... does the Xbee Zigbee also send any other characters that are for control flow for example etc and they are not displayeable on X-CTU? Because from the basic knowledge I have over protocols they try to fix the header and rest of the packet to a certain size with padding (?) (ex. TCP/IP). That is what I am asking...

Thank you...

alex5678: I checked the Xbees on XCT-U. I have one attached to the Arduino that sends:

922

and it also displays the ASCII that are:

39 32 32

and the other connected to the laptop and receives,

but... does the Xbee Zigbee also send any other characters that are for control flow for example etc and they are not displayeable on X-CTU? Because from the basic knowledge I have over protocols they try to fix the header and rest of the packet to a certain size with padding (?) (ex. TCP/IP). That is what I am asking...

Thank you...

Serial.printly uses Serial which is UART protocol, it has nothing to do with TCP which is a different protocol/concept/layer. UART does not do padding as far as I know.

bperrybap:
It isn’t really opinion, which is based on one’s arbitrary beliefs.
println() sending and is based on what the code actually does.
Experiments are not needed. Just read the code.

In Arduino programming, there is no room/scope for ‘belief’ – either it is or it is not? One can always put rational opinion on the possible outcome of the execution of a code; a reader does deserve the right to verify the opinion using a suitably designed test jig. As the code Serial.println(); does not embed (except ln – newline?) any obvious camouflage for the charcaters ‘CR’ and ‘LF’, one has to conduct experiments to establish that the said code does transmit two separate characters in succession. Galileo says that he does not guess; rather, he performs experiments and then predicts.

GolamMostafa:
In Arduino programming, there is no room/scope for ‘belief’ – either it is or it is not? One can always put rational opinion on the possible outcome of the execution of a code; a reader does deserve the right to verify the opinion using a suitably designed test jig. As the code Serial.println(); does not embed (except ln – newline?) any obvious camouflage for the charcaters ‘CR’ and ‘LF’, one has to conduct experiments to establish that the said code does transmit two separate characters in succession. Galileo says that he does not guess; rather, he performs experiments and then predicts.

HUH? I’m very curious, Is English your native language? Your posts are always so obtuse.

Anybody can choose to believe whatever they want, regardless of whether there is any supporting basis for the belief.
Code on the other hand, works according to the rules of the language.
In this specific case, there is no need to have any opinions, or guesses about what the code does or to run any experiments to see what the code does, given the code is very simple and very clear. This code:

size_t Print::println(void)
{
  return write("\r\n");
}

is eventually called any time println() is called with any argument type just after the output for the argument is printed.
There is no need for any testing.
It is clear through inspection that according to rules of how C++ works, that the Print class println() method will ALWAYS send and to the underlying inherited write() method as the last 2 characters.

— bill

bperrybap: Your posts are always so obtuse.

That's putting it mildly.

PaulS is closer to the mark:

PaulS: I would have thought you'd have had a 6 page explanation with dozens of incomprehensible pictures explaining just why this was so, putting everyone to sleep.

But that said, nobody can deny GolamMostafa's heart's in the right place. Others' aren't.