Pages: [1]   Go Down
Author Topic: code with zoetrope with stepper  (Read 952 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 1
Posts: 142
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello,

i posted about this earlier and have gotten a little further along.

basically, i have a 3D print of 15 different guys in different positions walking. I am spinning them around in a 2way mirror box with an array of LEDs flashing. I am using a bi polar stepper motor with this configuration: http://arduino.cc/en/uploads/Tutorial/bipolar_schem.jpeg but I'm using the accelStepper library instead of the arduino stepper library.
this is my first time using a stepper so i'm very much in the dark with how to control it.

the problem is, is that i can't seem to time the motor RPM and the LED flashing perfect enough to get anything other than a blur.

what would be ideal is if I can know the exact RPM of the stepper. I have the speed set to 600. Can I assume this is 60 RPM? how would I know?
why do i need to set a max speed with the motor for it to work?

the reason i want to know the exact RPM is because, since i have 15 different positions to animate, i assume if i flash the LEDs 15 times per rotation i will get a zoetrope effect.

any ideas? thanks so much for any guidance!


Code:
#include <AccelStepper.h>

AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5, i changed to 8,9,10,11

const int ledPin =  13;     


int ledState = LOW;           
long previousMillis = 0;       

long interval = 25;           


void setup()

    pinMode(ledPin, OUTPUT);     

   stepper.setMaxSpeed(1000);  //why do i need to set this?
   stepper.setSpeed(600);  //is this at 60RPM?
}

void loop()

//run stepper
   stepper.runSpeed();

//blink LEDs
  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;   
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;
    digitalWrite(ledPin, ledState);
  }
}

Logged

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 51
Posts: 2276
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe you should try thinking in terms of the number of steps per rotation and then flash the leds when thinks are in the right position.

But in a case like this I'd look at how steppers are really controlled and write my own control code. So that you can insert the code to flash the leds in to the stepper control code.

Mark
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 142
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks so much for the help.

where is a good place to start where i could learn how to write my own stepper code? everything out there that i've found i don't understand because i just simply want to control RPM. would an easy driver from sparkfun help? or you think it's better to use this h-bridge?

how do i find out how many steps per rotation i have?

i can't find the datasheet to my stepper anywhere. it's a moons stepping motor 17HD4063-01N, bipolar, the regular 40mmx40mm ones if that helps at all...4 wires.

thank for any more feedback!
Logged

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 51
Posts: 2276
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
would an easy driver from sparkfun help? or you think it's better to use this h-bridge?

I don't think this is a hardware issue so stick with what you have.

Use Google your looking for the basics of driving the motor without using a lib. But the code from one of the libs can of course be modified!

Mark 
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Looks like it could be a 1.8 degree stepper, so 200 pulses per rotation. (page 29 of their catalogue for 17HD albeit not your specific code). A 3.6 degree stepper would only require 100 pulses per revolution ie twice as fast.
The stepper motor speed is controlled by the rate of pulses as applied to the stator.

You could even try using a variable controlled via a pot on an analogue input and use this to control the speed rather than having a set 600.
Logged

London
Offline Offline
Edison Member
*
Karma: 46
Posts: 1416
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have the speed set to 600. Can I assume this is 60 RPM? how would I know?

I suspect that speed() is the number of steps per second, so 600 would give you either 180 or 360 RPM, depending on your motor type.

To check, try setting the speed to a low figure (say 10) and timing one complete revolution.
10 steps/second on a 1.8 degree stepper will take 20 seconds for a complete rev. On a 3.6 degree stepper it will take 10 seconds.

Once you know how many steps are needed for a complete revolution, divide that figure by 15 to tell you how many steps are needed between each flash of your LEDs. If, as I suspect, that figure isn't a whole number (100/15 = 6.666) you'll have to juggle the number of steps between each flash to average out the decimal part (for 6.666 use 7 steps, 6 steps and 7 steps). Once you can do that, the RPM can be set to whatever speed you like without affecting the timing.
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 142
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks so much! this is all super helpful! so yes, it was 20 seconds to rotate at 10 steps per second. so it's a 1.8 degree at 200 pulses a second.

i have other questions now
when i set the stepper.setSpeed(); to too low of a number (below 500 or so), the motor is very jumpy and sort of makes noises and has almost no torque. why is this? i'm just using an h-bridge, would an EasyDriver or something like that help this? do motor drivers help because they do microstepping, thus making the motor rotate smoother?

if i make the flash into the steps does this mean i have to do this in the stepper library? or just write my own code? is there anywhere you recommend where i could learn to write code for a stepper? everything i've found through google is so so confusing and more for robots/printers and not just setting smooth rotations.

thanks again!
Logged

