Multiple Serial Read from Serial Monitor

Hey Arduino Community! I am currently working on a project to control two stepper motors using an Arduino Mega. My main question is, how do you serial read multiple times within a loop? Basically the User will send me a recipe in a 5 char string beginning with "A". Once this string is received, I store it and then want to wait for a GO command string from the serial monitor to run my specified motor functions received from the recipe string. The if loop including the Serial.avaiable() > 0 will not activate

void setup() {
Serial.begin(9600);
stepper.setSpeed(300);
stepper1.setSpeed(300);
pinMode(stepperPin11, OUTPUT);
pinMode(stepperPin10, OUTPUT);
pinMode(stepperPin9, OUTPUT);
pinMode(stepperPin8, OUTPUT);
pinMode(stepperPin39, OUTPUT);
pinMode(stepperPin37, OUTPUT);
pinMode(stepperPin35, OUTPUT);
pinMode(stepperPin33, OUTPUT);
Serial.println("Enter Prescription Data");
}

void loop() {
char Hopper1 = 0;
char Hopper2 = 0;
char Dispense1 = 0;
char Dispense2 = 0;
result = Serial.available();
if (Serial.available()>0 ) {
// delay(10);
codeword = Serial.readStringUntil('\n');
gotSomething = 1;

if (gotSomething == 1){
Serial.println(codeword);
gotSomething = 0;

if (codeword.startsWith("A")){
Hopper1 = codeword.charAt(1);
Hopper2 = codeword.charAt(3);
Dispense1 = codeword.charAt(2);
Dispense2 = codeword.charAt(4);
Serial.println("Hopper 1 is 1 for ON 0 for OFF:");
Serial.println(Hopper1);
Serial.println("Pills to Dispense from Hopper 1:");
Serial.println(Dispense1);
Serial.println("Hopper 2 is 1 for ON 0 for OFF");
Serial.println(Hopper2);
Serial.println("Pills to Dispense from Hopper 2:");
Serial.println(Dispense2);
whensomething = 1;
}
if (whensomething == 1 && Serial.available()>0 ) {
Serial.println("Waiting for G0000");
Go = Serial.readStringUntil('\n');
Letsgo = 1;
}

if (Letsgo == 1 && Go.startsWith("G") && Dispense1 == 49 && Dispense2 == 48){
stepper.step(-2048);
stepper.step(-50);
stepper.step(200);
stepper.step(-150);
Serial.println("Complete");

}

Please use code tags when posting code. Please edit your post and

Type

[code] before the code
Type [/code]

after the code

And please post complete code including the part before setup()

#include <Stepper.h>
#include <SoftwareSerial.h>
#define STEPS 64 // Stepper Motor Steps
Stepper stepper(STEPS, 8, 10, 9, 11);
Stepper stepper1(STEPS, 39, 35, 37, 33);
SoftwareSerial mySerial(0, 1); // RX, TX
int stepperPin11 = 11;
int stepperPin10 = 10;
int stepperPin9= 9;
int stepperPin8 = 8;
int stepperPin39 = 39;
int stepperPin37 = 37;
int stepperPin35= 35;
int stepperPin33 = 33;
char D;
char DoneArray[5] = {D, 0, 0, 0, 0};
String Go = String(6);
String codeword = String(6);
char code = 1;
int result = 0;
bool gotSomething = 0;
bool whensomething = 0;
bool Letsgo = 0;

void setup() {
Serial.begin(9600);
stepper.setSpeed(300);
stepper1.setSpeed(300);
pinMode(stepperPin11, OUTPUT);
pinMode(stepperPin10, OUTPUT);
pinMode(stepperPin9, OUTPUT);
pinMode(stepperPin8, OUTPUT);
pinMode(stepperPin39, OUTPUT);
pinMode(stepperPin37, OUTPUT);
pinMode(stepperPin35, OUTPUT);
pinMode(stepperPin33, OUTPUT);
Serial.println(“Enter Prescription Data”);
}

void loop() {
char Hopper1;
char Hopper2;
char Dispense1;
char Dispense2;
result = Serial.available();
if (Serial.available()>0 ) {
// delay(10);
codeword = Serial.readStringUntil(’\n’);
gotSomething = 1;

if (gotSomething == 1){
Serial.println(codeword);
gotSomething = 0;

if (codeword.startsWith(“A”)){
Hopper1 = codeword.charAt(1);
Hopper2 = codeword.charAt(3);
Dispense1 = codeword.charAt(2);
Dispense2 = codeword.charAt(4);
Serial.println(“Hopper 1 is 1 for ON 0 for OFF:”);
Serial.println(Hopper1);
Serial.println(“Pills to Dispense from Hopper 1:”);
Serial.println(Dispense1);
Serial.println(“Hopper 2 is 1 for ON 0 for OFF”);
Serial.println(Hopper2);
Serial.println(“Pills to Dispense from Hopper 2:”);
Serial.println(Dispense2);
whensomething = 1;

if (whensomething == 1) {
Letsgo = 1;
}

if (Letsgo == 1 && Dispense1 == 49 && Dispense2 == 48){
stepper.step(-2048);
stepper.step(-50);
stepper.step(200);
stepper.step(-150);
Serial.println(“You did this”);
Serial.write(DoneArray[5]);
}
if (Letsgo == 1 && Go.startsWith(“G”) && Dispense1 == 2 && Dispense2 == 0 ) {

stepper.step(-2048);
stepper.step(-50);
stepper.step(200);
stepper.step(-150);
stepper.step(-2048);
stepper.step(-50);
stepper.step(200);
stepper.step(-150);
Serial.write(DoneArray[5]);
}

I also said "please use code tags" :wink: so it looks like

code here

you're obviously no help. Off you go

Lukelafata:
you're obviously no help. Off you go

and you are obviously not listening.
Don't expect too much help with an attitude like that.

My main question is, how do you serial read multiple times within a loop?

That should be rather obvious. If you need to read N characters, don't read anything until there are N characters available to read.

Of course, your attitude sucks.

Basically the User will send me a recipe in a 5 char string beginning with "A"

I can't think of many recipes that short.

char DoneArray[5] = {D, 0, 0, 0, 0};
...   
Serial.write(DoneArray[5]);

You need to retake "C arrays 101"

Lukelafata:
you're obviously no help. Off you go

I know how to solve this problem but I would like to see the OP's response to Reply #5 first.

...R