Shop OBEX P1 Docs P2 Docs Learn Events
Stepper motor controlers - Page 2 — Parallax Forums

Stepper motor controlers

2»

Comments

  • whiteoxewhiteoxe Posts: 794
    edited 2014-06-30 22:03
    i was looking for ways to operate relay boards and by accident i watched a youtube video of a bloke showing everystep of wiring up that same L298n motor contrller. it had a rather ambiguous title and i would never have found it. it was excellent except thanks to yor post i didnt need to see it but i did anyway. he turns out to be the author of that diagram you were not at all that fond of( i had been using google images to find a drawing i might understand as id given up oon youtube.

    He does connect the 5volt screw via the arduino without saying why , a little bit sus as he explained every other connection as he went along. it was 18 min, i stopped after 14 min and no point posting it here as you wont learn anything frm it. Oh hell., here it is u dont have to click on it ;)

    https://www.youtube.com/watch?v=b4uhh_j8uR0

    I tried numerous types of search phrases short and long without coming up with a clean and simple video like this. Considering the number of these units being sold(iguess) it started to get under my skin.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-07-01 10:54
    whiteoxe wrote: »

    Either I'm wrong about how the board works of TheRaspberryPieGuy is wrong. He's got the enable pins all confused.

    Ug! This guy showed a third of a million people the wrong way to wire these boards!

    I'm going to dig an unused board just to double check I'm correct and then leave a comment on the YouTube video.

    Darn.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-07-01 11:19
    I found a four month old post pointing out the error (which could easily destroy a RPi). It's very disturbing this guy has made such a serious error without correcting it.
  • ercoerco Posts: 20,256
    edited 2014-07-01 12:58
    One less RasPi in circulation. Perhaps you can sway him to the Propeller with your technical prowess, young Duane?
  • whiteoxewhiteoxe Posts: 794
    edited 2014-07-01 14:23
    you could maybe upload your own video, and give it a title and tags that make it easier to actually find , or post a video response. like a ten min vid,, 18 min almost put me off clicking on it !

    edit; didn't he say that the most the Pi could supply on its own was 3,3 volts, then later he said to use the pi to supply the 5volts to the motor contoller so that it would work? I dont know ive got the attention span of something like a bee ;)

    in the last couple of years my eyes have gone from seeing like a hawk to finding it hard to read the captions on a tv show. i couldnt make out what the connectors were i had to use on the ena enb, till i loked at your diagram again and you said "remove the jumpers " ;) haa, thx.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-07-02 13:45
    whiteoxe wrote: »
    you could maybe upload your own video, and give it a title and tags that make it easier to actually find , or post a video response. like a ten min vid,, 18 min almost put me off clicking on it !

    I agree with your suggestion about my making a video. I'll try to do this next week (I have family reunion stuff going on this week). I'll show an example of controlling the h-bridge by just setting the various pins high or low (discussed below) and I'll also have some simple Spin code to show how to control the L298N with a Propeller.
    whiteoxe wrote: »
    edit; didn't he say that the most the Pi could supply on its own was 3,3 volts, then later he said to use the pi to supply the 5volts to the motor contoller so that it would work?

    The RaspberryPi board has to be powered with 5 Volts but I believe the chip on the board uses 3.3V. The board has a regulator to reduce the 5V to 3.3V. The "general purpose input/output" (GPIO) pins can output 3.3V. When the GPIO pins are used as inputs instead of outputs, they can only tolerate 3.3V (I doubt the Pi can tolerate 5V when set to an output so in either state connecting it to 5V is bad). So when the PiGuy connected 5V to the GPIO pin he was putting more voltage on the pin than it was intended to take. Since the pin was set as an output it was probably sinking more current than the pin could safely use (I think the RPi can source or sink between 40 and 50mA (I don't know the exact figure)). It's a bad idea all the way around to connect a 5V source to a RPi's GPIO pin.

    It's also a bad idea to connect 5V to a Propeller's I/O pin unless you use a resistor to safely limit the current. Unlike the RPi, the Propeller can tolerate 5V on a pin being used as an input as long as the current is less than 500uA (half a milliamp). Connecting the 5V line directly to a Propeller I/O pin is also a bad idea.

    As I said, the RPi board is powered by 5V. The RPi has pins on the board which allows one to access this 5V source so it can be used to power other lower current devices. ThePiGuy used one of these 5V sources to power the logic portion of the L298N chip. If he had used the "5V enable" jumper (the one I said to leave in place(in post #27)), he wouldn't have needed to power the board with 5V since the regulator on the h-bridge board would have provided the 5V.

    The L298N (like many h-bridges) needs two power sources. One source is used to power the motors (around 12V in this case) and the other source powers the logic (or brains) of the chip (5V in the case of the L298N). Some h-bridge chips use 3.3V for the logic portion.

    The 5V output (or input if you don't use the on board regulator) is connected to the two pins behind ENA and ENA. I tried to show this with the yellow lines.

    These two 5V output pins can be used to tie the enable pins (ENA and ENB) high (with the jumpers). You would want to tie the enable pins high if you were to use the h-bridge board with a stepper motor (since stepper motors are controlled differently (only one stepper motor could be controlled with this h-bridge board)).

    Normal DC motors (which, based on the photo you posted, I assume you are using) work better (IMO but there is debate about this) if you pulse the enable pin (with PWM) to control the speed. The INX (where X can be the number 1 through 4) pins are used to control the direction of the motors (IN1 and IN2 to control motor A and IN3 and IN4 to control motor B) as I explained a bit in post #27.

    Are you using the Arduino with this h-bridge? If you want to try the h-bridge with the Propeller, I could probably find some demo code (in Spin) for you to try.

    One way to familiarize oneself with a h-bridge is to control the h-bridge with just wires before using a microcontroller. Connect ENA to ground to "turn off" the motor to start with. Connect IN1 to a 3.3V source and connect IN2 to ground. See which way the motor turns when you "turn the motor on" by connecting ENA to 3.3V. Turn the motor off again (by connecting ENA to ground) and switch the IN1 and IN2 connections so the one which was connected to 3.3V is now connected to ground and vice versa.

    I'll attempt to make these same points when a make a video on this topic. Most of my videos are self serving "look at me" videos so I can show off what I've done or what I'm working on. It's about time I made a video with some educational content. Who knows, maybe I'll even edit out my long pauses? Just don't expect any background music.
  • Mark_TMark_T Posts: 1,981
    edited 2014-07-02 14:21
    whiteoxe wrote: »
    Do all three of these work the same way ? Especially the sparkfun controller ?

    H-bridges might not be what you want - what motor are you thinking of?

    Low impedance bipolars need chopper drivers, high voltage unipolars only
    need ULN2803 (which can drive two motors!).
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-07-02 15:06
    erco wrote: »
    young Duane?

    It's been a while since I've been called "young Duane."

    My first and last name (and middle initial) are the same as my father's but since our middle names are different, I'm not a junior. I was often called "little Duane" or "young Duane" at family gatherings. The "young" version became more popular once I was taller than my father.

    BTW, I'm only a couple of years younger than you old Eric.

    I'm not sure if I will be able to sway TheRPiGuy over to the way of the Propeller, or as they call it on Let's Make Robots the "Cult of the Propeller". I have successfully persuaded several LMRian's to try the Propeller. I think Gareth's many amazing projects using the Propeller and Chris the Carpenter's Propeller projects made my efforts much easier.
  • whiteoxewhiteoxe Posts: 794
    edited 2014-07-07 02:31
    [QUOTE=Duane Degn;1276717
    The L298N (like many h-bridges) needs two power sources. One source is used to power the motors (around 12V in this case) and the other source powers the logic (or brains) of the chip (5V in the case of the L298N). Some h-bridge chips use 3.3V for the logic portion..[/QUOTE] I dint get much of a chance today. But I've only got the 6 volt battery pack ? Just to check my memory, did you say I should take the jumpers of the enable pins on each side, then I can just use one pin of each set high to enable it, then say to drive ENA -high to spin the wheel in one direction INA1 -high, INA2-low ? Anyway, ignore that I’m not looking at the pic or post but yes if you do put some spin code up I will give it a run ? Thx ;)
  • ercoerco Posts: 20,256
    edited 2014-07-07 09:04
    Those premade L298N modules have a built-in 5V regulator, FYI. If you keep the motor input voltage below ~18V, it works fine and you don't need a separate 5V supply. Too high and it goes boom, there's a jumper you can remove if you want to provide separate 5V. I learned the hard way. I love the smell of magic smoke in the morning!
  • whiteoxewhiteoxe Posts: 794
    edited 2014-07-07 11:35
    Too early, 4:25am, I found another picture using th 5V !

    When I’ve had breaky Ill get this motor going.


    Arduino_UNO_L298N.jpg
    910 x 683 - 160K
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-07-07 12:51
    whiteoxe wrote: »
    Too early, 4:25am, I found another picture using th 5V !

    When I’ve had breaky Ill get this motor going.


    Arduino_UNO_L298N.jpg

    Don't trust that one.

    What they are calling "motor grounds" should not be connected to ground.

    The board is significantly different from the one your have.

    I still think the diagram in post #27 is correct.
  • whiteoxewhiteoxe Posts: 794
    edited 2014-07-07 15:47
    S'ok, I am going to use your diagram ! Just thought I'd show you a similar picture which I figured u would agree 100% with ;)

    edit" would not !!!!
  • whiteoxewhiteoxe Posts: 794
    edited 2014-07-07 16:44
    Youtube is a pretty magic channel




    /*######################### ENCODER DC MOTOR CONTROL ############################
    This sketch takes the encoder code from Episode 35 and uses it to control
    a the speed and direction of a DC motor. Turning the encoder clockwise
    starts the motor in the clockwise direction and turning the encoder more
    makes the motor run faster.

    Turn the encoder counter clockwise to slow it down to a stop. Keep going
    to have the motor go in reverse, keep turning to increase the speed.

    From: Mike Myers (http://mikemyers.me) @netnutmike
    Let's Make It Episode 36 at http://tech-zen.tv

    http://tech-zen.tv

    For the sample code, show notes, contact information and many more
    videos, visit the show page at http://tech-zen.tv/letsmakeit

    Please subscribe to our YouTube channel or our netcasts at any of
    your favorite netcast / podcast outlets.

    We normally record Let's Make It live on Monday evenings around
    9pm eastern. You can watch it live by going to tech-zen.tv and clicking
    the live link at the top of the page.

    We also have a community setup for our viewers and listeners. You can
    join the community by going to community.tech-zen.tv.

    We love input on what you would like to know or if you have an idea for
    a new Let's Make it episode, you can contact us via email or phone at
    the show information page.
    ################################################################################*/

    #include <AccelStepper.h>
    #include <AFMotor.h>

    #define encoderPinA 53
    #define encoderPinB 51

    int motorspeed = 0;
    int encoderPinALast = LOW;
    int encoderPinBLast = LOW;
    int n = LOW;

    AF_DCMotor motor(1);

    void setup()
    {
    motor.setSpeed(0);

    motor.run(RELEASE);
    //motor.run(FORWARD);

    pinMode(encoderPinA, INPUT_PULLUP);
    pinMode(encoderPinB, INPUT_PULLUP);
    }

    void loop()
    {
    n = digitalRead(encoderPinA);
    if ((encoderPinALast != n )) {
    if (((n == HIGH) && (digitalRead(encoderPinB) == LOW)) ||
    ((n == LOW) && (digitalRead(encoderPinB) == HIGH))) {
    motorspeed = motorspeed - 10;
    } else {
    motorspeed = motorspeed + 10;
    }
    //Serial.print(encoderPos);
    //Serial.println(" ");
    } else {
    n = digitalRead(encoderPinB);
    if ((encoderPinBLast != n )) {
    if (((n == HIGH) && (digitalRead(encoderPinA) == LOW)) ||
    ((n == LOW) && (digitalRead(encoderPinA) == HIGH))) {
    motorspeed = motorspeed + 10;
    } else {
    motorspeed = motorspeed - 10;
    }
    //Serial.print(encoderPos);
    //Serial.println(" ");
    }
    }
    encoderPinALast = digitalRead(encoderPinA);
    encoderPinBLast = digitalRead(encoderPinB);

    if (motorspeed > 10) {
    if (motorspeed > 200)
    motorspeed = 200;
    motor.setSpeed(motorspeed);
    motor.run(FORWARD);
    } else if (motorspeed < -10) {
    if (motorspeed < -200)
    motorspeed = -200;
    motor.setSpeed(abs(motorspeed));
    motor.run(BACKWARD);
    } else {
    motor.run(RELEASE);
    }
    }



    Encoder Stepper Motor Control

    /*######################### ENCODER TO STEPPER MOTOR ############################
    This sketch takes the encoder code from Episode 35 and uses it to control
    a stepper motor. We turn the encoder clockwise and the stepper motor turns
    clockwise as well. Same thing for turning the encoder counter clockwise.

    From: Mike Myers (http://mikemyers.me) @netnutmike
    Let's Make It Episode 36 at http://tech-zen.tv

    http://tech-zen.tv

    For the sample code, show notes, contact information and many more
    videos, visit the show page at http://tech-zen.tv/letsmakeit

    Please subscribe to our YouTube channel or our netcasts at any of
    your favorite netcast / podcast outlets.

    We normally record Let's Make It live on Monday evenings around
    9pm eastern. You can watch it live by going to tech-zen.tv and clicking
    the live link at the top of the page.

    We also have a community setup for our viewers and listeners. You can
    join the community by going to community.tech-zen.tv.

    We love input on what you would like to know or if you have an idea for
    a new Let's Make it episode, you can contact us via email or phone at
    the show information page.
    ################################################################################*/

    #include <AccelStepper.h>
    #include <AFMotor.h>

    #define encoderPinA 53
    #define encoderPinB 51

    int encoderPos = 0;
    int encoderPinALast = LOW;
    int encoderPinBLast = LOW;
    int n = LOW;

    AF_Stepper motor2(200, 2);

    // wrappers for the motor!
    void forwardstep2() {
    motor2.onestep(FORWARD, SINGLE);
    }
    void backwardstep2() {
    motor2.onestep(BACKWARD, SINGLE);
    }

    // Motor shield has two motor ports, now we'll wrap them in an AccelStepper object
    AccelStepper stepper2(forwardstep2, backwardstep2);

    void setup()
    {
    stepper2.setMaxSpeed(500.0);
    stepper2.setAcceleration(100.0);
    stepper2.moveTo(0);

    pinMode(encoderPinA, INPUT_PULLUP);
    pinMode(encoderPinB, INPUT_PULLUP);
    }

    void loop()
    {
    n = digitalRead(encoderPinA);
    if ((encoderPinALast != n )) {
    if (((n == HIGH) && (digitalRead(encoderPinB) == LOW)) ||
    ((n == LOW) && (digitalRead(encoderPinB) == HIGH))) {
    motor2.step(100, BACKWARD, MICROSTEP);
    } else {
    motor2.step(100, FORWARD, MICROSTEP);
    }
    } else {
    n = digitalRead(encoderPinB);
    if ((encoderPinBLast != n )) {
    if (((n == HIGH) && (digitalRead(encoderPinA) == LOW)) ||
    ((n == LOW) && (digitalRead(encoderPinA) == HIGH))) {
    motor2.step(100, FORWARD, MICROSTEP);
    } else {
    motor2.step(100, BACKWARD, MICROSTEP);
    }
    }
    }
    encoderPinALast = digitalRead(encoderPinA);
    encoderPinBLast = digitalRead(encoderPinB);

    }
  • whiteoxewhiteoxe Posts: 794
    edited 2014-07-08 01:05
    Due to a mix up by the eBay seller, I have a spare one of these infamous controllers. Got 4 of them now. no extra charge to me. I’m happy to post it to anybody in Australia, I don’t think i;ll ever use 4 !
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-07-08 08:58
    Whiteoxe,

    I'm not sure how these ebay sellers can send these things for so little. My guess is it would cost you about the same amount to ship them locally as it would cost to purchase them from ebay.

    It's very easy to use 4. These can be used with stepper motors and normal DC motors. While a L298N can control two DC motors, the L298N can only control a single stepper motor.

    You can also use them to power high current LEDs (not a very efficient way to power LEDs but I'm pretty sure it would work).

    I use two on my Mecanum wheeled robot and two on my Rover 5 with treads.

    I wrote a two motor, all Spin driver yesterday. I've been collecting the parts I need to shoot a video and I'll likely shoot the video sometime today. I might not get it uploaded onto YouTube until tomorrow.
  • whiteoxewhiteoxe Posts: 794
    edited 2014-07-08 18:34
    Sure, thanks for the update. and you'd correct about the postage but i was feeking generous and would not mind if anyone asked me to post one ; and then if i later regretted it, it'd only cost me another 3 or 4 bucks to get from ebay.

    Does anyone know who or how the chineese can sell so cheap with little or no postage ?

    And looking forward to your vid if you get around to it today ;)

    This was where i got the latest diagram from

    http://www.funnyrobotics.com/2011/03/arduino-with-l298n-based-dual-motor.html
  • whiteoxewhiteoxe Posts: 794
    edited 2014-07-08 18:45
    Ive been trying to fix a laptop’s broken recharge/power port , replace ot. not easy at all but it was a great dell lappy so ill have to make it work. and right now im trying /about to ....fix the bootloader onmy pc to get back win and mint.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2014-07-08 18:51
    Is it just me, or do you seem to just have a LOT of rotten luck????:smile:
  • RDL2004RDL2004 Posts: 2,554
    edited 2014-07-08 18:53
    Ive been trying to fix a laptop’s broken recharge/power port , replace ot. not easy at all but it was a great dell lappy so ill have to make it work. and right now im trying /about to ....fix the bootloader onmy pc to get back win and mint.

    ...and this pertains to stepper motor controllers how?
  • kuekue Posts: 16
    edited 2014-07-08 19:37
    NWCCTV wrote: »
    Is it just me, or do you seem to just have a LOT of rotten luck????

    Well I hope you don't tear up too much, but a couple of years ago i had a very bad accident. So yea, i do have lots of bad luck. I wrote of an XR8, on a long straight road that needed fixing yup but i was flying, not sure what the eqivalant V8 is in the US. Now I walk with difficulty and can easily trip. erog (erco) I should not leave things lying around on the floor. I won't go into the depression and all that, I used to have theraspy or counselling but it was just lots of talking and boared me !I cant go back to my line of work it is way too physical but i do need to find work because my bank balance keeps going down !!
    RDL2004 wrote: »
    ...and this pertains to stepper motor controllers how?

    Whoops nothing, I just remembered to take it round to the shop neasr me to ensure i buy the right port.

    Ive forgot my password so ive logged in as an alter ego.
  • whiteoxewhiteoxe Posts: 794
    edited 2014-07-08 19:53
    kue wrote: »

    Ive forgot my password so ive logged in as an alter ego.

    Finally, I got got the string right, i must be nearly as smart as a robot .
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-07-08 22:04
    whiteoxe wrote: »
    And looking forward to your vid if you get around to it today

    I just shot the video. It's late here so I doubt I'll get it uploaded until tomorrow. I'll want to edit it a bit before making it public but once it's uploaded I'll post a link to the unlisted version.

    I have two different PWM programs, each using a different PWM technique. I'll post these programs tomorrow.
  • whiteoxewhiteoxe Posts: 794
    edited 2014-07-08 23:11
    Im looking forward to the final edit !!! I’ve been attempting to take apart a Dell Vostro laptop, its been out of action for months because I wrecked the power jack. The best a PC repair store could do for me was $125 plus $50 for the jack. I looked up the jack for my laptop model on ebay and it was around 10 dollars. Sorry , gone of the track here but that’s what I’ve been doing instead of powering up the motors !!!!
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-07-09 15:46
    I'll start a new thread in the robot forum to post this video and the code.

    For now, here's the video.

    I'll probably make a few adjustment to the captions but I hope it helps you understand how to use these h-bridges better.
  • whiteoxewhiteoxe Posts: 794
    edited 2014-07-09 19:49
    Great to see your Video and to see you using the QuickStart, I have one still sealed in its packet. I think when you've re-posted I will drive the L298N and my robot skeleton with it. So I took a one minute video to show you I have just got it working.

    Code for L298N.jpg


    http://youtu.be/vqEivw5HhO8
    819 x 518 - 126K
  • GenetixGenetix Posts: 1,754
    edited 2014-07-10 13:50
    Very nice demo Duane. (Great for R.S. QuickStarts)
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-07-10 14:05
    Genetix wrote: »
    Very nice demo Duane. (Great for R.S. QuickStarts)

    Thanks.

    I started a thread in the robot forum on this topic.
Sign In or Register to comment.