Go Down

Topic: CustomStepper - A library for stepper motors (Read 8666 times) previous topic - next topic

Jul 03, 2012, 01:32 am Last Edit: Jul 03, 2012, 04:11 am by darthwissen Reason: 1
Hey Folks,

I have had some trouble making my stepper motor work, that made me decide to make my own library for stepper motors, and here I come to share it with you guys.

The library is attached to this post, to install it, all you have to do is place it inside your libraries folder inside the Arduino IDE folder.

Take a look at the stepper example for explanation of how it works.

I've just added a new entry for it in the libraries page, check it here: http://arduino.cc/playground/Main/CustomStepper

Please post any bugs or suggestions you have.

Hope you find it useful.

sbright33

I read the first page of your link, looks great!
Why are you the only person with such strange gear ratios?
Everybody I have talked to uses 64:1 and it works as expected.
Can you include the link where you bought your stepper motors?
(so we can avoid them)

The problem with your library is the Floats.  That must be slower.
My code can be configured to use integers only...
If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Yer_dah

Looks great been looking for a stepper motor code like this for my project. Is it ok for me to use some of it?

I'm currently trying to motorise a chair for a simulator with a stepper motor and I am using a rotary encoder for feedback. What I am intending to is have the user control the rotation of a chair by using a USB joystick and the encoder will count the steps the motor takes and will prevent the chair from rotating if it reaches a limit in that direction. The user would either press the home button making the motor rotate back to a neutral position or twist the joystick in the opposite direction.

I have all the parts ready the only thing that is holding me back is my lack of knowledge in programming but I have been learning a lot from reading all the tutorials I can find and I have started playing around with codes to gain a greater understanding.


murf83

Is there a way of using the library with a stepper driver instead of inputting all of the pins individually?

I did some tests with the Custom Stepper Library and it worked.
At startup my motor turns 90 degrees to left and then 90 degrees to the right, which is correct according to the code.

What I want, is when I push button1 the motor turns 90 degrees to the left and when I press button2 , 90 degrees to the right.

This is the working code (example)
Code: [Select]

#include <CustomStepper.h>
CustomStepper stepper(8, 9, 10, 11);
boolean rotatedeg = false;

void setup()
{
  stepper.setRPM(12);
  stepper.setSPR(4075.7728395);
}

void loop()
{
  if (stepper.isDone() && rotatedeg == false)
  {
    stepper.setDirection(CW);
    stepper.rotateDegrees(360);
    rotatedeg = true;
  }
  stepper.run();
}


Here's my changed code which is not working (with the implementation of the 1 button)

Code: [Select]

#include <CustomStepper.h>
CustomStepper stepper(8, 9, 10, 11);
boolean rotate1 = false;
boolean rotatedeg = false;
boolean crotate = false;

const int buttonPin = 4;   
int buttonState = 0;       

void setup()
{
  pinMode(buttonPin, INPUT);
  stepper.setRPM(12);
  stepper.setSPR(4075.7728395);
}
 
void loop()
{
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH)
  {
    stepper.setDirection(CW);
    stepper.rotateDegrees(360);
    rotatedeg = true;     
    stepper.run();
  }
}


Is there somebody facing the same problem, or can somebody help me with this?
Thank you


MarkT


Why are you the only person with such strange gear ratios?
Everybody I have talked to uses 64:1 and it works as expected.


The 28BYJ-48 stepper motor has a normal gear train (gear trains are seldom powers of two, since the
people designing gear trains are not computer scientists!), and is only approxomately 64:1.
The gears in mine are 9:32, 11:22, 9:26, 10:31, giving a reduction ratio of ~63.684:1

Look at the picture halfway down this thread: http://forum.arduino.cc/index.php?topic=71964.15
which is the same as the ones I have from eBay.

Of course there may be other manufacturers with different gearings, the motor is made to control air-vanes
in car ventilation / air-conditioning systems.
[ I won't respond to messages, use the forum please ]

DozerXP

This looks great. I wrote a similar library for controlling these motors but the only copy is on a hard drive in a container on board the APL Yangshen at the moment...

I got these motors for controlling gauges for flight simulator cockpits. The input is an angle relative to the datum; the library tracks the motor's position relative to the datum and moves the motor CW or CCW towards the commanded position.

For this functionality a feedback sensor is needed (a hall switch and magnet does fine); on startup the motor rotates until the sensor is tripped at a known position relative to the datum (determined by experimentation).

Would it be OK if I recreate this functionality into the CustomStepper library? Progress is slow - nearly all my tools and components are also on the good ship Yangshen.

Hi,

I was facing the weird gear ratios of the 28BJY-48, and was looking for libraries that would work with it, when I found yours! Thanks a lot for your work!

I tried installing and trying out your custom stepper example. I'm using a 12v 28BJY-48, and have it hooked up using a L293D bridge, so I figured the example would work as-is, with the exception of the pins. The input pins I'm specifying are the ones from the arduino connected to input1, 2, 3, 4 of the L293D. 

I hear the stepper motor buzzing, but nothing happens! :-( Am I missing something? The only thing I can think of are the pin assignments - they work with the regular stepper library and the adafruit library, but with an annoying drift because of the gear ratio.

Thanks!
Sridhar

Dear darthwissen,

I just got my Arduino Uno and some stuff along. It made me feel more comfortable to use your library than using the official one.
To avoid duplicate variables,I preferred to modify your code and added "get" versions some of your "set" methods.
Do you plan to release newer versions? Might be adding such methods favorable?

Regards
Ozer




Robin2

I wonder if the odd gear ratios are designed to provide even wear on the gear teeth?

...R

dovber

Hi, i was experimenting with the customstepper library & 28BYJ motor, and trying to make the motor rotate one rev. in CW direction, then one rev. in CCW. the code looks somthing like below . the problem is the first "rotate" command is being ignored, the motor goes just 1 rev in CCW then stops.
will appreciate your help understanding why this happens and how make it to work.
thanks!


Quote

void loop()
{
 if (  stepper.isDone() &&rotate_end == false
 {
 stepper.setDirection(CW);
stepper.rotate(1);
delay(5000);   //probably not needed ??
stepper.setDirection(CCW);
stepper.rotate(1);
 rotate_end = true;
}
stepper.run();
}


Harrzack

Greetings!  Would like to use your library with a Big Easy Driver.  Will it work with that board? If so - in the constructor, what pins should be STEP, and DIRECTION?

=Alan R>
+++++++++++++++++++++++++++++++++++++
The completion date of a software project is 2 weeks from any given date.

I must say, thank you a lot, I had so much trouble controlling this stepper, I could not solve this without you, many thanks.

Harrzack

It appears this library is NOT for use with a driver board such as the Big Easy Driver.

I've gone over the code quite a bit and can not identify where the STEP and DIRECTION pins are set up. I'm getting the feeling Custom Stepper is for interfacing directly with driver transistors where each coil in the motor is handled separately by the software.  There is no info in the header file to explain this.

If anybody HAS used this with the Big Easy Driver (or equivalent) would love to hear from you and what mods you had to make.

=Alan R.
+++++++++++++++++++++++++++++++++++++
The completion date of a software project is 2 weeks from any given date.

eatabean

Is there any way to set an exact speed and make the motor run continously, with no stop? I am building a telescope drive and would like to have these options.

Go Up