You are reading a single comment by @fobus and its replies. Click here to read the full conversation.
  • Hello,

    There is many questions, I'm sorry if I forgot to answer anyone.

    At first, all 3 code work. The first code that write at the start of this thread works so slow.
    The second one (http://forum.espruino.com/comments/12041­929/) works good bot not fast as @DrAzzy's code (http://forum.espruino.com/comments/12042­026/)
    @DrAzzy code is the fastest (Apx. 13 RPM) When I use this code leds are not blinking in sequence any more. Leds allways on.

    I think that I'm wiring up correctly.

    I'm using stm32F4DISCOVERY. I'm using my boards power supply(5+), today I'm going to try with +9 Volt external battery and write results here.

    I have catched an interesting point.
    @DrAzzy's code works good but only with console.log("doing step:"+step); line.
    When I comment out this line it doesn't work :)

    Also, when I flash the code -with save()- in to the device and restart it @DrAzzy's code doesn't works. It's about console.log() command. I think console.log() command doesn't work if device is working stanalone.

    So, I thought that it needs to wait a little bit before doing next step, here is my new code works good without comments and after save()

    var step = 0;
    pinMode(D1,'output');
    pinMode(D2,'output');
    pinMode(D3,'output');
    pinMode(D4,'output');
    var steps = [0b0001,0b0011,0b0010,0b0110,0b0100,0b11­00,0b1000,0b1001];
    var stepperPins = [D4,D3,D2,D1]; // Change these to pins for your motor driver
    function doStep() {
     step++;
      i=0;
      while(i!=3)i++; //delay a little bit before doing steps. Better than console.log()
    var stepval=steps[step % steps.length];
    digitalWrite(stepperPins[0],stepval&1);
    digitalWrite(stepperPins[1],stepval&2);
    digitalWrite(stepperPins[2],stepval&4);
    digitalWrite(stepperPins[3],stepval&8);
    }
    var stepInterval = setInterval(doStep, 1);
    
About

Avatar for fobus @fobus started