Stepper Code help

Hi,

I am using a L293d driver shield and trying to run a bipolar (4 wire stepper). Can someone confirm if this code will jog the tray about 4cm or so back and forth. I just wish to check if stepper is working fine or not.

At present it vibrates, moves in jerky fashion and there are more vibrations. I am not sure why. I am using a DVD drive motor. Picture/video is attached and the program is below.

Here is a small video: https://photos.app.goo.gl/HsdJANbuSQs1hJFr9

=====================

#include <AFMotor.h>
AF_Stepper motor(200, 1);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Stepper test!");
motor.setSpeed(50); // 10 rpm
motor.step(400, FORWARD, SINGLE);
motor.release();
delay(10000);
}
void loop() {
motor.step(200, FORWARD, SINGLE);
motor.step(200, BACKWARD, SINGLE);
motor.step(200, FORWARD, DOUBLE);
motor.step(200, BACKWARD, DOUBLE);
motor.step(200, FORWARD, INTERLEAVE);
motor.step(200, BACKWARD, INTERLEAVE);
motor.step(200, FORWARD, MICROSTEP);
motor.step(200, BACKWARD, MICROSTEP);
}

Thanks,
Pankaj

Post a link to the datasheet for your stepper motor. An L298 may not be suitable.

What stepper motor power supply (volts and amps) are you using?

Have you tried the AccelStepper library?

...R
Stepper Motor Basics
Simple Stepper Code

Thanks for the reply and links. Unfortunately I don't have data sheet for stepper. I am using a stepper salvaged from computer DVD drive. It's SM 308 from SAMSUNG. I have attached images of the same. Datasheet is not available online.

I am supplying 9V 1A to the shield. The Arduino is powered by USB. The shield is mounted on Arduino as the pins should align.

Yes, the accelstepper library is present in the Arduino code when I try to run Processing with G code. While testing, I don't use it.

I can also see in the serial monitor all the messages that I should see, but motor does not jog.

I am following the tutorial present here: DIY Arduino Uno CNC Plotter Machine Project with Code and Circuit Diagram

Thanks for the help Robin.

Another image of the drive which says 5V and 12V

Images from Replies #2 and #3 so we don't have to download them. See this Simple Image Guide

...R

vigisbig:
Yes, the accelstepper library is present in the Arduino code when I try to run Processing with G code. While testing, I don't use it.

Before trying anything more complicated see if you can get the simplest of the AccelStepper examples to work just to prove that you can make the motor move. Make sure to start with very slow steps.

I see that I mixed up the L298 with your L293D in my earlier Reply. I don't have any experience with an L293. AFAIK the L293D can only provide 600mA - but I have no idea how much current your motor needs. I doubt if the label in the picture refers to the motor.

Can you measure the motor coil resistance with your multimeter?

...R

Notes:

  1. The library AFMotor was deprecated almost ten years ago.

  2. The 'jerky' behavior and vibration is typically an indication of motor stall when trying to operate outside of the pullin/pullout torque curve band. If you're powering a 5V stepper directly from a GPIO pin without acceleration, you'd be lucky to get 8 rpm.

  3. The power rating you see on the CD/DVD is only applicable during a write (burning) operation. Most of the rest of the time consumption is quite low.

I know step motors are used in HDDs to position the R/W head, what do they do in a DVD? I thought everything in them was continuous motion

outsider:
I know step motors are used in HDDs to position the R/W head, what do they do in a DVD? I thought everything in them was continuous motion

The tray.

Hmmm. Would have thought a simple rack and pinion and DC gearmotor. Oh well.

Robin2:
Before trying anything more complicated see if you can get the simplest of the AccelStepper examples to work just to prove that you can make the motor move. Make sure to start with very slow steps.

I see that I mixed up the L298 with your L293D in my earlier Reply. I don't have any experience with an L293. AFAIK the L293D can only provide 600mA - but I have no idea how much current your motor needs. I doubt if the label in the picture refers to the motor.

Can you measure the motor coil resistance with your multimeter?

...R

Thanks for letting me know how images can be posted. :slight_smile: Yes, each coil resistance is 8.5 ohms. I am able to move the motor now with the code mentioned before. However, I am not sure if it is moving as the code says. :slight_smile: Infact, I am not sure what the code is saying. I need to learn more programming.

Am I correct in understanding that using an adapter that can supply higher current is not a problem. However, I should keep the voltage appropriate or even low?

Thanks for the help! Let me tinker more. I will report back. :slight_smile:

DKWatson:
Notes:

  1. The library AFMotor was deprecated almost ten years ago.

  2. The 'jerky' behavior and vibration is typically an indication of motor stall when trying to operate outside of the pullin/pullout torque curve band. If you're powering a 5V stepper directly from a GPIO pin without acceleration, you'd be lucky to get 8 rpm.

  3. The power rating you see on the CD/DVD is only applicable during a write (burning) operation. Most of the rest of the time consumption is quite low.

Thanks for the reply DKWatson!

  1. I am not sure what happens if the library is deprecated. Should we not use it? Can using it have severe consequences.

  2. The motor drivers are powered with the shield, which is getting power from 9V 1A adapter and not GPIO pins.

  3. Should I reduce the voltage applied to the shield?

Thanks
Pankaj

outsider:
Hmmm. Would have thought a simple rack and pinion and DC gearmotor. Oh well.

You are right. There's a separate DC motor for tray.

I am not sure what happens if the library is deprecated

That means it hasn't been kept up to date. You're working with code from a long time ago. You should find another library that is still supported.

The tray comment should have ended with a question mark.

Deprecated is typically synonymous with abandoned, as in there are better ones available.

  1. Should I reduce the voltage applied to the shield?

Not if the shield/motor can handle it. A speed limiting factor with stepper motors is the inductance of the coils. The 'harder' you can push power into them (more voltage) the greater the speed potential. A NEMA 23 with 12V tops out at about 300rpm, with 24V closer to 800.

Here's a datasheet for one motor/shaft combo which is used in applications from floppy disk drives to DVD drives.
The dvd drives in computers use devices very similar to this. (I have a few of them disassembled in my stash)
I haven't yet gotten round to using them for anything yet but would like to use them and the laser diodes for an etching machine someday.
I would be interested in how you go with getting your code running.