Issue with stepper motor: 'Stepper' does not name a type [RESOLVED]

Hi everyone!

I’m trying to run a NEMA-17 bipolar stepper from my core, but when I go to verify the code in the web IDE I end up with the error:

Stepper.cpp:62:1: error: 'Stepper' does not name a type
Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2)

As the motor I am using has four leads, when I comment it out, the error crops up a few lines later for the four lead version.

I’ve copied Stepper.h and Stepper.cpp into my file and called #include “Stepper.h”. How would I name a ‘type’ for Stepper to resolve the issue?

Thanks for the help! My .ino code is as follows:

//Includes
#include "application.h"
#include <Stepper.h>
#include "math.h"

//Defines
#define STEPS 200
#define ADCwidth 12
#define ADCsteps pow(2, ADCwidth)
#define maxSpeed 256 //RPM (for test, using max LED value 255)

Stepper stepper(STEPS, D0, D1, D2, D3);

int potPin = A0;
int LEDPin = D5;
int potVal = 0;
uint8_t speed = 0;

void setup() {
    Serial.begin(9600);
    pinMode(potPin, INPUT);
    pinMode(ledPin, OUTPUT); //LED brightness correlates to motor speed
    stepper.setSpeed(0);
}

void loop() {
    potVal = analogRead(potPin);
    speed = floor(potVal/(ADCsteps/maxSpeed));
    analogWrite(ledPin, speed);
    stepper.setSpeed(speed);
    stepper.step(1);

    display();
}

void display() {
    Serial.print("Pot Val: ");
    Serial.print(potVal);
    Serial.print(" | ");
    Serial.print("Speed: ");
    Serial.println(speed);
}

Try #include "Stepper.h"

Where did you copy the library from?

Thanks for the suggestion, but that didn’t change the error.

I copied it from:

https://community.spark.io/t/stepper-motor-with-spark-core/1168

@BDub’s post from January. I copied each section (Stepper.cpp and Stepper.h into their own tab) and #include “Stepper.h” in my .ino.

Give me a few minutes. Wrapping it up into a Web IDE library now :wink:

Hi @gaudsend

I copied those files over just now and I see some of the problems. That code was from a time when all your libraries had to go in the same file in the web IDE and some the includes are not right for separate files.

In Stepper.cpp, add #include "Stepper.h" near the top of the file.

As @kennethlimcp said, you have to use #include "Stepper.h" in your sketch.

I also found a couple of typos around ledPin versus LEDPin which I changed to all use LEDPin.

After those changes it compiled for me.

@bko hi5!

I have fixed them and gonna publish a library now. DO you have any idea why Stepper stepper() gives and error for multiple declaration?

Too many includes? Maybe a #pragma once in the header file.

@gaudsend,

you should now see the Stepper library in the Web IDE. Simple remove all the libraries you pasted and include the published library.


The error code doesn’t make sense to me:

testing.o:(.bss+0x0): multiple definition of `stepper'
Stepper.o:/spark/compile_server/shared/workspace/2_compile-server2/core-firmware/build/../inc/spark_wiring_ipaddress.h:48: first defined here
collect2: error: ld returned 1 exit status
make: *** [e48da1182b542636318866f77604d9399bbdb62b41359b09d5da11b46595.elf] Error 1

Also, the github repo is here in case you found the issue: https://github.com/kennethlimcp/spark-stepper

1 Like

Awesome, @kennethlimcp, @BDub, and @bko! Thank you all very much. Works like a charm.

1 Like

I just tried it and I’m not seeing any error… were you still getting one? And thanks for wrapping that up into a library!

1 Like

I used stepper1 in the example. Did you try stepper?

Yeah that’s weird…I get the error with “stepper” in your library as well… but interestingly enough the very first app I created was Stepper, and it still compiles fine… with “stepper” as the class instance name.

Look at the error message. Something might be weird about the makefile or compiler. :slight_smile:

Ok, so I went to flash the code to a different core today and the error @kennethlimcp mentioned came up. Specifically, the error is as follows:

multiple definitions of Stepper::stepper(int, int, int)
multiple definitions of Stepper::stepper(int, int, int, int, int)
multiple definitions of Stepper::setSpeed(long)
multiple definitions of Stepper::stepMotor(int)
multiple definitions of Stepper::step(int)
multiple definitions of Stepper::version()

Is it just a matter of commenting out/removing lines from the library?

Thanks.

If you create the Stepper instance as Stepper stepper1(STEPS, D0, D1, D2, D3); it should work fine… I even added multiple header includes and it didn’t break.

Ok, thanks @BDub! I’ll check it out once I get home this evening and report back. Thanks for the help.

1 Like

Awesome! It compiled! Now just need to get the circuit working. Thanks for all the help!

1 Like

@BDub and @gaudsend,

i found the issue with stepper having multiple declation

It turns out that the example code was copied into the .cpp file.

Fixed the library already. :wink:

3 Likes