// Include the AccelStepper Library #include <AccelStepper.h>
// Define step constant #define FULLSTEP 4
// Creates an instance
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
AccelStepper myStepper(FULLSTEP, 4, 6, 5, 7);
void setup() {
// set the maximum speed, acceleration factor,
// initial speed and the target position
myStepper.setMaxSpeed(1000.0);
myStepper.setAcceleration(100.0);
myStepper.setSpeed(100.0);
myStepper.moveTo(2038);// aqui serve para setar o numero de voltas que o motor vai dar, então no caso é melhor que marcar o tempo em minutos 1 volta=2038
}
void loop() {
// Move the motor one step
myStepper.run();
}
so I have this code here, for now it runs well and does what it proposes is to take a walk, the problem is that I wanted to take a larger number of turns, but if I edit the number of steps for example and multiply by 4 (2038 * 94 = 8152) he doesn't start 4 laps, he reaches the limit (2038 or in this case, one lap) and hangs up, my question is, what should I put in the code for him to give a certain number of laps?
So when you use "myStepper.moveTo(2038);" it goes one 'lap' and when you change it to "myStepper.moveTo(8152);" it does exactly the same thing? One 'lap'?
it is strange but ... yes, a turn means that it goes from 0 to 2038, even though I put a value greater than 2038 there, for some reason I have no idea what it is
I added some lines to print out the current position. It counts up to 8152. Are you sure the code you modified was uploaded successfully? Try this version on your hardware. Does the motor stop before the position reaches 8152?
Are you sure your hardware is capable of 1000 steps per second? Try a lower number like 300 to see if the motor reaches the desired position.
// Include the AccelStepper Library
#include <AccelStepper.h>
// Creates an instance
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
AccelStepper myStepper(AccelStepper::FULL4WIRE, 4, 6, 5, 7);
void setup()
{
Serial.begin(115200);
// set the maximum speed, acceleration factor,
// initial speed and the target position
myStepper.setMaxSpeed(1000.0);
myStepper.setAcceleration(100.0);
myStepper.setSpeed(100.0);
myStepper.moveTo(4 * 2038ul);
// aqui serve para setar o numero de voltas que o motor
// vai dar, então no caso é melhor que marcar o tempo
// em minutos 1 volta=2038
}
void loop()
{
// Move the motor one step each time through loop()
myStepper.run();
Serial.println(myStepper.currentPosition());
}
yes, it was exactly that, a lot but your code solved my case, I want to thank you for that, before I have to create another topic on the subject, I would just like to see if someone here does not have the solution for my next problem
since my intention was to determine a number of laps, I was wondering how I can replace the value that will be multiplied by '2038' with the value that will come out of a slider in the blynk app
I don't know if by chance you would know how to answer that too
and not to say that I didn't try it myself, in the research I did I would have to add something like
''' BLYNK_WRITE (V1)
{
int pinValue = param.asInt (); '''
only if I try to put
"pinvalue" or "param.asInt (); '" before *, it doesn't work the way I want
Note: Some of these geared steppers have a complex gear-train with a factor of 63.68395 (2037.8864 steps per revolution) instead of the commonly-reported 64. If that is the case, 2048 will be 0.5% fast and 2038 will be only 0.0056% fast.
One way to find out, put a pointer (just a piece of tape) on the shaft, draw a pencil line on the housing for a reference mark, load up a simple, repeating one rotation program and let it run for a while.
/*
Stepper Motor Control - one revolution
This program drives a unipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino.
*/
#include <Stepper.h>
const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
//Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
//different pin sequence for 28BYJ-48 and ULN2003 module
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
void setup() {
// set the speed at 8 rpm:
myStepper.setSpeed(8);
// initialize the serial port:
//Serial.begin(9600);
}
void loop() {
// step one revolution in one direction:
myStepper.step(stepsPerRevolution);
delay(1000);
}
If it's 2038, it will gradually move away from the starting point, might take a few dozen revs to see.