Hi there!
I'm trying to manipulate a stepper motor to create a displacement on an axis of a CNC machine.
In order to do that, I have an Arduino UNO, a stepper motor coming from an old CD-ROM (so I have no information on that motor) and a stepper driver (
A4988).
For the wiring, it is as following:
-> MS1, MS2, MS3 on the D10, D11, D12 pin of the Arduino.
-> ENABLE pin isn't wired.
-> SLEEP pin and RESET pin are connected together.
-> DIRECTION is set to D8.
-> STEP is set to D9.
The rest is wired the same as the scheme in the A4988 datasheet.
My biggest issue here is that I don't know the characteristics of the motor, so I don't have the angular resolution or the number of steps per revolution.
Well, first, I tried to make the stepper motor works by using this code (
library used) :
#include <Arduino.h>
#include "BasicStepperDriver.h"
// Motor steps per revolution. Most steppers are 200 steps or 1.8 degrees/step
#define MOTOR_STEPS 200
#define RPM 30
// Since microstepping is set externally, make sure this matches the selected mode
// If it doesn't, the motor will move at a different RPM than chosen
// 1=full step, 2=half step etc.
#define MICROSTEPS 16
// All the wires needed for full functionality
#define DIR 8
#define STEP 9
//Uncomment line to use enable/disable functionality
//#define SLEEP 13
// 2-wire basic config, microstepping is hardwired on the driver
BasicStepperDriver stepper(MOTOR_STEPS, DIR, STEP);
//Uncomment line to use enable/disable functionality
//BasicStepperDriver stepper(MOTOR_STEPS, DIR, STEP, SLEEP);
void setup() {
stepper.begin(RPM, MICROSTEPS);
// if using enable/disable on ENABLE pin (active LOW) instead of SLEEP uncomment next line
// stepper.setEnableActiveState(LOW);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
}
void loop() {
// energize coils - the motor will hold position
// stepper.enable();
/*
* Moving motor one full revolution using the degree notation
*/
stepper.rotate(-20);
// pause and allow the motor to be moved by hand
stepper.disable();
delay(2000);
}
Note that I put D10, D11, and D12 to high because I wanted a sixteenth step resolution (for a "smooth movement").
So with this code, everything is kind of fine, I create a "negative" displacement like I wanted. But, I can't stop the motor, I tried the stepper.stop() and stepper.disable() function but none of them worked.
So I thought of using the AccelStepper library, I downloaded it and try to launch an example :
// Blocking.pde
// -*- mode: C++ -*-
//
// Shows how to use the blocking call runToNewPosition
// Which sets a new target position and then waits until the stepper has
// achieved it.
//
// Copyright (C) 2009 Mike McCauley
// $Id: Blocking.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $
#include <AccelStepper.h>
// Define a stepper and the pins it will use
AccelStepper stepper(1,9,8); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
void setup()
{
stepper.setMaxSpeed(20.0);
stepper.setAcceleration(20.0);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
}
void loop()
{
stepper.runToNewPosition(0);
stepper.runToNewPosition(18);
}
But, the motor is not moving at all, it is just making small noises.
Any ideas why?
Best regards!