trying to wrap 288 element array on serial.print

I want to see all the elements of my array on my serial monitor without having to use the slide bar. wrapping is what i want.
i've googled it and everybody seems to want to talk about strings, which seems easier to deal with.

is there a way i can set a wrap length for serial.print an array ?

pratto:
I want to see all the elements of my array on my serial monitor without having to use the slide bar. wrapping is what i want.
i've googled it and everybody seems to want to talk about strings, which seems easier to deal with.

is there a way i can set a wrap length for serial.print an array ?

Yes, but you have to do it when you are printing. Without see your code, after some number of Serial.print, make one of them a Serial.println.

Paul

Try this for ideas

byte anArray[288];

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  randomSeed(analogRead(A6));
  for (int x = 0; x < 288; x++)
  {
    anArray[x] = random(256);
  }
  printArray();
}

void loop()
{
}

void printArray()
{
  byte columns = 10;
  for (int x = 0; x < 288; x++)
  {
    Serial.print(anArray[x]);
    Serial.print("\t");
    if ((x % columns) == 0)
    {
      Serial.println();
    }
  }
}

it works beautifully. i just wish i had figured it out. but not knowing about tab or %= was a bit of a stumbling block. but i was up to speed on random number generation.

I went through it and understand it, except for a few things.

why use bytes as the array type, as opposed to int ?

what is the purpose of this statement 'while (!Serial);' ?

why is there a number at the very top left, above the first column ?

why 115200 as opposed to 9600 ?

I ask to learn.

thanks.

pratto:
why use bytes as the array type, as opposed to int ?

It's just an illustration. Any variable type could be used. As long as you've got RAM to put it in along with any other variables the sketch might need.

pratto:
what is the purpose of this statement 'while (!Serial);' ?

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

pratto:
why is there a number at the very top left, above the first column ?

Be the processor. Step through printArray() one line at a time and analyze what each statement does. Use pencil and paper to keep track of changing variables if need be. Arduino Reference - Arduino Reference

pratto:
why 115200 as opposed to 9600 ?

It's faster.

why is there a number at the very top left, above the first column ?

Me being lazy. To tidy up the output try this

    if ((x % columns) == 0 && x != 0)

Thanks to you both.

It's just an illustration.

ok.

wait for the port to connect. got it.

115200 is faster. check.

I had figured out that the upper left number was an array element that wasn't properly evaluated by the
((x % columns) == 0), zero being the problem. and was flopping around trying to figure out the fix. i had ruled out if x=0 x=x+1;

but i put the revised code in and it is still a problem child. in your example the first row has 11 columns.
i'll keep working on it.

i don’t know if this makes any sense, but if i take 1 extra sensor reading, and eliminate the first, it works fine columnwise.

byte anArray[289];

void setup()
{
  Serial.begin(9600);
  while (!Serial);
  randomSeed(analogRead(A6));
  for (int x = 0; x < 289; x++)
  {
    anArray[x] = random(256);
  }
  printArray();
}

void loop()
{
}

void printArray()      
{
  byte columns = 10;
  for (int x = 1; x < 289; x++)
  {
    Serial.print(anArray[x]);
    Serial.print("\t");
    if ((x % columns) == 0)
   {
     Serial.println();
   }
  }
}

as you can see, i start at x = 1. this eliminates the column number vs. array number problem.

i am tired now, but it seems like it doesn’t matter if i take an extra reading, or lose one. i am taking hundreds and they don’t have to start at a certain time.

i can see that for some applications this approach wouldn’t work.

Better to do this

void printArray()
{
  byte columns = 10;
  for (int x = 0; x < 288; x++)
  {
    Serial.print(anArray[x]);
    Serial.print("\t");
    if ((x % columns) == columns - 1)
    {
      Serial.println();
    }
  }
}

ok. thanks. i'll plug it in tomorrow.

yep, that did the trick. aggravating. it looks so simple after it's been figured out.