Arduino Forum

Using Arduino => Motors, Mechanics, Power and CNC => Topic started by: neksmerj on Nov 08, 2014, 05:30 am

Title: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 08, 2014, 05:30 am
Not long ago, Robin2 wrote a terrific article entitled:-

Planning & implementing an Arduino program, see here http://forum.arduino.cc/index.php?topic=261445.0

I would be extremely grateful if a similar tutorial could be written to drive a nema 17 stepper motor utilizing an Arduino uno R3 board,and an Adafruit stepper motor board.

Simple controls such as a 3 position switch for forward, stop and reverse, and a potentiometer to control speed.

What I would like to see is how each line of code is developed with an explanation of what each piece of code means along with the meaning of each character.

Once I have a piece of code, how do I get it into my computer and transfer it to the Arduino?

As you can tell, I know absolutely nothing about Aduino's or programming.

Hoping someone can throw some light on my short comings.

Ken 
Title: Re: Arduino uno R3 stepper motor control
Post by: JimboZA on Nov 08, 2014, 07:51 am
Have you looked at ada's own tutorial here (https://learn.adafruit.com/adafruit-motor-shield/using-stepper-motors)?

It looks straightforward: if you haven't looked at it, why not try now and see if it makes sense. Then ask specific questions about things that don't make sense to you.
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 08, 2014, 09:19 am
Thanks Kimbo,

Yes I have looked at the tutorial, but it doesn't describe what each program step does, nor how to get the program into my computer then into the Arduino.

Many thanks anyway.

Ken
Title: Re: Arduino uno R3 stepper motor control
Post by: JimboZA on Nov 08, 2014, 09:37 am
That's Jimbo with a "J"....  8)

Getting it into your Arduino's a matter of ctrl-c copying off the screen and ctrl-v pasting into the IDE, then upload.

Seems like you've not yet worked through the examples in the ide, which are also available here (http://arduino.cc/en/Tutorial/HomePage). I'm pretty sure that if you worked through some of those, the ada code would make a fair amount of sense and the forum will help with the missing bits.

You would then most likely be able to answer your own questions about switches for direction and a pot for speed.
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 08, 2014, 10:59 am
Jimbo, sorry for misspelling your name.

You are talking to an absolute, total, novice. Reading other sketches means nothing to me. I need an example sketch to control a stepper motor with a line by line description of what each line/character means. I won't know what I'm doing otherwise.

Ken
Title: Re: Arduino uno R3 stepper motor control
Post by: JimboZA on Nov 08, 2014, 11:32 am
Yep I get the novice bit, but I think the best way to become a not-a-novice, is to work through the examples that I linked to and which are in the ide in File > Examples.

Then, when you try to understand other code you'll have a fighting chance of figuring it out for yourself. Granted, right now a stepper sketch might make no sense, but it will make sense when you get your mind round some basic concepts.

Don't get me wrong: not refusing to assist, it's just that forum experience is that it's better to go it alone first, then ask for help on specifics. And going it alone, implies working through at least some of those examples.
Title: Re: Arduino uno R3 stepper motor control
Post by: Robin2 on Nov 08, 2014, 11:43 am
I am being polite when I say I am confused.

