Notifications
Clear all

Big Stepper Motors with Arduino Video Tutorial

14 Posts
4 Users
0 Likes
1,528 Views
(@westb)
Member
Joined: 3 years ago
Posts: 6
Topic starter  

This is my first introduction to arduino and stepper motors. I have successfully downloaded EccelStepper Bounce sketch and modified speed, acceleration etc no problem. With the simple sketch illustrated on the tutorial which I have copied I have an error message come up when I attempt to download to my arduino a function definition is not allowed here before '{' token. This error is highlighted in pink thro the void loop () { line in the sketch so I guess the error is in the code line preseading. I have tried various mods unsuccessfully so any suggestions would be welcome. Regards Westb.

 


   
Quote
(@davee)
Member
Joined: 3 years ago
Posts: 1680
 

Hi @westb,

  There are others on this forum, who are much more experienced with stepper motors, etc. and who will be able to give more precise  advice, but I think it would help if you copy in the exact code and error message .. possibly including a screen shot of the highlighted bit. It might be something as small, but vital, as a missing semicolon, so without this information it is difficult to proceed.

NB if you haven't posted code before, have a read of the How tos under Forum Help Menu in the right hand column of this page,and use the Preview button below the editing window here, to see what you are going to post, before hitting ADD REPLY. (Lessons I learnt the hard way. 🙄 )


   
ReplyQuote
(@sj_h1)
Member
Joined: 4 years ago
Posts: 167
 

@davee Please post the code.

 


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2529
 

@westb

As DaveE implied, this sounds more like a programming error than a stepper problem and we will need to see your sketch to find and fix the problem.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@westb)
Member
Joined: 3 years ago
Posts: 6
Topic starter  
@davee

[code]
void setup() {
// put your setup code here, to run once:

// Defin pins

int reverseSwich = 2; // Push button for reverse
int driverPUL = 7; //PUL- pin
int driverDIR = 6; //DIR- pin
int spd = A0; // Potentiometer

// Variables

int pd = 500; // Pulse Delay period
boolean setdir = LOW; // Set Direction

// interrupt Handler

 

void revmotor (){
setdir = !setdir;

}

void setup ()
{

pinMode (driverPUL, OUTPUT);
pinMode (driverDIR, OUTPUT);
attachInterrupt(digitalPinToInterrupt(reverseSwitch), revmotor , FALLING);

}

void loop () {

pd = map((analogRead(spd))),0,1023,2000,50);
digitalWrite(driverDIR, setdir);
digitalWrite(driverPUL, HIGH);
delayMicroseconds(pd);
digitalWrite(driverPUL, LOW);
delayMicroseconds(pd);

}
[/code]

 

{

   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2529
 

@westb 

 

You appear to have 2 setup() sections defined one after the other.

Also, you appear to be defining your interrupt routine revmotor inside the first setup, so you're missing  "}"

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@westb)
Member
Joined: 3 years ago
Posts: 6
Topic starter  

@will  So I posted the code and confirm the stepper works well using the eccelstepper Bounce program I already downloaded


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2529
 
Posted by: @westb

@will  So I posted the code and confirm the stepper works well using the eccelstepper Bounce program I already downloaded

I think you mean AccelStepper. The fact that the stepper works with the Bounce sketch confirms the operation of the stepper motor (and library).

My observations above were for problems based on the code you posted.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@westb)
Member
Joined: 3 years ago
Posts: 6
Topic starter  

@will Thank you for that could you just clarify where the missing } should be inserted?


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2529
 

@westb 

If you start reading down the sketch until you see the first setup(), you'll find that there are a bunch of variables declared and then the start of the sub revmotor(), but there's no closing } for that original setup().

I think you need to remove the first line "void setup() {". It shouldn't be there because you define the setup section later in the code. Including those variable declarations inside setup will make them local and you won't be able to use them elsewhere in your sketch.

And you really don't want to define the revmotor interrupt code inside your setup routine.

So first, delete the single line "void setup() {" at the top and try it again.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@westb)
Member
Joined: 3 years ago
Posts: 6
Topic starter  

@will I have deleted void setup however a new error message applicable to the code line 'attachInterrupt etc'

'reverseSwitch was not declared in this scope'


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2529
 
Posted by: @westb

@will I have deleted void setup however a new error message applicable to the code line 'attachInterrupt etc'

'reverseSwitch was not declared in this scope'

You declared a variable "reverseSwich", was that what you meant ?

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@westb)
Member
Joined: 3 years ago
Posts: 6
Topic starter  

@will Sorry for delay in repy have been travelling south for holidays will return to the arduino problem when I get back. Regardsv Westb.

PS: What is a little odd about this is I have copied the sketch directly from the Bills tutorial and therefore would not have expected to have an upload problem.   


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2529
 
Posted by: @westb

PS: What is a little odd about this is I have copied the sketch directly from the Bills tutorial and therefore would not have expected to have an upload problem.   

If you did a copy and paste, then I suspect that you didn't clear out the original base sketch properly before pasting the new version in. Bill's original has none of the extra lines and typos you're seeing.

I'd suggest recopying Bill's code, deleting the entire contents of your sketch, then pasting his code back into the empty sketch and then try again.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote