Need a little help as beginner

hello, i am trying to make a automated cocktail bar with an arduino and 2 nema 17 steppers, i tryed different sketches but nothing was like it needed to be with my components so i make a mix from alot of different sketches, after a long time trying to fix all the errors i could compile the code without errors.
every axis (X and Z) can be homed now, and i can let the axis move with an serial input, but i always get an error when i try the command " F2 H2500 W3000" also command "F" gives me the same result even with a number after it
i get the answer "Hold and wait duration parameters cannot be lower than or equal to 0"
so i think my problem is in the "void pour" section.
is there somebody who can help me on the way? and can explain why it went wrong?
here is the sketch;

#include "AccelStepper.h"
#include "Configuration.h"

String serialBuffer = "";
String actions[TOTAL_ACTIONS];

int counter = 0;
int lastIndex = 0;

AccelStepper stepperX(X_INTERFACE_TYPE, X_STEP_PIN, X_DIR_PIN);  // Define a stepper and the pins it will use
AccelStepper stepperZ(Z_INTERFACE_TYPE, Z_STEP_PIN, Z_DIR_PIN);  // Define a stepper and the pins it will use


void setup() {
  Serial.begin(9600);  // Serial port for debugging
  //maestroSerial.begin(9600); // Servo controller
  //Serial2.begin(9600); // Bluetooth module
  stepperX.setMaxSpeed(X_MAX_SPEED);     // Sets the maximum speed the X axis accelerate up to
  stepperZ.setMaxSpeed(Z_MAX_SPEED);     // Sets the maximum speed the X axis accelerate up to
  pinMode(X_ENDSTOP_PIN, INPUT_PULLUP);  // Initialize endstop pin with the internal pull-up resistor enabled
  pinMode(Z_ENDSTOP_PIN, INPUT_PULLUP);  // Initialize endstop pin with the internal pull-up resistor enabled
  homeXAxis();                           // Return the X axis to it's home position at the startup
  delay(5000);                           // waits for a second
  homeZAxis();                           // Return the X axis to it's home position at the startup
}

void homeXAxis() {
  int endStopState = digitalRead(X_ENDSTOP_PIN);

  while (endStopState == HIGH) {
    stepperX.moveTo(100);
    stepperX.setSpeed(X_HOME_SPEED);
    stepperX.runSpeed();
    endStopState = digitalRead(X_ENDSTOP_PIN);
  }

  stepperX.moveTo(stepperX.currentPosition() - 50);
  while (stepperX.distanceToGo() != 0) {
    stepperX.setSpeed(X_PARK_SPEED * -1);
    stepperX.runSpeed();
  }

  endStopState = digitalRead(X_ENDSTOP_PIN);

  while (endStopState == HIGH) {
    stepperX.moveTo(100);
    stepperX.setSpeed(X_PARK_SPEED);
    stepperX.runSpeed();
    endStopState = digitalRead(X_ENDSTOP_PIN);
  }
  stepperX.setCurrentPosition(0);
}

void homeZAxis() {

  int endStopState = digitalRead(Z_ENDSTOP_PIN);
  while (endStopState == HIGH) {

    stepperZ.moveTo(50);
    stepperZ.setSpeed(Z_HOME_SPEED);
    stepperZ.runSpeed();
    endStopState = digitalRead(Z_ENDSTOP_PIN);
  }

  stepperZ.moveTo(stepperZ.currentPosition() - 25);

  while (stepperZ.distanceToGo() != 0) {
    stepperZ.setSpeed(Z_PARK_SPEED * -1);
    stepperZ.runSpeed();
  }
  endStopState = digitalRead(Z_ENDSTOP_PIN);


  while (endStopState == HIGH) {
    stepperZ.moveTo(50);
    stepperZ.setSpeed(Z_PARK_SPEED);
    stepperZ.runSpeed();
    endStopState = digitalRead(Z_ENDSTOP_PIN);
  }

  stepperZ.setCurrentPosition(0);
}


void loop() {
  while (Serial.available() > 0) {
    char ch = Serial.read();
    serialBuffer += ch;
    if (ch == '\n') {
      for (int i = 0; i < serialBuffer.length(); i++) {
        if (serialBuffer.substring(i, i + 1) == ",") {
          actions[counter] = serialBuffer.substring(lastIndex, i);
          lastIndex = i + 1;
          counter++;
        }

        if (i == serialBuffer.length() - 1) {
          actions[counter] = serialBuffer.substring(lastIndex, i);
        }
      }

      for (int z = 0; z < TOTAL_ACTIONS; z++) {
        if (actions[z] != "0") {
          parseInput(actions[z]);
        }
      }

      Serial.println("voidloop");

      for (int y = 0; y < TOTAL_ACTIONS; y++) {
        actions[y] = "0";
      }

      serialBuffer = "";
      counter = 0;
      lastIndex = 0;

      serialFlush();
    }
  }
}

