user31958: Can some one explain this behaviour please, i have the following code
  byte buffer[512];
  byte block;
  byte len;

  Serial.setTimeout(60000L) ;     // wait until 20 seconds for input from serial
  // Ask personal data: Family name
  Serial.println(F("Type text followed by #"));
  len = Serial.readBytesUntil('#', (char *) buffer, 500) ; // read from serial
  Serial.print(len);
  for (byte i = len; i < 250; i++) buffer[i] = '#';     // pad with #
  Serial.print(len);

This works but if i change the "for" line to any thing higer then 250 it stops working and there is a "buffer out of memory condition) 
My question is why can't the for loop say the below as the buffer size is 512? 
for (byte i = len; i < 512; i++) buffer[i] = '#'; 

Am i right in thinking it has something to do with  (Char *), i did copy this code from the example ardunio code and was jsut trying to incress the lenth of input it accpeted. 

user31105: A byte can only contain values from 0 to 255 (including). 
So my guess it works for values until 255.
You should use a different type, e.g. unsigned int or unsigned short.
for (unsigned short i = len; i < 250; i++) buffer[i] = '#';     // pad with #

Also, I advise to use a constant or define for the buffer size, now you have 3 values (512, 500 and 250 in the loop, I assume they should be based on the same value).
About the char*: Looking at StreamReadBytesUntil, it seems that the parameter wants a char* instead of a byte* (which is more or less the same), but it's better to cast to show the parameter is of type char* since that is high likely the exact type (but the official Arduino documentation does not show the parameter types sadly).

31958: <p>Can some one explain this behaviour please, i have the following code</p>

<pre><code>  byte buffer[512];
  byte block;
  byte len;

  Serial.setTimeout(60000L) ;     // wait until 20 seconds for input from serial
  // Ask personal data: Family name
  Serial.println(F("Type text followed by #"));
  len = Serial.readBytesUntil('#', (char *) buffer, 500) ; // read from serial
  Serial.print(len);
  for (byte i = len; i &lt; 250; i++) buffer[i] = '#';     // pad with #
  Serial.print(len);
</code></pre>

<p>This works but if i change the "for" line to any thing higer then 250 it stops working and there is a "buffer out of memory condition) </p>

<p>My question is why can't the for loop say the below as the buffer size is 512? </p>

<pre><code>for (byte i = len; i &lt; 512; i++) buffer[i] = '#'; 
</code></pre>

<p>Am i right in thinking it has something to do with  (Char *), i did copy this code from the example ardunio code and was jsut trying to incress the lenth of input it accpeted. </p>
 31105: <p>A byte can only contain values from 0 to 255 (including). </p>

<p>So my guess it works for values until 255.</p>

<p>You should use a different type, e.g. unsigned int or unsigned short.</p>

<pre><code>for (unsigned short i = len; i &lt; 250; i++) buffer[i] = '#';     // pad with #
</code></pre>

<p>Also, I advise to use a constant or define for the buffer size, now you have 3 values (512, 500 and 250 in the loop, I assume they should be based on the same value).</p>

<p>About the char*: Looking at <a href="https://www.arduino.cc/en/Reference/StreamReadBytesUntil" rel="nofollow noreferrer">StreamReadBytesUntil</a>, it seems that the parameter wants a char* instead of a byte* (which is more or less the same), but it's better to cast to show the parameter is of type char* since that is high likely the exact type (but the official Arduino documentation does not show the parameter types sadly).</p>