You sent me a PM earlier today with a link to your other Thread (http://forum.arduino.cc/index.php?topic=276204.0) - to which I replied that I was waiting for your response to advice I had given on 1 Nov - the same day you started the other Thread.

Now I find you have started a new Thread (quite unnecessarily) asking for advice which I had already given in the other Thread. I still don't know if you read it.


OK - that advice may not cover all of your present question but it covers at least 50% of it - and the rest (detecting buttons) is well covered in my article and in the sticky several things at a time (http://forum.arduino.cc/index.php?topic=223286.0)

...R
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 08, 2014, 12:48 pm
Hi Robin2

It seems we have crossed paths. The only response I thought I had from you was that you don't respond to PM's, and you suggested that I start a new thread, so that's what I did.

I am new to this forum and am still feeling my way around.

Ken
Title: Re: Arduino uno R3 stepper motor control
Post by: Robin2 on Nov 08, 2014, 01:58 pm
I am new to this forum and am still feeling my way around.
Precisely because you are new to the Forum I would assume you are doing a lot of reading - especially in Threads that you have started yourself.

You may be interested in the code in this new Thread (http://forum.arduino.cc/index.php?topic=277692)

...R
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 09, 2014, 02:10 am
Hi Robin2, you are correct, I am reading as much as time allows.

Can you recommend some books that will give me an insight into the Ardinuo world.

Thanks for your assistance.

Ken
Title: Re: Arduino uno R3 stepper motor control
Post by: Robin2 on Nov 09, 2014, 10:34 am
Hi Robin2, you are correct, I am reading as much as time allows.

Can you recommend some books that will give me an insight into the Ardinuo world.
I haven't got the impression you are reading the stuff I have taken the time to write !

Sorry, I don't have any book recommendations as I have got all my info from the web. There are plenty of Arduino books but I have not read any of them. In a bookshop recently I did glance through one large book about Arduino Robots and the code was very poorly structured - i.e. it seemed to have no structure.

...R
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 10, 2014, 01:35 am
Hi Robin2

I admire your knowledge, and of the few of your threads I have read so far, have learned from you.

I am a little disappointed you are having a go at me, you probably have many hundreds of threads, and obviously, I've not read them all.

Ken
Title: Re: Arduino uno R3 stepper motor control
Post by: Robin2 on Nov 10, 2014, 10:27 am
and obviously, I've not read them all.
I was only referring to the replies I have written specially for you.

Perhaps you did read them as I wrote them but as you have never commented on them I have no way of knowing.

...R
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 10, 2014, 12:18 pm
Robin2, fair enough.

I am progressing a little further with my camera slider project. Two weeks ago I had never heard of Arduino or Adafruit products.

I came across an Arduino tutorial called MotorKnob describing how to control the stepper motor speed using a potentiometer.

http://arduino.cc/en/Tutorial/MotorKnob

This I will use. All I need to find out now is where to wire in a 3 position switch for forward, stop and reverse,
and some lines of code.

Just out of curiosity, does it make any difference which order the lines of code are in?

Lots more reading to do.

Ken

Title: Re: Arduino uno R3 stepper motor control
Post by: Robin2 on Nov 10, 2014, 05:04 pm
Just out of curiosity, does it make any difference which order the lines of code are in?
The order of the code is one of the most important things.

Computers are stupid. They do things that you tell them in the order you tell them - even if what you tell them is wrong.


Quote
Two weeks ago I had never heard of Arduino
If the stuff I have written is too complex for your current level of knowledge you need to tell me and I will be happy to try to explain. But don't just ignore it. 

...R
Title: Re: Arduino uno R3 stepper motor control
Post by: JimboZA on Nov 10, 2014, 05:25 pm
Imagine you were driving your car down the road and were about to make a turn- you have to do two things: judge if it's time to turn, and if it is, turn. (Ok three things- if it's not time to turn, don't.) Rinse and repeat that sequence of look/decide; look/decide.

The sequence is important, since it would be crazy to decide to turn before you had looked to see if you were at the crossing. Well the Arduino is dumber than soup until you give it some instructions, and it will decide then look if that's the order you code the instructions.

You may find it beneficial to look up flowcharting to help you model the program conceptually.... it's a bit old school and there are newer ways to model things, but nevertheless it's a good way of getting the sequence of steps, the algorithm, clear in your mind.
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 11, 2014, 03:04 am
JimboZA, thanks for your advice.

Robin2, you put the words in my mouth, I am not ignoring your input, just having trouble understanding all of it.

If you had the time to look at my project and write a tutorial for dummies, I'm sure a lot of readers would benefit greatly from your knowledge. I still can't find where to place switches and write code for them to control direction of the stepper motor.

I'm over 70 and venturing into the Arduino world is totally new for me, always up for a challenge.

I am a retired product designer and have always had an interest in mechanical and electronic things.

My first Arduino uno R3 board arrived today, my godfather, it's so small, I did not realise.

Time to start playing with some very easy examples from the Arduino library starting with "blink"

Ken
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 11, 2014, 07:27 am
I don't seem to be able to get past first base.

As mentioned earlier, my Arduino board arrived today, so decided to try the "blink" example.

I reckon I've done everything correctly, but it's not doing what it's supposed to do. The green led is on all the time and the orange led is blinking at a constant rate of two blinks per second.

Windows reports all the drivers are installed and working correctly.

I have selected com3 port.

I've tried changing the time delay and it makes no difference.

Any clues?

Ken
Title: Re: Arduino uno R3 stepper motor control
Post by: JimboZA on Nov 11, 2014, 09:14 am
Ugggghhhh.

What message do you get when you hit the Upload button?- it should say "done uploading" and give you a message about the sketch size.
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 11, 2014, 09:37 am
Hi JimboZA,

Yes I get the message that the sketch has uploaded telling me that 1,082 bytes have been uploaded.

Should I try different ports, any other suggestions?

Definitely have the correct board selected, uno.

Ken
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 11, 2014, 09:50 am
Eureka, it works.

I don't know what I did, but it just started to blink slowly. I changed the delay time, and it responded.

Now onto the next exercises, this is going to be fun. I feel like a kid in the candy shop.

Ken

Title: Re: Arduino uno R3 stepper motor control
Post by: JimboZA on Nov 11, 2014, 10:02 am
If the IDE says it uploaded I'd be inclined to believe it, but did the Tx and Rx lights flicker during the upload?

You could edit these lines into setup() and view the output in the serial monitor. Open the serial monitor with Tools > Serial Monitor, or Ctrl-Shift-M, or hit the icon top right. Opening the monitor resets the board so setup runs again.

Code: [Select]

Serial.begin(9600);
Serial.println("Hello, World");


If you get this output then you would know it uploaded and is running.
Title: Re: Arduino uno R3 stepper motor control
Post by: JimboZA on Nov 11, 2014, 10:03 am
Ah ok, glad that it works.
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 11, 2014, 12:15 pm
This may be a dumb question, but.....

Looking through some of the Arduino examples, I see there is a facility to copy the code (sketch)

When I hit this dialogue box, nothing seems to happen. I'm using Windows7 and as far as I know, the clipboard function has been dropped, so where do I recover the sketch file from?

Ken
Title: Re: Arduino uno R3 stepper motor control
Post by: Robin2 on Nov 11, 2014, 02:37 pm
I feel like a kid in the candy shop
That's great. Now you should spend a bit of time working through some of the Arduino examples so that you learn how code is constructed.

Sorry - I don't use Windows so I don't know exactly where your programs (sketches) are stored. If you click the preferences button in the Arduino IDE I think it tells you.

...R
Title: Re: Arduino uno R3 stepper motor control
Post by: Robin2 on Nov 11, 2014, 08:24 pm
If you had the time to look at my project and write a tutorial for dummies,
If you can write an outline of what the tutorial should cover I will think about it.

...R
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 12, 2014, 03:18 am
Hi Robin2,

Thank you for thinking of writing up a tutorial re control of stepper motors, and in particular, a camera slider. As soon as I have time, I will outline how I think the project should work.

I am working through the Arduino worked examples, firstly "blink" that tests the board, so far so good.

Many thanks in advance,

Ken
Title: Re: Arduino uno R3 stepper motor control
Post by: Robin2 on Nov 12, 2014, 10:16 am
control of stepper motors, and in particular, a camera slider
This is a common subject on the Forum. Have you searched for other Threads on the subject. Use Google - for example camera slider site:arduino.cc

...R
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 12, 2014, 11:10 am
Hi Robyn2,

I have searched for other camera slider projects, and to me, they seem quite complex. They probably aren't that complicated, just to my inexperienced brain.

I'm going to use the same hardware as this one  http://computers.tutsplus.com/tutorials/motion-control-with-arduino-motorising-a-camera-slider--cms-21539

HARDWARE

For me I just want a track fitted with a carriage, all openbuild stuff. At one end a nema17 stepper motor, the other, an idler pulley. The carriage will be driven forwards and backwards with a toothed belt.

ELECTRONICS

I would like to use an Arduino uno R3 board fitted with an Adafruit stepper motor controller.
A 3-position switch, or two pushbuttons, will drive the carriage in one direction or the other until a limit switch is triggered. A potentiometer will control speed.

With the 3-position switch midway, no power will be sent to the motor and the carriage can be pushed to one end or the other.

That's about it unless someone can suggest some improvements.

The whole kit and caboodle will be used in the field, and hence, be powered by a decent 12v battery.

AFTER THOUGHT

I'm just wondering whether the carriage should stop when a shot is being taken.

I have no idea how this could be done.

Ken

Title: Re: Arduino uno R3 stepper motor control
Post by: Robin2 on Nov 12, 2014, 12:40 pm
I have no idea how this could be done.
This is the problem. I can try to help you sort out how to do things but you have to have something that forms the basis for a question.

What you have described seems eminently feasible. Are you confident that you can do the mechanical construction?

One of the links I gave you earlier has code to make a stepper move back and forth in response to push buttons.

Most stepper drivers have ENABLE pins which you can activate to de-power the motor to allow it to freewheel.

Stepper motors are inefficient. I hope you are planning for a big 12v battery.

...R
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 12, 2014, 01:25 pm
Hi Robin2,

I wont have any trouble with the mechanical side of things, I've tinkered with mechanical things all my life.

Lets forget about stopping the carriage whilst a shot is taken. I can't see that it will make much difference. I'm not a photographer, this project is for my son who's right into it.

Help with driving the carriage forwards and backwards at variable speeds, would be appreciated.

I shall look back through some of your replies to look for stepper motor control ideas.

Thanks,

Ken
Title: Re: Arduino uno R3 stepper motor control
Post by: Robin2 on Nov 12, 2014, 05:02 pm
I shall look back through some of your replies to look for stepper motor control ideas.
Sorry to keep on about it, but maybe now you can understand why I am a little frustrated that you did not take account my replies when they were new.

If you study the code I have written you should understand how different speeds are achieved by changing the interval between steps.

...R
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 13, 2014, 01:00 am
Hi Robin2,

I'm the one who's frustrated, I haven't learned how to read a sketch if there are few comments.

With respect to your thread "Simple Stepper Program" it's all double dutch to me.

For starters there's no comments to say what each step is doing, and no schematic diagram.

Without any knowledge, I'm lost as mentioned earlier.

This is why I'm asking for a tutorial that even a dummy like me can follow.

Ken
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 13, 2014, 07:44 am
Hi Robin2,

All of the above but delete the Adafruit stepper motor controller and substitute it for the
Easy driver board, cheaper option I think.

Ken
Title: Re: Arduino uno R3 stepper motor control
Post by: Robin2 on Nov 13, 2014, 11:14 am
I am using the Pololu A4988 (http://www.pololu.com/product/1182) stepper drivers. That web page has a lot of useful information including a wiring diagram.

I wrote my Simple Stepper Program (http://forum.arduino.cc/index.php?topic=277692) Thread for people who already have a basic understanding of stepper motors. Wikipedia has a good info.

By the way I have just realized that instead of 2 separate programs in that Thread I had repeated the first program (nobody seems to have noticed). I have now corrected that and I hope that has not been the cause of your confusion. Feel free to slap my wrist.

I don't think I can provide a teaching-from-nothing introduction. In any case it would just be duplicating info that is widely available elsewhere.

I wrote my demo code with what I hope are meaningful names for variables rather than comments. I hope they make sense for someone who already knows the general concept of stepper motors.

Writing in the Forum is necessarily different from a face-to-face experience where either or us can instantly interrupt the other if we don't understand something.

If you want to point out specific items in my code I will be happy to try to explain further.

...R
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 14, 2014, 03:42 am
Hi Robyn2

Sounds like you have have pulled the pin on helping me.

With respect to your Simple Stepper Program, any chance you could include a wiring/schematic diagram?

From just the code, I can't tell how you control the motor ie, is it push button control for direction or software control. Is there a motor reversal routine in your code?

Ken
Title: Re: Arduino uno R3 stepper motor control
Post by: Robin2 on Nov 14, 2014, 01:18 pm
Sounds like you have have pulled the pin on helping me.
I'm not sure if you mean I am doing more or less?  Which would you prefer?

Quote
With respect to your Simple Stepper Program, any chance you could include a wiring/schematic diagram?
have you looked at the diagram on the Pololu page I gave you a link for?

Quote
From just the code, I can't tell how you control the motor ie, is it push button control for direction or software control. Is there a motor reversal routine in your code?
I don't know how to answer this. I'm quite sure you realize there is code to make the motor go in both directions - even if you can't identify where it is.

I can't help feeling that the problem is your lack of background knowledge about the basics of stepper motors and stepper motor drivers. There is loads of information on the web about that and I am not going to write duplicate stuff. I already suggested Wikipedia.

And, as I already mentioned, the Pololu page has a lot of info.

It would be much easier to help if you were asking questions like "I was reading BBB and it says XXXX in paragraph NN and I don't understand what it means".

...R
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 15, 2014, 04:58 am
Hi Robyn2,

Thanks for all your help, though it's a pity a schematic is not forth coming for your easy stepper motor.

My lack of understanding is a problem, however, a series of tutorials has helped me a bit with the code.

http://www.youtube.com/watch?v=fsMg6F6yYlo

I will go back over the driver board details you prefer.

Ken
Title: Re: Arduino uno R3 stepper motor control
Post by: JimboZA on Nov 15, 2014, 06:43 am
it's a pity a schematic is not forth coming for your easy stepper motor.
Well, there actually is one: it's on the link to the Pololu driver that Rob(with an "i" not a "y")n2 gave earlier. It shows exactly how to set it up, except it doesn't explicitly say Arduino since it's correct for any micro.

The 4988's input "step" and "dir" pins are called "stepPin" and "directionPin" as outputs in Robin2's sketch. The whole thing happens in software:

stepPin in pulsed HIGH/LOW for numberOfSteps, one sequence with directionPin as HIGH (= one direction) and another full sequence with directionPin LOW (= the other direction).

Why don't you give yourself a challenge, and see if you could rig a simple switch (say directionSwitch), whose value (HIGH or LOW) is then used as a flag for direction, so that you could output a HIGH or LOW in directionPin based on what you read from directionSwitch.
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 15, 2014, 07:51 am
Hi JimboZA,

Thanks for correcting my spelling of Robin2. 

With respect to the rest of your challenge, I'm not yet up to the stage of writing code, just beginning to get the gist of sketches via tutorials.

I have on order an Easy Driver board, hasn't arrived as yet. Have found a tutorial where speed and direction of a stepper motor is addressed plus wiring diagram. Have the Arduino uno R3 board and have been having a play.

Amazing piece of hardware.

Ken
Title: Re: Arduino uno R3 stepper motor control
Post by: Robin2 on Nov 15, 2014, 10:33 am
Have found a tutorial where speed and direction of a stepper motor is addressed plus wiring diagram.
Please post a link to it so I can learn the deficiencies in mine.

...R
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 15, 2014, 11:02 am
Hi Robin2,

I wouldn't say there are any deficiencies in your thread, it's all at this end.

I found this tutorial re Arduino and EasyDriver employing 3 push buttons for forward, stop and reverse plus potentiometer for speed on the fly. Included also is a schematic diagram.

http://www.schmalzhaus.com/EasyDriver/Examples/EasyDriverExamples.html

Ken
Title: Re: Arduino uno R3 stepper motor control
Post by: JimboZA on Nov 15, 2014, 12:17 pm
With respect to the rest of your challenge, I'm not yet up to the stage of writing code, just beginning to get the gist of sketches via tutorials.
Well you have to start sometime! And if you have the Uno and a couple of led/resistor pairs, you can sort of mimic the direction thing. Read a switch (which if you don't have one can simply be a wire from an i/o pin which is either jabbed into a GND hole or not), and if the result is HIGH switch on led #1 and if it's LOW switch on a different one.

Or, if you like, draw a flow chart of the logic of what you want to do and code it in pseudo-code. Pseudo code is just words that you make up, which should reflect what you want to do, but needn't be correct in terms of the programming language's rules. So you could say something like:

read switchPin
if switchPin is high-
    set led1Pin high
    set led2Pin low.
otherwise-
    set led1Pin low
    set led2Pin high.
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 15, 2014, 12:53 pm
Hi JimboZA,

Your words make it sound so simple. It's a pity that the code for the Arduino is not written in english or basic.

How about some code to reflect your english steps?

Ken
Title: Re: Arduino uno R3 stepper motor control
Post by: JimboZA on Nov 15, 2014, 01:14 pm
Give it a bash yourself.

If you don't feel confident running it in case you pop something, at least type it up and see if it compiles. Compile only, with no upload, poses no danger the Uno. That way you'll know it's grammatically correct even if it falls over on the logic. Then post that and let someone here comment.

But here's some clues with no code, since I really think you'll benefit from trying to write it yourself.

Start with the BareMinimum sketch which gives you a skeleton setup() and loop(). Above setup() define any variables you would like to name. You might for instance decide to have one LED on pin 5 so you could use byte (http://arduino.cc/en/Reference/Byte) to set say myLedPin1 to be 5. Same for another led on a different pin, and ditto the switch.

Then in setup() use pinMode (http://arduino.cc/en/Reference/PinMode) to set those leds' pins as outputs and the switch one as an input with pullup resistors.

In loop, use digitalRead (http://arduino.cc/en/Reference/DigitalRead) to read the switch and digitalWrite (http://arduino.cc/en/Reference/DigitalWrite) inside an if / else (http://arduino.cc/en/Reference/Else) to conditionally turn on the LEDs.

Time to get your feet wet, methinks: but as I say if you want comment before you hook stuff up, that's cool. At least get to the stage of sorting out compile errors like if you type "PinMode" when it should be "pinMode", for instance.
Title: Re: Arduino uno R3 stepper motor control
Post by: JimboZA on Nov 15, 2014, 01:45 pm
ps.... you would also want to declare a variable to hold the result of your digitalRead, and use that value (say mySwitchVal) in the test of the if/else.

I am writing a short sketch to do this as we speak, but I'm reluctant to post it until you go first  8)
Title: Re: Arduino uno R3 stepper motor control
Post by: Robin2 on Nov 15, 2014, 02:01 pm
I found this tutorial re Arduino and EasyDriver employing 3 push buttons for forward, stop and reverse plus potentiometer for speed on the fly. Included also is a schematic diagram.
I'm delighted you have found something that works for you.

But, to be honest, I don't understand how the link you gave is any different from the combination of my code and the diagram on the Pololu A4988 (http://www.pololu.com/product/1182) page.

And I guess my frustration has been my inability to find the key that would help me to bridge whatever gap exists between what I write and your understanding of what I write. I suppose I expect people who don't understand to respond with lots of questions that illustrate that gap - and you will have noticed from earlier posts that for a long time I was not even sure if you had read my stuff.

...R
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 16, 2014, 05:15 am
Hi Robin2,

I need to be hand fed at this stage until I'm up to speed. The tutorial I linked to shows the code and a pictorial diagram that I can relate to. 

http://www.schmalzhaus.com/EasyDriver/Examples/EasyDriverExamples.html

Your link to the Polou A4988 shows a schematic only, no code.

I wouldn't know how to hook your board up to an Arduino, and how to control direction and speed.

I haven't reached that level of knowledge yet. I'm ploughing through as many tutorials as I can find, it seems to be the only way to learn.
Title: Re: Arduino uno R3 stepper motor control
Post by: JimboZA on Nov 16, 2014, 05:45 am
I vividly remember the two days years ago when I let go of the saddle on my kids' bikes and all of a sudden they could ride a two-wheeler with no fairy wheels. But I was still jogging behind just for in case.....

I'm pretty sure you remember those days too neksmerj, yet you seem reluctant to let go of your own saddle so to speak.

My advice: try to write the code as I suggested a few posts ago, to get (and this is merely a suggestion) one or other led on when a switch is pressed or not. Post it here by all means for comment, but the time has come where you have to do that.

Quote
I'm ploughing through as many tutorials as I can find, it seems to be the only way to learn.
There's only one way to find out what you have learned, and that's to try a sketch. Right now, you're like Sheldon in TBBT when he said he learned to swim on the floor of the apartment.
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 16, 2014, 06:13 am
JimboZA,

I have set up a bread board with 4 leds to represent the 4 windings of a stepper motor.
Each led is connected via resistors to the Arduino board to pins 8, 9, 10 and 11.

Credit goes to David Cuartielles for a very basic program that cycles through each led with a pause in between.

To take it from here, I would like to be able to vary the speed with a pot, and be able to reverse the direction.

His cut down code is here

int motorPin1 = 8;
int motorPin2 = 9;
int motorPin3 = 10;
int motorPin4 = 11;
int delayTime = 500;

void setup() {
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
}

void loop() {
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
  delay(delayTime);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
  delay(delayTime);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, LOW);
  delay(delayTime);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, HIGH);
  delay(delayTime);
}
 This I can follow without much trouble.

I have fallen off my bike many times, but that was a long, long time ago........

Ken
Title: Re: Arduino uno R3 stepper motor control
Post by: JimboZA on Nov 16, 2014, 06:32 am
This I can follow this without much trouble.

To take it from here, I would like to be able to vary the speed with a pot, and be able to reverse the direction.
Well taking the speed thing first, have you looked at this (http://arduino.cc/en/Tutorial/AnalogInput)?

And for the direction, you could do what I suggested earlier: run either leg of an if/else based on the switch's value. One leg has the code you have currently in loop(), the other has very similar code but with those highs and lows in the digitalWrites re-jigged to go in the opposite direction.
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 16, 2014, 08:24 am
Hi JimboZA,

Let's see your version of using the if/else statement, I've had my little go.

I've managed to control the speed of the sequential leds using a pot but haven't yet figured how to reverse the sequence.

Ken













Title: Re: Arduino uno R3 stepper motor control
Post by: Robin2 on Nov 16, 2014, 11:06 am
I have set up a bread board with 4 leds to represent the 4 windings of a stepper motor.
Each led is connected via resistors to the Arduino board to pins 8, 9, 10 and 11.

Sorry -  but this is sheer folly.

Your Arduino will NOT be connecting to motor coils. That is the job of the stepper driver. You have no need to know what goes on inside the stepper driver.

The Arduino just needs to control the stepper driver by setting the direction pin for Clockwise or CounterClockwise and producing a pulse on the step pin whenever you want the motor to move one step in the selected direction.

This is what my code has been illustrating all along. My first simple code is deliberately very simple. I think part of the "cycling without stabilizers experience" is just to sit down and study my code (100 times if necessary) until you do understand it. And ask as many "stupid" questions about it as you like. Learning the code will also help you to learn about stepper motors.

...R
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 16, 2014, 11:35 am
Oh dear oh dear Robin2,

Now I'm wondering whether you have read the above threads/posts etc.

I fully realise that in the real world a stepper motor will require a stepper motor board, and the code will be different.

The above excercise was a challenge started by JimboZA to simply simulate a stepper using leds run straight off the Arduino board.

Ken
Title: Re: Arduino uno R3 stepper motor control
Post by: JimboZA on Nov 16, 2014, 12:34 pm
Ken-

Let's see your version of using the if/else statement, I've had my little go.
My code from yesterday looks like the below: two leds and a switch, as shown in the attached schematic.

Code: [Select]
//read a switch and if it's high,
//    put a led on. If it's low,
//    put a different led on instead.
//LEDs are on pins 5 and 6, with the anodes
//    to 5V and cathodes to the pins. So, the
//    leds come on when their i/o pins are low
//The switch is on pin 10 with pullup enabled,
//    so pin 10 is usually high but goes low
//    when the switch is pushed.
//Serial is enabled and the value of the pin
//    is shown in the monitor each time thru loop()

byte ledOne=5; // a byte is the smallest type that can store a number
byte ledTwo=6;
byte mySwitch = 10;
bool mySwitchVal; // it can only be on or off so bool is cool


void setup() {
 Serial.begin(9600);
 pinMode(ledOne, OUTPUT);
 pinMode(ledTwo, OUTPUT);
 pinMode(mySwitch, INPUT_PULLUP);

}

void loop() {
mySwitchVal= digitalRead(mySwitch);
Serial.println(mySwitchVal);

if (mySwitchVal == 1)  // note the == not just a =
{
 digitalWrite(ledOne, HIGH);
 digitalWrite(ledTwo, LOW);
}
else // if not 1, it must be 0
{
 digitalWrite(ledOne, LOW);
 digitalWrite(ledTwo, HIGH);
}

}
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 16, 2014, 01:33 pm
Thanks JimboZA,

At my next opportunity, ie, daylight, I'll whack your code in and see what it does, looks interesting.

Ken
Title: Re: Arduino uno R3 stepper motor control
Post by: Robin2 on Nov 16, 2014, 03:02 pm
Oh dear oh dear Robin2,

Now I'm wondering whether you have read the above threads/posts etc.
I've put a lot into this. Now, and I'm out of here.

@KenF I hope your patience is more elastic than mine.

...R
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 18, 2014, 09:41 am
For no apparent reason, the port comm3 has changed to comm1, and sample sketches that were running ok, now don't.

Under the "Tools" menu, comm1 appears with no provision to change it to comm3.

When I first started to play with the Arduino, I had the choice, not now.

Any clues?

Ken

edit, looking at device manager, and clicking on Ports (com & lpt)
Arduino uno reports com3

When trying to run a sketch, the bottom dialogue box reports com1.

The sketch compiles but will not run
Title: Re: Arduino uno R3 stepper motor control
Post by: neksmerj on Nov 18, 2014, 11:50 pm
I accidentally found a fix. In Device Manager, I uninstalled Arduino UNO com1 port, then plugged my Arduio UNO board in.

Device manager then found the board and assigned com3 to it.

I uploaded the sketch, and it failed saying "could not find port com1, try another port", so I selected com3 and wallah.

Ken