RE: step motor

I am programming my step motor to turn a full revolution and keep getting a few error message when compiling >:( The motor is 32 steps for full revolution I think. The error messages and code are below.

In function ‘void setup()’:

sketch_dec31a:22: error: expected unqualified-id before ‘.’ token

Stepper.setSpeed(100);

^

In function ‘void loop()’:

sketch_dec31a:31: error: ‘step’ cannot be used as a function

step(32);

^
exit status 1
expected unqualified-id before ‘.’ token

#include <Stepper.h>
#define pin1 4
#define pin2 3
#define pin3 5
#define pin4 1
int step = 32;
int NumSteps = 200;
int Distance = 0;
int Speed = 100;
int MicroSteps = 16;
int FullRotation = NumSteps * MicroSteps;
void setup() {
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT);
digitalWrite(4, LOW);
digitalWrite(3, LOW);
digitalWrite(5, LOW);
digitalWrite(1, LOW);
Stepper.setSpeed(100);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(4, HIGH);
digitalWrite(3, HIGH);
digitalWrite(5, HIGH);
digitalWrite(1, HIGH);
step(32);
delay(3000);
}

Here’s your code formatted and in code tags to ward off the tag police.

#include <Stepper.h>
#define pin1 4
#define pin2 3
#define pin3 5
#define pin4 1
int step = 32;
int NumSteps = 200;
int Distance = 0;
int Speed = 100;
int MicroSteps = 16;
int FullRotation = NumSteps * MicroSteps;

void setup() {
  pinMode(pin1, OUTPUT);
  pinMode(pin2, OUTPUT);
  pinMode(pin3, OUTPUT);
  pinMode(pin4, OUTPUT);
  digitalWrite(4, LOW);
  digitalWrite(3, LOW);
  digitalWrite(5, LOW);
  digitalWrite(1, LOW);
  Stepper.setSpeed(100);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(4, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(1, HIGH);
  step(32);
  delay(3000);
}

Stepper is not an object so you can’t use Stepper.setSpeed();. I assume you need to declare a stepper object first, then call the setSpeed() method on that.

Next time code tags and formatting. Its the polite thing to do.

-jim lee

You have included the stepper library but do not seem to have declared a stepper object. Have you looked at the stepper examples ?

  1. read the forum rules, especially how to post code in code tags
  2. if your stepper is in 1/16 mode and needs 200 steps for one revolution, then it needs 3200 steps for one turn
  3. you define step as integer with a value of 32 and in your loop you try to call step as a function with the argument 32 -> that won't work and causes the error

So, study the stepper library examples, how to declare stepper objects, call the stepper commands and send 3200 steps.

It would also be good to see, What stepper What driver How is the wiring

Addit: @jimlee (almost) fixed everything for you (he deserves karma points from you, although we tend to let our newbies do the job based on our advices normally ..). Modify the number of steps being sent from 32 to 3200 ( theStepper.step (3200)) and you will be set, given that the driver is adjusted (current limits) and the wiring is correct.

Addit2: Just saw that @jimlee jumped back to your original code so my first addit is not addressing the current code. Declare the stepper right and then send 3200 steps in your loop and it should work (given the assumptions in my previous posts are considered).

@rpt007 Before seeing yours I saw that I'd screwed up and deleted my "fixed" version. Thanks anyway.

-jim lee