where can I find a simple sketch that runs stepper motors with accelstepper

1,015 views
Skip to first unread message

bob2...@gmail.com

unread,
Sep 10, 2015, 7:15:20 AM9/10/15
to accelstepper
I have a stepper motor connected to a l298n unit, see
I am using the library supplied with the arduino and the 'stepper_oneRevolution' sketch in the arduino library. The motor runs as advertised but when I connect a cog to it I get a rough, noisy motor.
I have found accelstepper but the only example sketches I can find for bipolar steppers like mine run the Adafruit mshield.
Is there a small sketch you know of that would help me wire up and run a 4 wire bipolar stepper with the l298 so I could utilise doubleStep. interleave and microstep to see if that improves the response of my motor?
Thanks., Bob.

gregor

unread,
Sep 10, 2015, 5:02:18 PM9/10/15
to accelstepper
Hi, 
try the AccelStepper Bounce and ConstantSpeed examples, just change the constructor to 
AccelStepper stepper(pin1, pin2, pin3, pin4);
where pin1...4 are the pins your L298n is connected to (if you followed the example on the website you posted, these will be D8, D9, D10 and D11).

The Adafruit Motor Shield(s) are different from your L298n module, Adafruit uses I²C to communicate with the Motor Shield, so you cannot just use their library. 
To get microstepping with the L298n module you will have to: 
1) connect the module to PWM pins of the Arduino
2) write your own functions for stepping the stepper using PWM. 
The Adafruit Motorshield implements microstepping by PWMing the driver, so you could look at their code to get an idea how to implement your stepping functions.

bob2...@gmail.com

unread,
Sep 10, 2015, 5:48:04 PM9/10/15
to accelstepper


Hi,
thanks for the reply.
I have been trying to get the accelstepper to work all day. I succeeded in doing what you suggest with 
AccelStepper stepper(pin1, pin2, pin3, pin4);
and various other things within that instruction. I have the stepper moving almost how I want but it is still a bit rough. I am trying to get it to do a sweep of about 120 degrees back and forth like a tracking radar but when I add the radar head to the cog it is quite noisy.
I think the instructions within the servo library would be a good place to look, they have single,double,interleave and microstep but the only sketches I can find for the servo library are for the mshield and don't show you how to drive the stepper direct.
Is this possible? is there an instruction in the servo library to allocate arduino pins to the coils of the stepper such as the one above?
I will keep looking.
thanks.

bob2...@gmail.com

unread,
Sep 10, 2015, 5:50:52 PM9/10/15
to accelstepper
sorry the library I am refering to that uses the servo.h is in examples from adafruit.

gregor

unread,
Sep 10, 2015, 5:53:47 PM9/10/15
to accelstepper
Hi, 
download the Adafruit Motor Shield V2 library (https://github.com/ladyada/Adafruit_Motor_Shield_V2_Library/archive/master.zip) if you have not already, open the Adafruit_MotorShield.cpp file and look in the section marked with
/****************************************** 
              STEPPERS
******************************************/

bob2...@gmail.com

unread,
Sep 10, 2015, 7:39:52 PM9/10/15
to accelstepper
Actually the bounce program you mention, with a couple of alterations to the variables, does quite a close job but I can  do it quieter with the mshield and interleaving the signal.

alex pj Morgan

unread,
Jul 5, 2017, 6:25:02 PM7/5/17
to accelstepper
would you mind helping me with some coding?

Mike McCauley

unread,
Jul 5, 2017, 11:00:41 PM7/5/17
to accels...@googlegroups.com
I am not able to help with coding.

Cheers.

On Wednesday, 5 July 2017 3:25:02 PM AEST alex pj Morgan wrote:
> would you mind helping me with some coding?
>
> On Thursday, September 10, 2015 at 6:39:52 PM UTC-5, bob2...@gmail.com
>
> wrote:
> > Actually the bounce program you mention, with a couple of alterations to
> > the variables, does quite a close job but I can do it quieter with the
> > mshield and interleaving the signal.
> >
> >
> > On Thursday, September 10, 2015 at 12:15:20 PM UTC+1, bob2...@gmail.com
> >
> > wrote:
> >> I have a stepper motor connected to a l298n unit, see
> >>
> >> http://tronixlabs.com/news/tutorial-l298n-dual-motor-controller-module-2a
> >> -and-arduino/ I am using the library supplied with the arduino and the
> >> 'stepper_oneRevolution' sketch in the arduino library. The motor runs as
> >> advertised but when I connect a cog to it I get a rough, noisy motor.
> >> I have found accelstepper but the only example sketches I can find for
> >> bipolar steppers like mine run the Adafruit mshield.
> >> Is there a small sketch you know of that would help me wire up and run a
> >> 4 wire bipolar stepper with the l298 so I could utilise doubleStep.
> >> interleave and microstep to see if that improves the response of my
> >> motor?
> >> Thanks., Bob.


--
Mike McCauley VK4AMM mi...@airspayce.com
Airspayce Pty Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia
http://www.airspayce.com
Phone +61 7 5598-7474

Brian Schmalz

unread,
Jul 7, 2017, 10:06:57 AM7/7/17
to accels...@googlegroups.com
I've put up some examples here http://www.schmalzhaus.com/EasyDriver/Examples/EasyDriverExamples.html that include AccelStepper.

Hopefully they'll be of some help to you.

*Brian


--
You received this message because you are subscribed to the Google Groups "accelstepper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

alex pj Morgan

unread,
Jul 7, 2017, 5:19:28 PM7/7/17
to accelstepper
A lot of my problem was just getting everything wired correctly.When you come into it totally
green it takes a while. im getting it though.
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper...@googlegroups.com.

Mike McCauley

unread,
Jul 7, 2017, 5:35:11 PM7/7/17
to accels...@googlegroups.com
Excellent work Brian.

Cheers.
> > email to accelstepper...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.


alex pj Morgan

unread,
Jul 7, 2017, 9:48:37 PM7/7/17
to accelstepper
im turning this wood disc 36" across 180 deg. slowly i have it may amp in dual step mode will that give me the most torque
so it does not fall out of step?



On Friday, July 7, 2017 at 9:06:57 AM UTC-5, EmbeddedMan wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper...@googlegroups.com.
coopwheel.JPG

Brian Schmalz

unread,
Jul 8, 2017, 8:31:08 AM7/8/17
to accels...@googlegroups.com
Alex,

Your question was somewhat unclear. Are you wondering what step mode produces the most torque? If so, the answer is that full step and half step both produce the maximum amount of torque of the various step modes.

*Brian

To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages