Stepper Motor Issues

Posted on
  • @Gordon @DrAzzy

    This is the code I'm using to generate what is called a 'Wave Drive' using this module DC 5V Stepper Motor + ULN2003 Driver Test Module and this is the result I'm getting: video

    Can someone tell me why this motor is spinning so slowly?

    function stepper(func) {
      var a = C11, b = C9, c = C7, d = C6;
      var list = [d,c,b,a];
      for (var j = 0; j < 1000; j++) {
        for (var v = 0; v < list.length; v++) {
          digitalWrite(list[v],1);
          for (var h = 0; h < list.length; h++) {
            func(h,v,list);
          }
        }
        digitalWrite(d,0);
      }
      digitalWrite(a,0);
    }
    
    function stepperWaveDrive() {
      stepper(function (h,v,list) {
        if (list[h] != list[v]) digitalWrite(list[h],0);
      });
    }
    
    stepperWaveDrive();
    
    //stepperNormalFull();
    

    This is the attempt with Espruino 4 Step Control Code

    Video

    var step = 0;
    var steps = [0b0001,0b0010,0b0100,0b1000];
    var stepperPins = [C11,C9,C7,C6];
    
    function doStep() {
     step++;
     digitalWrite(stepperPins, steps[step % steps.length]);
    }
    var stepInterval = setInterval(doStep, 200);
    
  • Take a look at this conversation about Stepper Motor Spinning Slow.

    Your second example of code is close to work... according to the motor's datasheet, it is a two phase 5-wire motor which needs two waves that overlap (that's why between every step with just one bit on there is an 'instable' half-step with 2 bits on)... just change your steps to

    var steps = [0b0001,0b0011,0b0010,0b0110,0b0100,0b11­00,0b1000,0b1001];
    

    and it will work... almost always... Almost because the loop can be too fast. In above mentioned conversation I go into some details where the limits come and may come from...

    The first example code *is a lot of busy code for little thing to achieve* (which last but not least contributes to the slowness - see Espruino Performance)...

    Therefore, take advantage of what Espruino comes with right out of box: Smart, concise way to talk to the GPIOs... ;-) - thanks @Gordon

    Enjoy!

  • I thought that was just one type of sequence... the Wave Drive, Normal Full Step, and the Half-Step Drive... will try this later, but could you explain what these step array elements are doing? Also, how am I able to reverse the direction of the motor? When I reverse the order of the pins in the code, it just jitters...


    1 Attachment

    • Screenshot 2015-03-06 at 4.53.13 PM.png
  • I'm not sure about your initial code, but generally it's not very good practice to do a big loop in Espruino - it's much better to use setInterval (as then it can do other things in the background).

    For a description of what the patterns are doing, see the wikipedia page and the animation on it for simple 'wave drive'. When you use half-step, it's almost like you're 'faking' another 4 electromagnets by turning 2 on at once, so you're able to pull the rotor around at 45 degree intervals rather than 90. It means you have a bit more control over the rotor, but also you can move it round with a bit more power.

    If you want to reverse the direction of the motor, simply decrement the 'steps' variable instead of incrementing it. You just want to go through the same step pattern from right to left rather than left to right.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Stepper Motor Issues

Posted by Avatar for user52526 @user52526

Actions