I see this in most of the stepper code that I have looked at and am not sure what exactly it does. What is the reason for dividing by 100? does this make the steps seem smaller so there is more accuracy? Please help and let me know if there are any limitations to this. I am trying to just run a motor and change the speed and direction and have no cares of accuracy of stopping points or starting points just want it to run in both directions and be able to make it go faster and slower.
This is the code I am trying but wondering if I can eliminate the /100 portion of the myStepper.step(stepsPerRevolution / 100); command
#include <Stepper.h>
int stepsPerRevolution = 48;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int stepCount = 0; // number of steps the motor has taken
String command;
void setup() {
Serial.begin(115200);
}
void loop()
{
// read the sensor value:
int motorSpeed = (motorSpeed);
// set the motor speed:
if (motorSpeed >= 0)
{
myStepper.setSpeed(motorSpeed);
// step 1/48 of a revolution:
myStepper.step(stepsPerRevolution / 100);
if(Serial.available())
{
char c = Serial.read();
if(c == '\n')
{
parseCommand(command);
command = "";
}
else
{
command += c;
}
}
}
}
void parseCommand(String com)
{
String part1;
String part2;
Whoever wrote that is not much good at math. A typical stepper motor is 200 steps/rev, so stepping stepsPerRevolution /100 will move 2 steps, or 1/100th of a rev, not 1/48th of a rev. You can replace that with whatever number you want.
The motor I am using is a 48 steps/rev motor so the way I am reading it is that I want that ratio to equal at least 1 such as 48/48 so that it will move one revolution I am really confused by this. I am trying to get the motor to run at the motor speed that is set do I want to make that 100 larger or smaller?
The value in the parentheses is the number of steps to take. If you want the motor, that takes 48 steps to complete a revolution, to step enough to complete one revolution, the value needs to be 48. If that is the value in stepsPerRevolution, the denominator in that call needs to be 1 (or removed)
This code declares motorSpeed and stepsPerRevolution as local variables that exist only inside the function, so it won't pass the values to your code in loop().
Try putting this before setup() to declare them as global variables ...
Do you happen to know what AI2 sends as the delimiter when it transmits the data as a list to bluetooth? I am seeing some things that say it is a "space" and other say it is a "comma" but there is no way to set it when sending data only when receiving.
Kind Regards
I made the changes you recommended and will be testing this evening.