Compilation error: redefinition of 'void setup()

Here my code and error message. What is my issue?

#include <AccelStepper.h>

AccelStepper stepper(AccelStepper::DRIVER, 2, 3); // StepPin D2 and DirPin D3

void setup() 
{  
  stepper.setMaxSpeed(4000);
  	
}

void loop()
{  
  int potValue = analogRead(A0);
  if (potValue < 100) potValue = 0;
  int stepperMotorSpeed = map(potValue, 0, 1023, 0 4000);

  stepper.setSepeed(stepperMotorSpeed);
  stepper.runSpeed();
}
C:\Users\joel.gillard\Downloads\CNC_Shield_Demo\Turntable_RPM.ino: In function 'void setup()':
C:\Users\joel.gillard\Downloads\CNC_Shield_Demo\Turntable_RPM.ino:5:6: error: redefinition of 'void setup()'
 void setup()
      ^~~~~
C:\Users\joel.gillard\Downloads\CNC_Shield_Demo\CNC_Shield_Demo.ino:14:6: note: 'void setup()' previously defined here
 void setup() {
      ^~~~~
C:\Users\joel.gillard\Downloads\CNC_Shield_Demo\Turntable_RPM.ino: In function 'void loop()':
C:\Users\joel.gillard\Downloads\CNC_Shield_Demo\Turntable_RPM.ino:11:6: error: redefinition of 'void loop()'
 void loop()
      ^~~~
C:\Users\joel.gillard\Downloads\CNC_Shield_Demo\CNC_Shield_Demo.ino:24:6: note: 'void loop()' previously defined here
 void loop() {
      ^~~~
C:\Users\joel.gillard\Downloads\CNC_Shield_Demo\Turntable_RPM.ino:15:52: error: expected ')' before numeric constant
   int stepperMotorSpeed = map(potValue, 0, 1023, 0 4000);
                                                    ^~~~
C:\Users\joel.gillard\Downloads\CNC_Shield_Demo\Turntable_RPM.ino:15:56: error: too few arguments to function 'long int map(long int, long int, long int, long int, long int)'
   int stepperMotorSpeed = map(potValue, 0, 1023, 0 4000);
                                                        ^
In file included from C:\Users\joel.gillard\AppData\Local\Temp\arduino\sketches\D294C475B7D271F1092015C861DEAD8E\sketch\CNC_Shield_Demo.ino.cpp:1:0:
C:\Users\joel.gillard\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/Arduino.h:254:6: note: declared here
 long map(long, long, long, long, long);
      ^~~
C:\Users\joel.gillard\Downloads\CNC_Shield_Demo\Turntable_RPM.ino:17:11: error: 'class AccelStepper' has no member named 'setSepeed'; did you mean 'setSpeed'?
   stepper.setSepeed(stepperMotorSpeed);
           ^~~~~~~~~
           setSpeed

exit status 1

Compilation error: redefinition of 'void setup()'

You just told the compiler to go to the red house in NY. It does not have a clue. Help it out by following the rules and use void setup() only one time. This goes for all functions. If you good you now know what the error report will look like.

The error messages seem to talk about two files. Do you have multiple tabs in your project?

CNC_Shield_Demo.ino

 and 

Turntable_RPM.ino

Copy the code you posted and paste it over a new sketch.

a7

missing a comma..

should be setSpeed.. :slight_smile:

good luck.. ~q

Yes. With the errors @qubits-us also found, it compiles. It may even do what you want. :wink:

I can't explain @joelgillard's error trail, it is not the errors I got when the code was pasted into a blank skech.

a7

looks like there is more than one *.ino file in the directory.. :frowning:

@joelgillard put each *.ino in it's own folder named same as the *.ino but without the .ino..

for example.. StepperTest.ino inside folder called StepperTest, no other *.ino file can be in there or they try to compile into one which is not what you desire..

good luck.. ~q

That would do it. And starting with a blank sketch is a fix, as it doesn't yet have a project folder, at least not one you are likely to see or find.

The first time you save a "sketch_jul16e" kinda project, you have to get an opportunity to name it. Then you have a folder with one *.ino with the same name.

Yes. All *.ino files are concatenated and the result is fed to the compiler. Some use tabs in this way as an organizational aid. It has plusses and minuses.

If you just try to open an ino file, the IDE, at least v 1.18.9, will complain and offer to move the sketch down into a new folder it will make for it, so I wonder how @joelgillard managed to get into that trouble.

a7

Thank you all! Having 2 tabs open, the missing common, and mis-spelling was my issue. It works now and even drives the stepper motor with a speed potentiometer.

Made it the "red house in NY" !!!

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.