Offline Offline
Full Member
***
Karma: 5
Posts: 181
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This should be a very easy modification to using the AccelStepper Library.  You can see what the library is doing here
https://github.com/adafruit/AccelStepper/blob/master/AccelStepper.cpp
So taking a look at the runspeed method, the code there is very similar to what you are doing in your loop function.  So what you can do is take that bit of code and add it to what you are doing
Code:
#include <AccelStepper.h>

AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5, i changed to 8,9,10,11

const int ledPin =  13;     


int ledState = LOW;           
long previousLedMillis = 0;       
long previousStepperMillis = 0;       

long ledInterval = 25;
long stepperInterval = 5; // I think this is 60 rpm

long currentPos = 0;

void setup()

   pinMode(ledPin, OUTPUT);
   stepper.setMaxSpeed(1000);  //why do i need to set this?
   stepper.setSpeed(600);  //is this at 60RPM?  No it's 600 RPM
}

void loop()
{
  // You could just step 5 times for every led interval, this is more flexible however
  unsigned long currentMillis = millis();
  if(currentMillis - previousLedMillis > ledInterval) {
    previousLedMillis = currentMillis;   
    if (ledState == LOW){
      ledState = HIGH;
    }else{
      ledState = LOW;
}
    digitalWrite(ledPin, ledState);
  }
  if(currentMillis - previousStepperMillis > stepperInterval){
previousStepperMillis = currentMillis;
currentPos += 1; //assumes clockwise stepping
step(currentPos & 0x3);
  }
}
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 142
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks so much for the code.
unfortunately my motor was all over the place. it didn't do a full rotation, it was super jerkey and kind of went back and forth. would a driver other than just an h-bridge chip help? or any other ideas?

after running the code for a little bit something popped!! what could it have been? powering this with a 12V 5amp supply...i think it was the h-bridge chip because when i give power to the stepper it budges and has torque...man...

here is the exact code i had:
Code:
#include <Stepper.h>
#define STEPS 200

Stepper stepper(STEPS, 8, 9, 10, 11);

const int ledPin =  13;      

int ledState = LOW;            
long previousLedMillis = 0;        
long previousStepperMillis = 0;        

long ledInterval = 25;
long stepperInterval = 5; // I think this is 60 rpm

long currentPos = 0;

void setup()
{  
   pinMode(ledPin, OUTPUT);
}

void loop()
{
  // You could just step 5 times for every led interval, this is more flexible however
  unsigned long currentMillis = millis();
  if(currentMillis - previousLedMillis > ledInterval) {
    previousLedMillis = currentMillis;  
    if (ledState == LOW){
      ledState = HIGH;
    }else{
      ledState = LOW;
}
    digitalWrite(ledPin, ledState);
  }
  if(currentMillis - previousStepperMillis > stepperInterval){
previousStepperMillis = currentMillis;
currentPos += 1; //assumes clockwise stepping
stepper.step(currentPos & 0x3);
  }
}
« Last Edit: June 05, 2013, 11:06:25 am by treebykooba » Logged

Offline Offline
Full Member
***
Karma: 5
Posts: 181
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just try it with only the stepper motor, and take out the bitwise operator, maybe up the interval a bit.  Also you switched stepper libraries, not sure how that would effect things.
Code:
#include <Stepper.h>
#define STEPS 200

Stepper stepper(STEPS, 8, 9, 10, 11);

const int ledPin =  13;     

int ledState = LOW;           
long previousLedMillis = 0;       
long previousStepperMillis = 0;       

long ledInterval = 25;
long stepperInterval = 500;

int currentPos = 0;

void setup()

   pinMode(ledPin, OUTPUT);
}

void loop()
{
  unsigned long currentMillis = millis();
  if(currentMillis - previousStepperMillis > stepperInterval){
previousStepperMillis = currentMillis;
currentPos += 1; //assumes clockwise stepping
stepper.step(currentPos);
  }
}
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 142
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks so much. but why would the above code have fried my h-bridge chip? now i have to wait to get new parts in the mail to test out the rest of the code.
here was how i had it wired up: http://arduino.cc/en/uploads/Tutorial/bipolar_schem.jpeg
i'll report back when the stuff comes in

thanks
Logged

Offline Offline
Full Member
***
Karma: 5
Posts: 181
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can also change the step line to just stepper.step(1); and remove all the currentPos code.
Logged

Offline Offline
Full Member
***
Karma: 5
Posts: 181
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would imagine that the h-bridge chip that you have avoids issues with short circuits, but the classic h-bridge can run into trouble when improper signals are sent to it.
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 142
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

oh wow i found this: https://github.com/xtremd/Zoetrope

for anyone curious. i'm waiting for my easyDriver to come in the mail then i'll try it out.
thanks so much for all the comments.
Logged

Pages: [1]   Go Up
Jump to: