Only 3/6 arrays working

I made 6 arrays all the same method but when i try to print each of their 6th index only the first 3 arrays that i made work, Could this be a storage issue even though it tells me
"sketch uses 8206 bytes (25%) of program storage space. Maximum is 32256 bytes.
Global variables use 856 bytes (41%) of dynamic memory, leaving 1192 bytes for local variables. Maximum is 2048 bytes."

#include <Stepper.h>
const int stepsPerRevolution = 100;  // change this to fit the number of steps per revolution
// for your motor


// initialize the stepper library on pins 8 through 11:
Stepper whiteStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
}

void loop() {
  Serial.begin(9600);
  //Setting up the white face
  Serial.println("With the white side towards you and the red end facing up enter the colors of each square by typing");
  Serial.println("for example 'wrbgwybog'.");
  while (Serial.available() == 0) {}
  String topWhite = Serial.readString();
  String aW = topWhite.substring(0, 1);
  String bW = topWhite.substring(1, 2);
  String cW = topWhite.substring(2, 3);
  String dW = topWhite.substring(3, 4);
  String wCore = topWhite.substring(4, 5);
  String fW = topWhite.substring(5, 6);
  String gW = topWhite.substring(6, 7);
  String hW = topWhite.substring(7, 8);
  String iW = topWhite.substring(8, 9);
  String white[] = {aW, bW, cW, dW, wCore, fW, gW, hW, iW};
  //Setting up the Blue face
  Serial.println("With the Blue side towards you and the white end facing up enter the colors of each square by typing");
  while (Serial.available() == 0) {}
  String topBlue = Serial.readString();  
  String aB = topBlue.substring(0, 1);
  String bB = topBlue.substring(1, 2);
  String cB = topBlue.substring(2, 3);
  String dB = topBlue.substring(3, 4);
  String bCore = topBlue.substring(4, 5);
  String fB = topBlue.substring(5, 6);
  String gB = topBlue.substring(6, 7);
  String hB = topBlue.substring(7, 8);
  String iB = topBlue.substring(8, 9);
  String blue[] = {aB, bB, cB, dB, bCore, fB, gB, hB, iB};
  //Setting up the Orange face
  Serial.println("With the Orange side towards you and the white end facing up enter the colors of each square by typing");
  while (Serial.available() == 0) {}
  String topOrange = Serial.readString(); 
  String aO = topOrange.substring(0, 1);
  String bO = topOrange.substring(1, 2);
  String cO = topOrange.substring(2, 3);
  String dO = topOrange.substring(3, 4);
  String oCore = topOrange.substring(4, 5);
  String fO = topOrange.substring(5, 6);
  String gO = topOrange.substring(6, 7);
  String hO = topOrange.substring(7, 8);
  String iO = topOrange.substring(8, 9);
  String orange[] = {aO, bO, cO, dO, oCore, fO, gO, hO, iO};
//Setting up the Green face
  Serial.println("With the Green side towards you and the white end facing up enter the colors of each square by typing");
  while (Serial.available() == 0) {}
  String topGreen = Serial.readString(); 
  String aG = topGreen.substring(0, 1);
  String bG = topGreen.substring(1, 2);
  String cG = topGreen.substring(2, 3);
  String dG = topGreen.substring(3, 4);
  String gCore = topGreen.substring(4, 5);
  String fG = topGreen.substring(5, 6);
  String gG = topGreen.substring(6, 7);
  String hG = topGreen.substring(7, 8);
  String iG = topGreen.substring(8, 9);
  String green[] = {aG, bG, cG, dG, gCore, fG, gG, hG, iG};
//Setting up the Red face
  Serial.println("With the Red side towards you and the white end facing up enter the colors of each square by typing");
  while (Serial.available() == 0) {}
  String topRed = Serial.readString(); 
  String aR = topRed.substring(0, 1);
  String bR = topRed.substring(1, 2);
  String cR = topRed.substring(2, 3);
  String dR = topRed.substring(3, 4);
  String rCore = topRed.substring(4, 5);
  String fR = topRed.substring(5, 6);
  String gR = topRed.substring(6, 7);
  String hR = topRed.substring(7, 8);
  String iR = topRed.substring(8, 9);
  String red[] = {aR, bR, cR, dR, rCore, fR, gR, hR, iR};
//Setting up the Yellow face
  Serial.println("With the Yellow side towards you and the Red end facing up enter the colors of each square by typing");
  while (Serial.available() == 0) {}
  String topYellow = Serial.readString(); 
  String aY = topYellow.substring(0, 1);
  String bY = topYellow.substring(1, 2);
  String cY = topYellow.substring(2, 3);
  String dY = topYellow.substring(3, 4);
  String yCore = topYellow.substring(4, 5);
  String fY = topYellow.substring(5, 6);
  String gY = topYellow.substring(6, 7);
  String hY = topYellow.substring(7, 8);
  String iY = topYellow.substring(8, 9);
  String yellow[] = {aY, bY, cY, dY, yCore, fY, gY, hY, iY};
//test the arrays
Serial.println(white[6]);
Serial.println(blue[6]);
Serial.println(orange[6]);
delay(5000);
Serial.println(green[6]);
Serial.println(red[6]);
Serial.println(yellow[6]);


  
  delay(1000000);
  int i = 0;
  while (i < 258) {
    whiteStepper.setSpeed(100);
    whiteStepper.step(stepsPerRevolution / 100);
    i++;
    if (i >= 258) {
      delay(2000);
      i = 0;
    }
  }
}

