Go Down

Topic: New 28BYJ-48 library (Read 18556 times) previous topic - next topic

Thanks for posting this library.  It is working great for me at 5 volts.  I am now going to do some 12 volt testing and I am going to add the line for the a-d to detect torque issues and I will post back any questions or information I have.  Thanks for helping my out on Skype yesterday!

Jeff

sbright33

Please let me know if you'd like any improvements.  Or if there are bugs or problems.  Any part of the code confusing?  Not sure of the purpose?  I'll explain.

I've written a new library with servo easing for animation.  It runs simple scripts in the background allowing the processor to continue with other tasks.  It works with Servos or Steppers.  4+2=6 at once together.

I've expanded it to include bigger steppers without a 64:1 gearbox.  You think I just multiplied everything by 64?  Nope.

It allows you to output a variable voltage to hold in place or slowly step the motor using PWM.  I've got a 2V motor running on 12v when it needs to move fast than 1v to hold it keeping it cool, without a gearbox like before to keep it in position.  PWM increases the maximum speed and allows you to slowly step without jerking as much.  It also runs smoother at middle speeds.  None of this was needed for our tiny 28BYj's.  Got a big stepper?  This is for you.
If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

sbright33

You've pointed out 2 of the coolest features of my library!  I don't know why anyone would limit themselves to a 5v supply with a 5v 28BYj stepper.  How about 24v with the 12v motor?  All you need is those functions I wrote to prevent it from getting warm, while you gain the enhanced performance.  The only limitation is that you can't keep running at full speed for long.  The torque detection is cool.  I've been told it's not possible, but I use it every day!
If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

The library is really good. Why not turn it into a "real" library and put it on github? These little steppers seem to be very popular, I think a lot of people could benefit from it :)
www.bajdi.com

sbright33

Thanks!  Will do it when it's finished.  What are the advantages of Github?  Tracking changes?  Any other advantages?
If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

sbright33

Can anyone suggest any improvements?  Additional functionality?
If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Write some documentation on how to use it. For a newbie like me it was a bit difficult to understand the different things  :smiley-red:
www.bajdi.com

sbright33

So far all we have is at the top of this post listing the functions and a brief description.  Some more documentation would be nice eh?  The easiest way is to dive right in.  To get started you only need to define which pins you have connected the motor IC to.  For many of the functions I provided, no setup or initialization is needed.  Just call them with the parameters they require.  One line of new code.  Experiment.  Try it.  It won't cause any harm until your motor gets very hot over an extended period.  There are many examples commented out in loop() in stepper2.pde.  Just un-comment one line at a time.  Ask me specific questions here or PM.  I'm willing to help anyone getting started.

Start by calling this function in your loop():
void degrpmEZ (boolean bcw, long deg100, int rpm100)
Does it work for you?
If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

joogaa

The code works fine!
here are some questions and ideas:
how can we run other tasks while the motor runs? besides interrupts?
how do we run 2 motors independently?
how do run the motor and read the analog pin 0 (torque?) while it runs?
what does the pin 0 really read?
can we measure the current it consumes?

Suggestions:
1. I like your idea of keeping constant speed by adjusting the torque, if you could include it, it would be very useful
2. acceleration

sbright33

The library is setup to run other code in loop while spinning the motor non-blocking without using interrupts.  First initialize the move you want to make 1x.  This could be done in setup or an if statement in loop for example:

void degrpm_nowait (boolean bcw, long deg100, int rpm100)

Then call this function often:

int calloften_micro (boolean bcw)

At faster speeds you have to call it more often or it will get behind and run slower.  You can look at d in loop to see how much time you have in micros.  There are lines to uncomment if you want it to be more smooth consistent and partly blocking, some of the time.  The calloften functions use little integer math so they are fast.

There is another pair of functions for going slower and cooler using 12v:
void degrpmslowCool4_nowait (boolean bcw, long deg100, int rph100)
int calloften()

