Dear Stefan,
In attachment I am sending picture of our project, yours and mine. As you can see this is going to be drive for my astrophotography.
I did slight modification of your code regarding number of steps, 6 instead of 4 as you proposed.
Namely, motor speed is controlled using DRV8825 driver and Arduino Uno V3. Sensor signal to A2 is connected to 6 point rotary switch in order to have 6 different motor speeds.
Everything works perfect, motor soundless in all speeds without overheating. My only problem is how to get precise control of motor speed.
As you see, on attached picture, motor is driving gear box. The ratio of gear box is such that output shaft have speed of 1 (one) turn in 24 hours.
In our case with motor speed 71, output shaft of gearbox makes 1 turn in 23 hours and 52minutes. If I put motor speed 70, output shaft make 1 turn in 24 hours and 8 minutes.
Pay attention on code
case 900 ... 985:
mySpeedVar = 71;
break;
My question is how to adjust motor speed to run like clock 1 turn in 24 hours.
Below is complete code
Should you need any further detail feel free to let me know.
Dear Stefan, thank you very much for your help and hoping that you will find solution
Best regards. Kamilo
// MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START *
// Take it for granted at the moment scroll down to void setup
// start of macros dbg and dbgi
#define dbg(myFixedText, variableName) \
Serial.print( F(#myFixedText " " #variableName"=") ); \
Serial.println(variableName);
// usage: dbg("1:my fixed text",myVariable);
// myVariable can be any variable or expression that is defined in scope
#define dbgi(myFixedText, variableName,timeInterval) \
do { \
static unsigned long intervalStartTime; \
if ( millis() - intervalStartTime >= timeInterval ){ \
intervalStartTime = millis(); \
Serial.print( F(#myFixedText " " #variableName"=") ); \
Serial.println(variableName); \
} \
} while (false);
// usage: dbgi("2:my fixed text",myVariable,1000);
// myVariable can be any variable or expression that is defined in scope
// third parameter is the time in milliseconds that must pass by until the next time a
// Serial.print is executed
// end of macros dbg and dbgi
// MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END *
/* ====== minimumStepper =======================================
Bare minimum to get a stepper with step/dir driver turning
*/
#include <MobaTools.h>
// Stepper connections - Please adapt to your own needs.
const byte dirPin = 2;
const byte stepPin = 3;
const byte microSteps = 16;
const int stepsPerRev = 200 * microSteps; // Steps per revolution - may need to be adjusted
MoToStepper stepper1( stepsPerRev, STEPDIR ); // create a stepper instance
const int analogPin = A2; // pin that the sensor is attached to
int ADC_Value;
int oldADC_Value;
int mySpeedVar;
void setup() {
Serial.begin(115200);
Serial.println("Setup-Start");
stepper1.attach( stepPin, dirPin );
stepper1.setSpeed( 200 ); // 20 rev/min (if stepsPerRev is set correctly)
stepper1.setRampLen( stepsPerRev / (2 * microSteps) ); // Ramp length is 1/2 revolution
stepper1.rotate(1); // start turning, 1=vorward, -1=backwards
}
void loop() {
ADC_Value = analogRead(A2);
dbgi("1:", ADC_Value, 1025);
if (ADC_Value != oldADC_Value) {//check if ADC_Value value has changed
dbgi("2:", ADC_Value, 1025);
dbgi("2:", oldADC_Value, 1025);
switch (ADC_Value) {
case 900 ... 985:
mySpeedVar = 71;
break;
case 700 ... 800:
mySpeedVar = 60;
break;
case 650 ... 695:
mySpeedVar = 50;
break;
case 490 ... 500:
mySpeedVar = 25;
break;
case 328 ... 450:
mySpeedVar = 1025;
break;
case 10 ... 200:
mySpeedVar = 500;
break;
}
dbgi("3:",mySpeedVar ,1025);
stepper1.setSpeed( mySpeedVar );
oldADC_Value = ADC_Value; // update oldADC_Value for next loop
}
}.