Is this a duplicate post? Lots is the same as in another post earlier today.

The message "doesn't work" contains no information. What comes out then?

What crap is this? Starting Serial is done once in Setup(), not ever time of loop.

You need to learn how to declare variables, and where to do it. This code looks "not good".

That statement produces a delay of 1000s = 16 minutes 40 seconds.

i wasnt worried about the setup because i dont neccisarily want to run the program as a loop. i also know very little about this language. But when the code Serial.println(white[6]) runs it gives the proper output of "w" and when printing from the arrays blue[6] and orange[6] but the 3 arrays i made last, green[6], red[6], and yellow[6] give nothing when printed. " ". all of the arrays should print out a single letter that is a string and not a char.

I suggest braking the issue down to lower levels. There You can test different constructions and find out what's working and what's going wrong. Maybe some old fashioned Basic guy will take on Your question.
I sign off.

My guess is that you run out of ram and creating new String variables fails. I added code to display each line that was entered and the last two don't show up.

Here is a version that doesn't use String so it doesn't run out of memory:

#include <Stepper.h>
const int stepsPerRevolution = 100;  // change this to fit the number of steps per revolution
// for your motor


// initialize the stepper library on pins 8 through 11:
Stepper whiteStepper(stepsPerRevolution, 8, 9, 10, 11);

char white[9], blue[9], orange[9], green[9], red[9], yellow[9];

void setup()
{
  Serial.begin(9600);

  //Setting up the white face
  Serial.println("With the white side towards you and the red end facing up enter the colors of each square by typing");
  Serial.println("for example 'wrbgwybog'.");
  while (Serial.available() < 9) {}
  white[0] = Serial.read();
  white[1] = Serial.read();
  white[2] = Serial.read();
  white[3] = Serial.read();
  white[4] = Serial.read();
  white[5] = Serial.read();
  white[6] = Serial.read();
  white[7] = Serial.read();
  white[8] = Serial.read();

  //Setting up the Blue face
  Serial.println("With the Blue side towards you and the white end facing up enter the colors of each square by typing");
  while (Serial.available() < 9) {}
  blue[0] = Serial.read();
  blue[1] = Serial.read();
  blue[2] = Serial.read();
  blue[3] = Serial.read();
  blue[4] = Serial.read();
  blue[5] = Serial.read();
  blue[6] = Serial.read();
  blue[7] = Serial.read();
  blue[8] = Serial.read();

  //Setting up the Orange face
  Serial.println("With the Orange side towards you and the white end facing up enter the colors of each square by typing");
  while (Serial.available() < 9) {}
  orange[0] = Serial.read();
  orange[1] = Serial.read();
  orange[2] = Serial.read();
  orange[3] = Serial.read();
  orange[4] = Serial.read();
  orange[5] = Serial.read();
  orange[6] = Serial.read();
  orange[7] = Serial.read();
  orange[8] = Serial.read();

  //Setting up the Green face
  Serial.println("With the Green side towards you and the white end facing up enter the colors of each square by typing");
  while (Serial.available() < 9) {}
  green[0] = Serial.read();
  green[1] = Serial.read();
  green[2] = Serial.read();
  green[3] = Serial.read();
  green[4] = Serial.read();
  green[5] = Serial.read();
  green[6] = Serial.read();
  green[7] = Serial.read();
  green[8] = Serial.read();

  //Setting up the Red face
  Serial.println("With the Red side towards you and the white end facing up enter the colors of each square by typing");
  while (Serial.available() < 9) {}
  red[0] = Serial.read();
  red[1] = Serial.read();
  red[2] = Serial.read();
  red[3] = Serial.read();
  red[4] = Serial.read();
  red[5] = Serial.read();
  red[6] = Serial.read();
  red[7] = Serial.read();
  red[8] = Serial.read();

  //Setting up the Yellow face
  Serial.println("With the Yellow side towards you and the Red end facing up enter the colors of each square by typing");
  while (Serial.available() < 9) {}
  yellow[0] = Serial.read();
  yellow[1] = Serial.read();
  yellow[2] = Serial.read();
  yellow[3] = Serial.read();
  yellow[4] = Serial.read();
  yellow[5] = Serial.read();
  yellow[6] = Serial.read();
  yellow[7] = Serial.read();
  yellow[8] = Serial.read();

  //test the arrays
  Serial.println(white[6]);
  Serial.println(blue[6]);
  Serial.println(orange[6]);
  Serial.println(green[6]);
  Serial.println(red[6]);
  Serial.println(yellow[6]);
}

