Stepper motor woes

Hi… complete newbie here, so thanks for adding me to forum. The site is full of great info…

I am trying to run a stepper motor, with Easy Driver and Arduino UNO clone. I have the motor wired up as per the sketches in the basic wiring sketch, and have tried to upload the first section of code on the page, which is as follows:

//Declare pin functions on RedBoard

#define stp 2

#define dir 3

#define MS1 4

#define MS2 5

#define EN 6

//Declare variables for functions

char user_input;

int x;

int y;

int state;

void setup() {

pinMode(stp, OUTPUT);

pinMode(dir, OUTPUT);

pinMode(MS1, OUTPUT);

pinMode(MS2, OUTPUT);

pinMode(EN, OUTPUT);

resetEDPins(); //Set step, direction, microstep and enable pins to default states

Serial.begin(9600); //Open Serial connection for debugging

Serial.println(“Begin motor control”);

Serial.println();

//Print function list for user selection

Serial.println(“Enter number for control option:”);

Serial.println(“1. Turn at default microstep mode.”);

Serial.println(“2. Reverse direction at default microstep mode.”);

Serial.println(“3. Turn at 1/8th microstep mode.”);

Serial.println(“4. Step forward and reverse directions.”);

Serial.println();

}

Firstly for some reason I get this error:


Arduino: 1.8.13 (Windows Store 1.8.39.0) (Windows 10), Board: “Arduino Uno”

C:\Users\ianya\AppData\Local\Temp\cc9b5P7b.ltrans0.ltrans.o: In function `main’:

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.39.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/main.cpp:46: undefined reference to `loop’

collect2.exe: error: ld returned 1 exit status

exit status 1

Error compiling for board Arduino Uno.

This report would have more information with

“Show verbose output during compilation”

option enabled in File → Preferences.


Secondly, to run this code, do I need a terminal of some sort to enter the requested values in the last section of the sketch??? Is this necessary, can it be removed for a simple “run” command or something?

The truth is, I am complete novice to arduino/steppers… tho I control them somewhat on my 3D printer.

This project is just to start the motor and run it very slowly (10rpm) till it hits a limit switch, then reverse direction for a fixed amount, then returning again to the switch and repeat. The stepper just turns a M8 rod, followed by a nut.

i have photo’s but the page gives me a HTTP error when I upload.

I have checked all the wiring and solder joints, which are all good.

Any help would be fab!

No worries, welcome!

First off, your code is missing portions that are required for the program to even run. At minimum the code should have the following:

void setup(){
//basic setup of variables and other needed parts
}

void loop(){
//where the actual algorithms and functions perform their magic (with some exceptions)
}

You are missing the loop() section. I would suggest using full code found on GitHub: https://github.com/sparkfun/Easy_Driver … r/Firmware.

As far as the input’s are concerned, you’ll enter values in using the Serial Monitor or an equivalent Serial terminal program. I would suggest looking at our hookup and getting started guides if you haven’t already. https://learn.sparkfun.com/tutorials/ea … k-up-guide

Good luck, keep pushing

Thanks for your reply Brandon

I’ve been working on the code… it’s changed completely and I can make the motor run in one direction:

#include <Stepper.h>

int stepsPerRevolution = 6400;

int motSpeed = 10;

int dt = 500;

int buttonPin = 8;

int motorDir = 1;

int buttonValNew;

int buttonValOld = 1;

Stepper myStepper(stepsPerRevolution, 2, 3, 5, 6);

// Declare pin functions on RedBoard

#define stp 2;

#define dir 3;

#define MS1 4;

#define MS2 5;

#define EN 6;

void setup() {

// put your setup code here to run once

Serial.begin (9600);

myStepper.setSpeed(motSpeed);

pinMode(buttonPin, INPUT);

digitalWrite(buttonPin, HIGH);

}

void loop () {

myStepper.step(stepsPerRevolution);

buttonValNew = digitalRead(buttonPin);

if (buttonValOld == 1 && buttonValNew == 0);

motorDir = motorDir * (-1);

}

// myStepper.step(stepsPerRevolution);

// delay(dt);

// myStepper.step(-stepsPerRevolution);

// delay(dt);

// }

The motor runs but has very little torque, I don’t know if this is a characteristic of this particular motor, which is 1.8deg/step , rated at 0.4Amp but I can stop it with very little pressure from just my fingertips???

I don’t know the serial monitor, but I’ve got rid of the inputs anyway… (BTW: that original code was copied directly from your sites instructions, which I have gone thru as much as one can…)

Anyhow, I’m getting along, but still have issues… my button (a limit switch, similar to the 3 axis switches on 3D printer) doesn’t change direction yet… nor did the hashed out section of code at the end… this runs the motor, but I am having trouble getting steps/rev correct and the auto change of direction (in fact I cannot get any change of direction without reversing the wiring to the motor)

Still looking for help???

To what value did you set the EasyDriver current limit?

What are the V/A characteristics of the motor power supply?