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");
}
}