void loop()
{
}

thnak you, im going to just get rid of the vairables and put the input from the serial monitor straight to the array. I had left the vairables in order to make it easier when rearranging the arrays but ill just have to find a way around it.

I'm making a Rubik's cube solver and decided to save the sequence of each face as an array but when I try to print from the array to the serial monitor it gives garbage outputs. The baud rates are synced and I've run the 'Fix encoder and reload'. I assume it's a problem with the array itself but I know very little about arrays.

#include <Stepper.h>
const int stepsPerRevolution = 100;  // change this to fit the number of steps per revolution
// for your motor


// initialize the stepper library on pins 8 through 11:
String aW = "";
String bW = "";
String cW = "";
String dW = "";
String wCore = "";
String fW = "";
String gW = "";
String hW = "";
String iW = "";
String topWhite = "";
String white[] = {};
Stepper whiteStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  Serial.begin(9600);
  Serial.println("With the white face towards you and the red end facing up enter the colors of each square by typing");
  Serial.println("for example 'wrbgwybog'.");
  while (Serial.available() == 0) {}
  topWhite = Serial.readString();
  aW = topWhite.substring(0, 1);
  bW = topWhite.substring(1, 2);
  cW = topWhite.substring(2, 3);
  dW = topWhite.substring(3, 4);
  wCore = topWhite.substring(4, 5);
  fW = topWhite.substring(5, 6);
  gW = topWhite.substring(6, 7);
  hW = topWhite.substring(7, 8);
  iW = topWhite.substring(8, 9);
  String white[] = {aW, bW, cW, dW, wCore, fW, gW, hW, iW};
}
int i = 0;

void loop() {
  Serial.println(white[0]);
  Serial.println(white[1]);
  Serial.println(cW);
  Serial.println(dW);
  Serial.println(wCore);
  Serial.println(fW);
  Serial.println(gW);
  Serial.println(hW);
  Serial.println(iW);
  delay(10000);
  while (i < 258) {
    whiteStepper.setSpeed(100);
    whiteStepper.step(stepsPerRevolution / 100);
    i++;
    Serial.println(i);
    if (i >= 258) {
      delay(2000);
      i = 0;
    }
  }
}

You have more than one array named White each with a different scope which at the best is confusing. Also, because the global one cannot hold any data because you did not specify how many elements it has then saving anything to it will corrupt other data by writing over memory allocated to it

When you print elements of the White array in loop() it is the global (empty) White array that you are printing, hence you get garbage

How would I be able to get the array from void setup() to the void loop? I had made it a global variable in hopes that it would just transfer the data between the two.

The String white[] variable you declared in setup() is a separate variable from the String white[] variable you declared globally.

Try declaring the global 'white' with enough elements and use that instead of creating a new one.

String white[9];

  white[0] = aW;
  white[1] = bW;
 ...
  white[7] = hW;
  white[8] = iW;

Note: You don't really need aW through iW. You can store directly into the corresponding white[n].

You are aware that the array gets destroyed directly after creation?
So the optimizer will not even bother to create code for that staement.

@davidvalen, do not cross-post. Threads merged.

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