Serial.availableForWrite() always return 63 (Stupid Question !)

hi guys :slight_smile:

sorry about wasting your time
(i am beginner )

actually i read about : Serial.availableForWrite() here :

https://www.arduino.cc/reference/en/language/functions/communication/serial/availableforwrite/

but when i try to use it it always returns 63 bytes , i wonder how to make it returns different values
to understand it better .

thanks so much <3

(deleted)

There is a buffer for Serial output that is 64 bytes long. Availableforwrite tells you how many of them are empty, i.e. how many more you can put there before your code will block and wait for the UART to put bytes on the wire to free up space.

I've never seen it used. Generally, you can crank up the baud rate and avoid Serial.printing too much stuff so that you don't need to worry about it.

spycatcher2k:
When you put something in the serial buffer - Serial.print("Hello World!");

PS - not a guy

#1

actually i used google and tried to write a code

for example here it also return 63 -_-

String val ;
byte bytes ;

void setup() {

Serial.begin(9660);

}

void loop() {

if(Serial.available()>0 ) {

bytes = Serial.availableForWrite();
val = Serial.readString();

Serial.println(val);
Serial.println(bytes);

}
}

wildbill:
There is a buffer for Serial output that is 64 bytes long. Availableforwrite tells you how many of them are empty, i.e. how many more you can put there before your code will block and wait for the UART to put bytes on the wire to free up space.

I’ve never seen it used. Generally, you can crank up the baud rate and avoid Serial.printing too much stuff so that you don’t need to worry about it.

i am so sorry for making u bear with me

thanks very much <3

Because, by the time you’ve actually typed something into the serial monitor to trigger Serial.available() everything you previously wrote with Serial.println has already been sent.

Try..

void loop()
{
  bytes = Serial.availableForWrite();
  Serial.println(bytes);
}

pcbbc:
Because, by the time you’ve actually typed something into the serial monitor to trigger Serial.available() everything you previously wrote with Serial.println has already been sent.

Try..

void loop()

{
 bytes = Serial.availableForWrite();
 Serial.println(bytes);
}

pcbbc:
Because, by the time you’ve actually typed something into the serial monitor to trigger Serial.available() everything you previously wrote with Serial.println has already been sent.

Try..

void loop()

{
 bytes = Serial.availableForWrite();
 Serial.println(bytes);
}

thanks for replying and explanation
yup now it returns :

63
61
57
53
49
45
41
37
33
30
26
22
18
14
10
6
3
0

!

Serial.begin(9660)Unusual

yaaaaaaaa

it worked hhh sorry guys i am stupid

63
61
57
53
49
45
41
37
33
30
26
22
18
14
10
6
3
0