With these functions you have much more free time to process in loop, d milliseconds.  If you miss a step it's no big deal, the motor will catch up to keep the speed mostly constant.  It will move the correct distance no matter what you do wrong with timing.

To run 2 motors at the same time you have to copy and paste these few short functions to create a duplicate, changing the names of the global variables with a motor number at the end of each.  I have a sketch to test that myself.  It works with 3.

Global vars:
step2
d
m
ii
stepnum

You also have to duplicate st07() or ccw,off() with different pin numbers.  You can delete ar[] if you're not using it.

You do not have to read the torque pin yourself unless you want to.  My function ccwss() measures torque and halts program if spike to prevent damage.  Look in that function for example code to see how you could read it to print a warning instead of halting.  But you do have to wire it up.  Just hook any motor winding to analog pin 0.  If you're worried about damage use a resistor like 1k.  Pin 0 does not give you any absolute data, only relative.  After it has been running the code stores the normal value at the normal load.  Anything abnormal will cause the program to halt.  It detects increased torque as well as zero torque if a linkage were to break.  The current the motor consumes is a constant amperage with a given voltage supply.  You can measure this with an ammeter and store it as a constant as it will not change much, even when not moving.  Use the function off() to save power and keep the motor cool when not moving.

With my new PWM library you can vary the average voltage and therefore power.  It is not so useful for this hardware setup.

1. Did I say that?  I think you misunderstood.  I was proposing to lower the speed when the torque load causes the motor to stall at high speeds.  Keep lowering it until it does not stall anymore.  The way to detect this is with pin 0.  It is easy to implement.  To be clear you cannot adjust the torque of a stepper motor, or it will skip when there is not enough voltage/current.  You keep the speed constant with timing using rpm100 variable in my code.

2. 3 of my functions support simple acceleration of large objects like a spinning DSLR.
ramp, unramp, unramp1
You can change the code to fit the desired accel and mass of the object.  I use unramp so that when it comes to a stop it does not bounce back and forth.

Many of my functions include a quick accel from stop otherwise it would stall.  Even without any rotating mass you cannot immediately start at the maximum speed.

My new library for natural easing motion allows for complex speed changes (accel) from a script stored in an array.

More soon.
If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

sbright33

I've modified this library to work with L298N and a big motor see thread below:
http://arduino.cc/forum/index.php/topic,98992.0.html
If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

aelkhalil

Hi,

I'm using one of these motors in a project but all I require it to do is to continuously turn at a set RPM (I need it to turn a wheel at 1 rotation per hour).  However I need this motor to be non blocking/ stand alone, while the arduino is doing other tasks...
how do I use this code to do that?

sbright33

Pasted from above:

The library is setup to run other code in loop while spinning the motor non-blocking without using interrupts.  First initialize the move you want to make 1x.  This could be done in setup or an if statement in loop for example:

void degrpm_nowait (boolean bcw, long deg100, int rpm100)

Then call this function often:

int calloften_micro (boolean bcw)

At faster speeds you have to call it more often or it will get behind and run slower.  You can look at d in loop to see how much time you have in micros.  There are lines to uncomment if you want it to be more smooth consistent and partly blocking, some of the time.  The calloften functions use little integer math so they are fast.

There is another pair of functions for going slower and cooler using 12v:
void degrpmslowCool4_nowait (boolean bcw, long deg100, int rph100)
int calloften()

With these functions you have much more free time to process in loop, d milliseconds.  If you miss a step it's no big deal, the motor will catch up to keep the speed mostly constant.  It will move the correct distance no matter what you do wrong with timing.

All you have to do is choose the RPM and *100.
If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

knipex

Where do I find your library(downloadlink), it sounds awesome. i'd really like to give it a try.

sbright33

It's not in the format of an Arduino library yet.  It's a single file no .H including all the functions and loop().  In some ways this makes it easier to experiment and change my functions.  When we're done changing it I know how to make it into a real Library.

Here it is again, same as before:
If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Go Up