Hi everyone, I'm creating an app to vary the speed of a stepper motor using a cnc shield with arduino but the problem is that with lower values than 60 rpm the motor does not run, also I would like to ask if is it possible to have more precise values with the slider for example it goes to 98 rpm to 102 and I need 100.
#include <SoftwareSerial.h>
#include <AccelStepper.h>
// Definimos los pines utilizados
const int pinStep = 4;
const int pinDir = 7;
const int pinEnable = 8;
// Creamos un objeto de tipo AccelStepper
AccelStepper stepper = AccelStepper(1, pinStep, pinDir);
SoftwareSerial BTSerial(10, 11); // Creamos un objeto SoftwareSerial para la comunicación Bluetooth
void setup() {
// Configuramos los pines
pinMode(pinEnable, OUTPUT);
digitalWrite(pinEnable, LOW); // Habilitamos el driver
// Configuramos el objeto AccelStepper
stepper.setMaxSpeed(2000); // Velocidad máxima en RPM
BTSerial.begin(38400); // Iniciamos la comunicación Bluetooth
void loop() {
// Definimos la velocidad en RPM y la dirección
while (BTSerial.available() > 0) {
int rpm = BTSerial.parseInt(); // Leemos el valor de RPM enviado desde la app
const int dir = -1; // 1 para CW, -1 para CCW
// Definimos la velocidad en RPM y la dirección
if (BTSerial.read() == ',') { // Si se recibió información por Bluetooth
rpm = constrain(rpm, 0, 600);
// Configuramos la velocidad y la dirección del motor
stepper.setSpeed((dir * rpm / 60) * 200); // Convertimos RPM a pasos por segundo
}
}
}
the range of the slider is 0 to 600
I appreciate any idea