Stepper don't work with Mysensors library



  • Mary Cristmas to all

    I try to make a sketch with a A4988 driver. When i activate mysensor library the stepper dont work not good any more.
    The stepper is not turning well.
    When i remark the my sensor library the everything is working okee.
    Can some one help me and give me a good advise.
    The sketch is a beginning and not ready yet.
    /* Gordijn aansturing

    • Benodigd 1 arduino pro/mini
    • 1 stepper motor
    • 1 stepper driver A4988
    • 2 switch (begin en eind)

    */
    // =========================== Zet de serielle monitor aan ========================
    #define MY_DEBUG
    // ********************************************************************************

    // =========================== Radio instelling RFM 69 ============================
    //#define MY_RADIO_NRF24
    #define MY_RADIO_RFM69
    #define MY_RFM69_FREUENCY RF69_433MHZ
    #define MY_RFM_PA_LEVEL RF69PA_LOW
    #define MY_ISRFM69HW
    //********************************************************************************

    //=========================== Node en Child infomatie ============================
    #define MY_NODE_ID 13
    #define CHILD_ID 20
    //********************************************************************************
    // defines pins numbers
    int stepPin = 8;
    int dirPin = 9;
    // ========================= Libraries ===========================================
    #include <SPI.h>
    //#include <MySensors.h>
    #include <Wire.h>
    // *******************************************************************************

    void setup() {
    // Sets the two pins as Outputs
    pinMode(stepPin,OUTPUT);
    pinMode(dirPin,OUTPUT);
    }
    void loop() {
    digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
    // Makes 200 pulses for making one full cycle rotation
    for(int x = 0; x < 200; x++) {
    digitalWrite(stepPin,HIGH);
    delayMicroseconds(500);
    digitalWrite(stepPin,LOW);
    delayMicroseconds(500);
    }
    delay(1000); // One second delay

    digitalWrite(dirPin,LOW); //Changes the rotations direction
    // Makes 400 pulses for making two full cycle rotation
    for(int x = 0; x < 400; x++) {
    digitalWrite(stepPin,HIGH);
    delayMicroseconds(500);
    digitalWrite(stepPin,LOW);
    delayMicroseconds(500);
    }
    delay(1000);
    }

    Greatz Ton


  • Mod

    @TON-RIJNAARD the way this code drives the motor requires 100% cpu all the time, so it will have trouble co-existing with almost any library.

    To my knowledge, you'll either need to write custom code that doesn't use delay, something similar to what is discussed in http://forum.arduino.cc/index.php?topic=137269.0 or you need to use a stepper motor library that already does that. I am not sure if http://www.airspayce.com/mikem/arduino/AccelStepper/ supports the A4988 but it might be worth a shot.


  • Mod

    Stumbled on an Instructables that could be useful:
    http://www.instructables.com/id/Control-a-Stepper-Motor-With-PWM/?ALLSTEPS



  • @mfalkvidd Tanks for the help i give it atry. I am new to arduino so maby i need more help. I let you now when it is nessesary.

    Greatz Ton


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.