void parseInput(String input) {
  input.trim();
  byte command = input.charAt(0);

  switch (command) {
    case 'H':
      homeXAxis();
      homeZAxis();
      break;
    case 'X':
      moveXTo(input);
      break;
    case 'Z':
      moveZTo(input);
      break;
    case 'F':
      pour(input);
      break;
  }
}

void moveXTo(String input) {
  int pos = input.substring(1).toInt();

  Serial.print("X goes to: ");
  Serial.println(pos);

  Serial.println(input);

  if (pos < 0 && pos >= X_MAX_POS) {
    stepperX.setAcceleration(X_ACCELERATION);
    stepperX.moveTo(pos);
    if (pos < stepperX.currentPosition()) {
      stepperX.setSpeed(-100);
    } else {
      stepperX.setSpeed(100);
    }
    while (stepperX.distanceToGo() != 0) {
      stepperX.run();
    }
  } else {
    Serial.println("Position should be between -9000 and 0");
  }
}

void moveZTo(String input) {
  int pos = input.substring(1).toInt();

  Serial.print("Z goes to: ");
  Serial.println(pos);

  Serial.println(input);

  if (pos < 0 && pos >= Z_MAX_POS) {
    stepperZ.setAcceleration(Z_ACCELERATION);
    stepperZ.moveTo(pos);
    if (pos < stepperZ.currentPosition()) {
      stepperZ.setSpeed(-100);
    } else {
      stepperZ.setSpeed(100);
    }
    while (stepperZ.distanceToGo() != 0) {
      stepperZ.run();
    }
  } else {
    Serial.println("Position should be between -4995 and 0");
  }
}

void pour(String input) {
  int holdDuration = getParameterValue(input, input.indexOf("h"));
  int waitDuration = getParameterValue(input, input.indexOf("w"));
  int times = getParameterValue(input, input.indexOf("t"));
  int count = 0;

  if (holdDuration > 0 && waitDuration > 0) {
    for (int i = 0; i < times; i++) {
      moveZTo(String(Z_MAX_POS));
      delay(holdDuration - HOLD_DELAY_IN_Z_MAX);
      moveZTo(String(0));
      //moveZTo(0);           origineel
      if (times - 1 > count) {
        delay(waitDuration);
      } else {
        delay(DELAY_BETWEEN_INGREDIENTS);
      }

      count++;
    }
  } else {
    Serial.println("Hold and wait duration parameters cannot be lower than or equal to 0");
  }
}

int getParameterValue(String input, int z) {
  for (int y = z + 1; y < input.length(); y++) {
    if (input.substring(y, y + 1) == " ") {
      return input.substring(z + 1, y).toInt();
    }
    if (y == input.length() - 1) {
      return input.substring(z + 1, y + 1).toInt();
    }
  }
}


void serialFlush() {
  while (Serial.available() > 0) Serial.read();
}

You're a bit light on debug prints and comments.

Do you need single quotes instead of double? i.e 'h' instead of "h"

You try the command:

but in code:

Do you think that the 'w' and 'W' are the same letters?

i tryed copy past, not really an programmer :blush:

i thaught it would be the same

Apparently, both are allowed.

i follow the commands where the sketch is based on trough his command on this github page

not for controller

but as i see the command F should also do something so i tryed also letter F and a number after is but still get the error

See reply 2

that's because it is my first arduino project that i want to succeed, not good in coding, only did copy paste from different sketches because the original void pour section was with a servo motor, so i copyed a part from somebody else who used an stepper motor, as result that i can home now and manually give a command like "Z-300" but further than that i dont get

No, all what it doing - try to read your H and W instructions which are incorrectly formatted. Your code doesn't contain any addition code for "F" letter

If you do not intend to learn, I think you will hardly succeed with only copy-paste skills :slight_smile:

the F letter should also be in the void pour section if i am getting it right?K

i had bought an E book of programming C++ but it's verry hard for me. it would be nice if i could learn on a practial way but i don't think something like this exists..

Indeed.
Exactly in poor() function you tried to parse "W" and "H" instructions. I don't see any addition code for parsing "F" itself there.

Start from adding the debug output (just a Serial.print() with variables in question) to your code, as suggested in post#2.
Show the edited code and its output to the forum

For example, change the parseInput() this way

after that we will know, what is entered to the procedure and what is the command used in switch.

ok, thank you for the answer! i'm gonna try that an then come back to you