Create a sketch with AccelStepper.h

The sketch with the new integrer stepsToGo:

// Example 3 - Receive with start- and end-markers

const byte numChars = 32;
char receivedChars[numChars];
int stepsToGo =0 ;
boolean newData = false;
void setup() {
     
    Serial.begin(9600);
    Serial.println("<Arduino is ready>");
   
    
}

void loop() {
    recvWithStartEndMarkers();
    showNewData();
}

void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;
    while (Serial.available() > 0 && newData == false  ) {
        rc = Serial.read();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        }

        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

void showNewData() {
  
    if (newData == true) {
        Serial.print("This just in ... ");
        Serial.println(receivedChars);
        Serial.println(stepsToGo);
        newData = false;
        
    }
    delay(1000);
}

Brinarpi:
I'll create the integrer but it cant print the same as the sended value.

That's because you have not added any code to take the data in receivedChars[] and convert it to an integer and save it into your variable stepsToGo.

I don't understand how you thought that the program could work without doing that?

Have a look at what I have added in this version

// Example 3 - Receive with start- and end-markers

const byte numChars = 32;
char receivedChars[numChars];
int stepsToGo =0 ;
boolean newData = false;
void setup() {
     
    Serial.begin(9600);
    Serial.println("<Arduino is ready>");
   
   
}

void loop() {
    recvWithStartEndMarkers();
    parseData();  // new
    showNewData();
}

void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;
    while (Serial.available() > 0 && newData == false  ) {
        rc = Serial.read();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        }

        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

void showNewData() {
 
    if (newData == true) {
        Serial.print("This just in ... ");
        Serial.println(receivedChars);
        Serial.println(stepsToGo);
        newData = false;
       
    }
    // delay(1000);  // this should not be here
}

   // new
void parseData() { 
   stepsToGo = atoi(receivedChars);
}

Also NOTE that I told you to put the delay(1000); in the other program - the sending program.

...R

Ohh dear Robin. The sender is a smaller problem . I have already added the delay as you ask.
The biggest is that I lost you here. So let me say that is working, but I did not understanding why...
But as you say, after a couple of hours thinking.......So thats what Im doing now.
In any case I print out on paper the sketches and when I drive the car, make a compare between. Maybe I will understand it. Becouse I am not so young (52) its coming slower, but I'll never give up.
Please let me explane with words the problem, maybe it is a little additional help for me.

There is only 1 segment left of the project. To implement in the sender, the push buttons, and the LCD16/2 and its finish. Try to do it alone......

Anyway thanks a lot for everything what you help to me. You are really a MAN (with capital characters).

Arpad from Hungary

Brinarpi:
Becouse I am not so young (52) its coming slower, but I'll never give up.

You are 13 years younger than me :slight_smile:

...R

Hello again

I was analize your way of the program build. First in the loop you tell what kind of jobs are like adress.

void loop() {
    recvWithStartEndMarkers();
    parseData(); 
    showNewData();

And after explain all of them in separated void like:

void recvWithStartEndMarkers()
{

}

Is that workable if I put in the loop the stepping program like adress(as others are) and open a void on the end like last void?

void loop() {
    recvWithStartEndMarkers();
    parseData();  // new
    showNewData();
    stepping();
void stepping()
{
// put an accel stepper program here
}

Is that way is correct?

A

Brinarpi:
Is that way is correct?

Yes. Organizing programs into separate single purpose functions makes them much easier to develop, test and debug.

Of course you also need to get the details right :slight_smile:

Maybe have a look at Planning and Implementing a Program

...R