First line of print not getting dispayed

To learn about arrays I wrote this simple sketch. It creates a 21 element array and should print out 21 pairs of lines. But I don't see why the first line does not get printed properly?

const int folderCount = 21;  // Number of elements (folders)

int subtractions[folderCount] = {0, 157, 21, 154, 153, 152, 151,
                                 49, 166, 149, 21, 206, 134, 133,
                                 33, 127, 41, 31, 15, 114, 252
                                };
void setup()
{
  Serial.begin(9600);
  for (int i = 1 ; i <= folderCount; i++)
  {
    Serial.print("In folder number ");
    Serial.println(i);
    Serial.print("Subtract this: ");
    Serial.println(subtractions[i - 1]);
    delay(100);
  }
}

void loop()
{

}

And when I copy paste the first few lines of output here, why does it only paste a single time stamp ? 

17:12:41.691 ->


I tried a screenshot and a link, but both failed. What I wanted to show was that the text for that first line appears far over to the right.



Arrays go from 0

But have I not accounted for that with

Serial.println(subtractions[i - 1]);

An array index begins with 0
And therefore ends with 1 less than the length of the array

I know, but my code takes account of that. It runs as it should, except for the format issue I described.

Sorry, couldn't see the output.
Try a simple test:

I added a new print statement before the if loop.
If this prints correctly it will let you know that it is not your array causing trouble. I don't see anything obviously wrong with your print statements.

Sorted: I was viewing the monitor directly after uploading the sketch. Is that known to be flaky in presenting the first line?

If instead I started with a reset, the first line was correctly displayed,

I have encountered some flakiness in the first of the output when using certain boards at one time.

I don't remember the exact details, but I think Arduino actually made a fix for it. I remember I was able to work around it by adding a short delay in setup to give a little time before the first output.

Which Arduino board are you using?

Which version of the Arduino IDE are you using?

Hi,
Use 115200baud for the serial monitor.

Tom... :smiley: :+1: :coffee: :australia:

Using a UNO with 1.8.19.

OK, I don't know of any problems with that combination

has your Uno CH340 as USB chip?

No, it's a 328.
EDIT: Sorry, reckon I didn't read your question correctly. The MCU is 328, but I guess you mean the tiny square chip near the USB socket. Can't identify that.

BTW, I almost always get two identical lines at the start of any printing, directly following upload.

because the sketch starts and then Serial Monitor reconnects and resets the Arduino

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.