Skip to main content
Tweeted twitter.com/StackArduino/status/1145890074078433280
edited tags
Link
Michel Keijzers
  • 13k
  • 7
  • 42
  • 59
Source Link

writting to buffer from serial input

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.