Driez:
Cheers guys thanks a lot! I am almost there. Keep in mind it’s my first time programming anything so I really do appreciate all the help! I’ve been looking for this for more than 2 hours on google and forums.
Right now I have a setable RPM value with my potentiometer. I can continue to use this RPM to calculate the required corresponding delayMicroseconds. However I suspect there might be an easier way to do this?
Furthermore do I need to use an acceleration code or are the RPM’s low enough that this isn’t necessary (max 100RPM)?
This is my current code to drive the 17HS24-2104S nema 17 motor using the TB6600 stepper driver at 2A and 200 pulses per revolution.
I take the potentiometers input RPM and divide by 60 to convert it to RPS. Then I multiply this number by 10^6 (1000000) to convert seconds to microseconds. I divide by 200 to get the delay in microseconds per pulse and divide this by 2 to get the delay in microseconds per phase.
void loop(){
Pot = analogRead(A1);
//Serial.print(Pot);
RPM =(Pot100L)/1023;
Serial.print(RPM);
lcd.setCursor(0,0); //Defining position to write from first row, first column.
lcd.print (“RPM”); // Showing the letters RPM
lcd.setCursor(0,1); //Defining position to write from second row, first column.
lcd.print (RPM); // Showing current RPM value
//Enables the motor direction to move in a certain direction.
digitalWrite(dirPin,LOW);
//Makes 200 Pulses for making one full cycle (1.8 degree stepper).
for(int x = 0; x < 200; x++){
digitalWrite(stepPin,HIGH);
delayMicroseconds=((((RPM1000000)/60)/200)/2);
//delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds=((((RPM*1000000)/60)/200)/2);
//delayMicroseconds(500);
If you are new to ‘C’ then check this out: https://www.tinkercad.com/
It is free to use.
You can do 3D design but also circuits.
The circuit part of it is an excellent electronics simulator complete with and Arduino Uno, servos, everything.
It is just like using real electronic components.
To program the virtual Arduino you can either use the Scratch like interface or code it with C as you do with Arduino IDE.
But the brilliant thing about it is that you can view both Scratch blocks and C code at the same time.
Put the blocks together and view the C code it generates.
A rather convenient way to quickly learn C code if you are not entirely familiar with it.