Zum Inhalt springen

Antwort auf: Mega2560 an DRV8825 und Schrittmotor

Projekte und Tutorials für Arduino Foren StartHardware-Forum Mega2560 an DRV8825 und Schrittmotor Antwort auf: Mega2560 an DRV8825 und Schrittmotor

#8588
Stefan Hermann
Administrator

So, jede Menge Try&Error und wenig Wissenschaft. Aber bei mir funktioniert diese Kombi:

  1. Library: StepperDriver by Laurentiu Badea (Kannst du über Sketch>Bibliotheken einbinden>Bibliotheken verwalten …) suchen und installieren.
  2. Schaltung:
    Ist im Grunde die, die du geschickt hattest, nur dass Pin 13 am Sleep hängt

    • Pin 13 -> SLEEP
    • Pin 9 -> DIR
    • Pin 8 -> STEP
    • GND -> GND
    • 5V+ -> RESET
  3. Strom habe ich per Poti auf 1,6A -> Zum Einstellen (Nur zum Einstellen! Der Code funktioniert bei mir nicht.) habe ich diese Anleitung verwendet: https://www.makerguides.com/drv8825-stepper-motor-driver-arduino-tutorial/
  4. Code ist aus dem Beispiel der Library Datei>Beispiele>StepperDriver>AccelTest. Da musst du noch den richtigen Treiber einkommentieren oder du nimmst den Code hier:
/*
 * Using accelerated motion ("linear speed") in nonblocking mode
 *
 * Copyright (C)2015-2017 Laurentiu Badea
 *
 * This file may be redistributed under the terms of the MIT license.
 * A copy of this license has been included with this distribution in the file LICENSE.
 */
#include <Arduino.h>

// Motor steps per revolution. Most steppers are 200 steps or 1.8 degrees/step
#define MOTOR_STEPS 200
// Target RPM for cruise speed
#define RPM 120
// Acceleration and deceleration values are always in FULL steps / s^2
#define MOTOR_ACCEL 2000
#define MOTOR_DECEL 1000

// Microstepping mode. If you hardwired it to save pins, set to the same value here.
#define MICROSTEPS 16

#define DIR 8
#define STEP 9
#define SLEEP 13 // optional (just delete SLEEP from everywhere if not used)

/*
 * Choose one of the sections below that match your board
 */

//#include "DRV8834.h"
//#define M0 10
//#define M1 11
//DRV8834 stepper(MOTOR_STEPS, DIR, STEP, SLEEP, M0, M1);

// #include "A4988.h"
// #define MS1 10
// #define MS2 11
// #define MS3 12
// A4988 stepper(MOTOR_STEPS, DIR, STEP, SLEEP, MS1, MS2, MS3);

#include "DRV8825.h"
#define MODE0 10
#define MODE1 11
#define MODE2 12
DRV8825 stepper(MOTOR_STEPS, DIR, STEP, SLEEP, MODE0, MODE1, MODE2);

// #include "DRV8880.h"
// #define M0 10
// #define M1 11
// #define TRQ0 6
// #define TRQ1 7
// DRV8880 stepper(MOTOR_STEPS, DIR, STEP, SLEEP, M0, M1, TRQ0, TRQ1);

// #include "BasicStepperDriver.h" // generic
// BasicStepperDriver stepper(DIR, STEP);

void setup() {
    Serial.begin(115200);

    stepper.begin(RPM, MICROSTEPS);
    // if using enable/disable on ENABLE pin (active LOW) instead of SLEEP uncomment next line
    // stepper.setEnableActiveState(LOW);
    stepper.enable();
    // set current level (for DRV8880 only). Valid percent values are 25, 50, 75 or 100.
    // stepper.setCurrent(100);

    /*
     * Set LINEAR_SPEED (accelerated) profile.
     */
    stepper.setSpeedProfile(stepper.LINEAR_SPEED, MOTOR_ACCEL, MOTOR_DECEL);

    Serial.println("START");
    /*
     * Using non-blocking mode to print out the step intervals.
     * We could have just as easily replace everything below this line with 
     * stepper.rotate(360);
     */
     stepper.startRotate(360);
}

void loop() {
    static int step = 0;
    unsigned wait_time = stepper.nextAction();
    if (wait_time){
        Serial.print("  step="); Serial.print(step++);
        Serial.print("  dt="); Serial.print(wait_time);
        Serial.print("  rpm="); Serial.print(stepper.getCurrentRPM());
        Serial.println();
    } else {
        stepper.disable();
        Serial.println("END");
        delay(3600000);
    }
}

Hoffe, das klappt auch bei dir.