Replacing String objects with C strings

I used the strstr() function and it seems to be working. I finally got the code to recognize the output. So, a minor victory! Thanks a ton.

Now, I use this information to set the home position for my CNC, or to let me know if my bed over-traveled in the +X, -X, +Y or -Y directions. Each limit has it's own L,XXXX code. In the grand scheme of things, I'd like to be able to call a function like "triangle" or "square" that would fill my stepCommand array with the desired string commands. This involves loading my char *stepCommand array with passed from functions, which I'm guessing is going to be a pain. But, I'll research that and see what I can do.

Serial Monitor output at limit switch activation:

-30000XG --> IF LOOP
Character Read:
FFFFFF86 ---> Character 0
A ---> Character 1
4C ---> Character 2
2C ---> Character 3
31 ---> Character 4
36 ---> Character 5
33 ---> Character 6
39 ---> Character 7
32 ---> Character 8
D ---> Character 9
A ---> Character 10
2A ---> Character 11

?
L,16392

  • --> Read String
    Write Q Here
/*
CNC Bed Sketch 

This program drives a Peter Norburg SD4DEU Stepper Driver board running SD4DNCRouter firmware connecting at 9600 Baud.
 
 
*/

//******************Constants***********
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX

char homePosition[5] = "0XYG";



//******************Variables***********

char readString[70];
char c;
int index = 0;
int commandNumber = 0;
int numCommands = 0;

//****************Function Prototypes******
long convertToSteps(int inches);

//***************Setup******************************
void setup() {
  delay(1000);
  
  //readString[0] = '\0';    //Add a null termination to readString
  
  Serial.begin(9600);    //Begin serial communication at 9600
  mySerial.begin(9600);  //Set software serial baud rate
  
  randomSeed(analogRead(0)); 
  
  // Initialize Stepperboard Values
  mySerial.write("!");      //reset Stepper Board
  delay(50);
  mySerial.write("1500R");  //Set Run Rate
  delay(50);
  mySerial.write("800P");  //Set Ramp Rate
  delay(1000);
}

//*************Main Program Loop************************
void loop() {
 
 
 char* stepCommand[] = {    //Load up CNC Patterns into string array
 "30000XG", 
 "-30000XG"
  }; 
 
 int numCommands = (sizeof(stepCommand)/sizeof(char*)); //Calculate array size

 while(mySerial.available()){
   c = mySerial.read();   //get one byte from buffer 
   readString[index++] = c;    //increment array (original array index is returned)
   readString[index] = '\0';    //Add NULL to next index
   //i=i+1;
   //Serial.print(c);
   //Serial.println(" --> c charachter byte");
   if(readString[index-1]== '*'){
     mySerial.write(stepCommand[commandNumber]);
     Serial.print(stepCommand[commandNumber]);
     Serial.println(" --> IF LOOP");
     commandNumber++;
     if(commandNumber == numCommands){    //if the max number of commands is reached...
        commandNumber = 0;                //reset command number back to zero
     }  
     break;
   } 
 }

 mySerial.write("L");
  
 if(strlen(readString) > 0){
   Serial.println("Character Read: ");
   for(int j=0; j < strlen(readString); j++){
     Serial.print(readString[j], HEX);
     Serial.print(" ---> Character ");
     Serial.println(j);
   }
   Serial.println("======================");
   Serial.print(readString);
   Serial.println(" --> Read String");
   char response[10];
   response[0] = '\0';
   
   
   
   if((strstr(readString, "L,16392")) != 0){
     Serial.println("Write Q Here");
     Serial.println("");
   }
   else{
     Serial.println("Strings not Equal");
     Serial.println("");
   }
   readString[0] = '\0';      //clear the array
   index = 0;
 }  
}
//*********************FUNCTIONS***************************
long convertToSteps(int inches){
  long steps = 130435 * inches;  //there are 130435 steps in 1-inch
  return(steps);
}
//**************************************************************************