Hi Franz-Peter and everyone
The code below. The ratio needs to be check out I am sure it is incorrect. That will help. Other things like does speedDir need to be included etc. The loop etc works ok. the settings need a change or two! Once we know correct gear ratio and how to show it for speed steps etc I can experiment with output speed. Should I e using bipolar or monopolar?
Thanks for your patience.
Charles
#include <MobaTools.h>
const int stepRev = 2048; // ??
//const int stepRev = 4096; //Or // steps per revolution 28byj48 no box= 32 (x64 ratio) with box =2048 FULLSTEP (HALFSTEP=4096)
//const int stepRev = 770 //Or // steps per revolution 28byj-48 with additional gears. After 28byj-48 motor gearbox, #1 belt drive = 40t,
// #2 belt drive = 20t, #3 crown = 20t, #4 idler = 18t, #5 = 15t. Total is: 2 x 1 x 1 x 1.1 1.2 = 2.64.?
// Therefore orig bearbox is 64th reduction divided?? 2.64 overdrive = ??
// 28byj-48 motor only = 32 rpm x 24 = 768 as used.FULLSTEP (HALFSTEP=)1536
const byte stepperPins[] = {2,3,4,5};
// create stepper object
//MoToStepper myStepper( stepRev, HALFSTEP );or
MoToStepper myStepper( stepRev, FULLSTEP );
// create button objects
const byte buttonPins[] = { A0, A1, A2, A3, A4 }; // adjust button pins to your needs = 5
//const long stepperPositions[] = {0, 4096, 8192, 12288, 16384}; //Or // must be same number of elements as buttonPins = 5
//const long stepperPositions[] = {0, 1000, 2000, 3000, 4000}; // Or
//const long stepperPositions[] = {0, 700, 1400, 2100, 2800}; //Or
//const long stepperPositions[] = {0, 250, 500, 750, 1000 }; //Or
//const long stepperPositions[] = {0, 3000, 6000, 9000, 10000 };//Or
const long stepperPositions[] = {0, 1500, 3000, 4500, 6000};
const byte buttonCnt = sizeof(buttonPins);
MoToButtons myButtons( buttonPins, buttonCnt, 20, 500 );
void setup()
{
Serial.begin(115200);
// Serial.println(file name is: ("TransferFP1, Arduino 1 8 18, last amended 17 March 2024");
Serial.println("Starting...");
myStepper.attach( stepperPins[0],stepperPins[1],stepperPins[2],stepperPins[3] );
myStepper.setSpeedSteps( 2000 ); //Need advice on what this number sshould be.
myStepper.setRampLen( 50 ); // steps to achieve set speed
}
void loop()
{
static int lastPos = 0; // must be static to not get initialized to 0 with every loop
myButtons.processButtons(); // Check buttonstates
for ( byte pos = 0; pos < buttonCnt; pos++ )
{
if ( myButtons.pressed(pos) )
{
Serial.print("Move from "); Serial.print(lastPos); Serial.print(" to "); Serial.println(pos); myStepper.write( stepperPositions[pos] );
lastPos = pos;
myStepper.writeSteps( stepperPositions[pos] );
}
}
}