Analog Input + A4988 + NRF24L010

Hi, I have a problem. I'm starting with arduino
What am I looking for with this project?
is that the Stepper Motor controlled by an a4988 "copy" the movement of the potentiometer. all this through RF

With this programming the idea takes shape but the engine has a lot of noise and false steps.
What will I be missing?

I think my problem lies in converting the increase and decrease of the analog input into pulses.
And I do not know if the solution you raise is correct.

I attach codes.
Greetings, thank you very much.

This is the RECEIVER's code

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
 
//Declaremos los pines CE y el CSN
#define CE_PIN 9
#define CSN_PIN 10
int Z = 0;
//Variable con la dirección del canal que se va a leer
byte direccion[5] ={'c','a','n','a','l'}; 

//creamos el objeto radio (NRF24L01)
RF24 radio(CE_PIN, CSN_PIN);

//vector para los datos recibidos
float datos[3];

void setup()
{
 //inicializamos el NRF24L01 
  radio.begin();
  //inicializamos el puerto serie
  Serial.begin(9600); 
  
  //Abrimos el canal de Lectura
  radio.openReadingPipe(1, direccion);
  
    //empezamos a escuchar por el canal
  radio.startListening();
 
}
 
void loop() {
 uint8_t numero_canal;
 //if ( radio.available(&numero_canal) )
 if ( radio.available() )
 {    
     //Leemos los datos y los guardamos en la variable datos[]
     radio.read(datos,sizeof(datos));
     
     //reportamos por el puerto serial los datos recibidos
     Serial.print("Dato0= " );
     Serial.print(datos[0]);
     Serial.print(" V, ");
     Serial.print("Dato1= " );
     Serial.print(datos[1]);
     Serial.print(" ms, ");
     Serial.print("Dato2= " );
     Serial.println(datos[2]);
      if (datos[0] > datos[1]) digitalWrite(5, HIGH);
      else digitalWrite (5,LOW);
      for(Z = 0; Z < ((datos[0] - datos[1])); Z++);
      {
    digitalWrite(8,HIGH);
    delayMicroseconds(500);
    digitalWrite(8,LOW);
    delayMicroseconds(500);
  }//comparacion para determinar la direccion
 
  for(Z = 1; Z < ((datos[1] - datos[0])); Z++);
  {
    digitalWrite(8,HIGH);
    delayMicroseconds(500);
    digitalWrite(8,LOW);
    delayMicroseconds(500);
  }

 }
 else
 {
     Serial.println("No hay datos de radio disponibles");
 }
 
}

This is the code of the TRANSMITTER

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


//Declaremos los pines CE y el CSN
#define CE_PIN 9
#define CSN_PIN 10
 
//Variable con la dirección del canal por donde se va a transmitir
byte direccion[5] ={'c','a','n','a','l'};

//creamos el objeto radio (NRF24L01)
RF24 radio(CE_PIN, CSN_PIN);

//vector con los datos a enviar
float datos[3];

void setup()
{
  //inicializamos el NRF24L01 
  radio.begin();
  //inicializamos el puerto serie
  Serial.begin(9600); 
 
//Abrimos un canal de escritura
 radio.openWritingPipe(direccion);
 
}
 
void loop()
{ 
  
 
 //cargamos los datos en la variable datos[]
 datos[0]=analogRead(A0);
 delay (10);
 datos[1]=analogRead (A0);
 datos[2]= digitalRead (8);
 //enviamos los datos
 bool ok = radio.write(datos, sizeof(datos));
  //reportamos por el puerto serial los datos enviados 
  if(ok)
  {
     Serial.print("Datos enviados: "); 
     Serial.print(datos[0]); 
     Serial.print(" , "); 
     Serial.print(datos[1]); 
     Serial.print(" , "); 
     Serial.println(datos[2]); 
  }
  else
  {
     Serial.println("no se ha podido enviar");
  }
  
}

I suggest that you try Robin2's simple stepper program to test the stepper, by itself, to make sure that the stepper works properly before trying to control it via radio.

Also, did you set the A4988 coil current. This Pololu page describes the process. This step is not optional.

groundFungus:
I suggest that you try Robin2's simple stepper program to test the stepper, by itself, to make sure that the stepper works properly before trying to control it via radio.

Also, did you set the A4988 coil current. This Pololu page describes the process. This step is not optional.

Thanks for answering.
Step one I did and it works well.

And in step two, I have adjusted the pololu to 25mA, only for the development stage

I think my problem lies in converting the increase and decrease of the analog input into pulses.
And I do not know if the solution you raise is correct.

Why is datos an array of floats when analogRead() and digitalRead() return an int ?

Thanks for answering

I was building the communication based on internet examples. You are right. it does not have to be float.

Now this part is all mine and is the one that is probably failing hahaha
PIN 5 is assigned to the Direction on a4988 and PIN 8 to the steps.

My idea is that when the value of A0 grows the engine will turn and when it decreases turn to the opposite direction.

and the problem is that I'm not sure that the solution I proposed worked

I take the data from a0 with a difference of 10ms and I compare them if it is higher or lower ... That would give me the DIR

Then rest the values ​​and I would give the steps of difference to correct

if (datos[0] > datos[1]) digitalWrite(5, HIGH);
      else digitalWrite (5,LOW);
      for(Z = 0; Z < ((datos[0] - datos[1])); Z++);
      {
    digitalWrite(8,HIGH);
    delayMicroseconds(500);
    digitalWrite(8,LOW);
    delayMicroseconds(500);
  }//comparacion para determinar la direccion
 
  for(Z = 1; Z < ((datos[1] - datos[0])); Z++);
  {
    digitalWrite(8,HIGH);
    delayMicroseconds(500);
    digitalWrite(8,LOW);
    delayMicroseconds(500);
  }

Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

...R