Go Down

Topic: Complete beginner trying to make my stepper motor work......power troubles  (Read 1 time) previous topic - next topic

bellows

So i got it working...im little worried it wont be able to lift the bellows i have made... Im thinking of using the stepper motor to turn a small cog that will then turn a bigger wheel that would then lift the bellows...it will liftslower but hopefully wont put as much strain on the motor .

The simple code Robin has written is great for me.. I understand how to make it spin faster and slower with more or less steps . I was wondering if there is a way to make it just keep going back and forward on a loop till it is disconnected from power

I basically want to plug it in and leave it going up and down till i unplug it again . Is this possible ?


Robin2

if there is a way to make it just keep going back and forward on a loop till it is disconnected from power

I basically want to plug it in and leave it going up and down till i unplug it again . Is this possible ?
Yes that is doable. Just get the code to keep issuing step pulses at the required interval.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

bellows

Yes that is doable. Just get the code to keep issuing step pulses at the required interval.

...R
Ok cool ... Just gotta figure out how to do that . Is there a good thing to read /watch you would recommend that would point me in the right direction to sorting this code out? Or a good source of pre made code i could copy paste and change stuff from ?

The code side is also brand new to me and obviously looks completely daunting but i know with these things once you get a basic knowledge will ease up .

Robin2

Ok cool ... Just gotta figure out how to do that . Is there a good thing to read /watch you would recommend that would point me in the right direction to sorting this code out?
Just take out of my example the code that makes it stop after N steps ?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

bellows

Just take out of my example the code that makes it stop after N steps ?

...R
Cool.. just gotta work out what that bit of code is haha

bellows

So i still cant work out what that bit of code is haha.

I have deleted stuff and tried it but it seems im not deleting the right stuff.

Any hints?

Thank you!

Robin2

Two or three hours spent thinking and reading documentation solves most programming problems.

bellows

Hi Robin

So im just using this at the moment .

Code: [Select]
// testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// this version uses delay() to manage timing

byte directionPin = 9;
byte stepPin = 8;
int numberOfSteps = 750;
byte ledPin = 13;
int pulseWidthMicros = 50;  // microseconds
int millisbetweenSteps = 15; // milliseconds - or try 1000 for slower steps


void setup() {

  Serial.begin(9600);
  Serial.println("Starting StepperTest");
  digitalWrite(ledPin, LOW);
 
  delay(2000);

  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
 
 
  digitalWrite(directionPin, HIGH);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros); // this line is probably unnecessary
    digitalWrite(stepPin, LOW);
   
    delay(millisbetweenSteps);
   
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
 
  delay(3000);
 

  digitalWrite(directionPin, LOW);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    // delayMicroseconds(pulseWidthMicros); // probably not needed
    digitalWrite(stepPin, LOW);
   
    delay(millisbetweenSteps);
   
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
}

void loop() {
}



What works fine but yeah im just looking for it to loop that sequence from power on to power off . Would you be able to point out where i need to delete some code ?

Thanks so much

Robin2

Try this version. Look carefully at the very minimal changes I have made
Code: [Select]
// testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// this version uses delay() to manage timing

byte directionPin = 9;
byte stepPin = 8;
int numberOfSteps = 750;
byte ledPin = 13;
int pulseWidthMicros = 50;  // microseconds
int millisbetweenSteps = 15; // milliseconds - or try 1000 for slower steps


void setup() {

  Serial.begin(9600);
  Serial.println("Starting StepperTest");
  digitalWrite(ledPin, LOW);
 
  delay(2000);

  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
 
}  // new
 
void loop() {  // moved

  digitalWrite(directionPin, HIGH);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros); // this line is probably unnecessary
    digitalWrite(stepPin, LOW);
   
    delay(millisbetweenSteps);
   
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
 
  delay(3000);
 

  digitalWrite(directionPin, LOW);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    // delayMicroseconds(pulseWidthMicros); // probably not needed
    digitalWrite(stepPin, LOW);
   
    delay(millisbetweenSteps);
   
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
}


// }   // not needed


Of course I may have misunderstood what you want

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

bellows

Robin thank you ! That is it . A very subtle change indeed but i never would of worked that out . So by putting the info after 'void loop' will loop everything and putting it at the end will only run the action once. Is this correct ? Im just trying to work out how the code after void loop is affecting the action of the motor ? i understand by changing the variables at the start i can change the number of steps and how quickly it steps but say for example i wanted there to be a delay at the start of the process what would i add ? i tried to just copy and pasting the delay function but it didnt seem to work... as i still dont really no the format of how this coding works haha

Code: [Select]
// testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// this version uses delay() to manage timing

byte directionPin = 9;
byte stepPin = 8;
int numberOfSteps = 300;
byte ledPin = 13;
int pulseWidthMicros = 50;  // microseconds
int millisbetweenSteps = 15; // milliseconds - or try 1000 for slower steps


void setup() {

  Serial.begin(9600);
  Serial.println("Starting StepperTest");
  digitalWrite(ledPin, LOW);
 
  delay(2000);

  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
 
}  // new
 
void loop() {  // moved

  digitalWrite(directionPin, HIGH);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros); // this line is probably unnecessary
    digitalWrite(stepPin, LOW);
   
    delay(millisbetweenSteps);
   
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
 
  delay(3000);
 

  digitalWrite(directionPin, LOW);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    // delayMicroseconds(pulseWidthMicros); // probably not needed
    digitalWrite(stepPin, LOW);
   
    delay(millisbetweenSteps);
   
    digitalWrite(ledPin, !digitalRead(ledPin));
  }

}
 
  delay(3000);
 

  digitalWrite(directionPin, LOW);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    // delayMicroseconds(pulseWidthMicros); // probably not needed
    digitalWrite(stepPin, LOW);
   
    delay(millisbetweenSteps);
   
    digitalWrite(ledPin, !digitalRead(ledPin));
  }


// }   // not needed



Im so close now . Basically all im trying to do is make the sequence loop just as the code you sent dose but have a delay at the beginning the same as the delay between the forward and backwards rotation ... is this possible ?

Your hero robin .


Robin2

So by putting the info after 'void loop' will loop everything and putting it at the end will only run the action once. Is this correct ?
If you open the Arduino IDE it starts with a new empty project that explains that better than I can. The code looks like this
Code: [Select]
void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}


...R
Two or three hours spent thinking and reading documentation solves most programming problems.

bellows

Well Robin my man i have figured the code out ! Thank you ! and everyone else that has helped me out so far !Tomorrow i go to the gallery to install. I will post a video on here if any of you wanna see once i have it up and running ... its quite a wild show and if anyone is around Oakville Ontario next Sunday swing by for the opening :-)


there will probably be more questions after tomorrow so im sure this isnt my final goodbye .... i bet you cant wait Robin .

peace

Go Up