Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:37 24 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Stepper Motor

     Page 2 of 3    
Author Message
BobDevries

Senior Member

Joined: 08/06/2011
Location: Australia
Posts: 266
Posted: 09:31pm 05 Oct 2011
Copy link to clipboard 
Print this post

Martin,

there's an error in my code at line 96 (second code post)

It *should* read:


96 I$=INKEY$:IF I$="" THEN 100


Otherwise, the code will never respond to the key presses.

Regards,
Bob Devries
Dalby, QLD, Australia
 
heppy36

Regular Member

Joined: 29/07/2011
Location: Australia
Posts: 54
Posted: 09:36pm 05 Oct 2011
Copy link to clipboard 
Print this post

Try here
http://www.ebay.com.au/sch/ge-th2009/m.html?_nkw=&_armrs=1&_ from=&_ipg=25&_trksid=p3686

He has a ebay shop ge-th2009 only cost $7.50 and they seem to work fine,seems to have a lot of good stuff.
I thought it was simlar to the silcon chip ,but then found there code was wrong.
Martin
Heppy
 
BobDevries

Senior Member

Joined: 08/06/2011
Location: Australia
Posts: 266
Posted: 09:37pm 05 Oct 2011
Copy link to clipboard 
Print this post

The original SC article mentioned that it used a Jaycar part:

Jaycar stepper motor

Regards,
Bob Devries
Dalby, QLD, Australia
 
heppy36

Regular Member

Joined: 29/07/2011
Location: Australia
Posts: 54
Posted: 09:44pm 05 Oct 2011
Copy link to clipboard 
Print this post

Thanks Bob ,I will try it all tonight
Heppy
 
BobDevries

Senior Member

Joined: 08/06/2011
Location: Australia
Posts: 266
Posted: 07:40am 06 Oct 2011
Copy link to clipboard 
Print this post

Martin,

Here's the code as it stands now, just cleaned up and renumbered.


10 DIM A$(3)
20 MAX=100
30 CW=0:REM CW=1 for CCW rotation
40 SETPIN 15,8:SETPIN 16,8:SETPIN 17,8:SETPIN 18,8
50 DATA "0110","0101","1001","1010"
60 FOR X=0 TO 3:READ A$(X):NEXT X
70 DO
80 IF CW=0 THEN 90 ELSE 110:REM CW=0 for clockwise, non-zero for CCW rotation
90 FOR STP=0 TO 3
100 GOTO 120
110 FOR STP=3 TO 0 STEP -1
120 FOR Y=0 TO 3
130 PIN(Y+1)=VAL(MID$(A$(STP),Y+1,1))
140 NEXT Y
150 PAUSE 5: REM increase PAUSE value to SLOW rotation.
160 I$=INKEY$:IF I$="" THEN 210
170 IF I$="Q" OR I$="q" THEN PRINT"STOPPED":END
180 IF I$="R" OR I$="r" THEN CW=NOT(CW):PRINT"REVERSE"
190 IF I$="F" OR I$="f" THEN PRINT"FASTER":DLY=DLY - 1: IF DLY<0 THEN DLY=0
200 IF I$="S" OR I$="s" THEN PRINT"SLOWER":DLY=DLY+1: IF DLY>MAX THEN DLY=MAX
210 NEXT STP
220 LOOP


Regards,
Bob Devries
Dalby, QLD, Australia
 
heppy36

Regular Member

Joined: 29/07/2011
Location: Australia
Posts: 54
Posted: 08:19am 06 Oct 2011
Copy link to clipboard 
Print this post

Hi your first code
10 DIM A$(3)
20 SETPIN 1,8:SETPIN 2,8:SETPIN 3,8:SETPIN 4,8
30 DATA "0110","0101","1001","1010"
40 FOR X=0 TO 3:READ A$(x):NEXT X
50 DO
60 FOR STP=0 TO 3
70 FOR Y=0 TO 3
80 PIN(Y+1)=VAL(MID$(A$(STP),Y+1,1))
90 NEXT Y
100 NEXT STP
110 LOOP
rotates CW realy fast,

the new one
10 DIM A$(3)
20 MAX=100
30 CW=0:REM CW=1 for CCW rotation
40 SETPIN 15,8:SETPIN 16,8:SETPIN 17,8:SETPIN 18,8
50 DATA "0110","0101","1001","1010"
60 FOR X=0 TO 3:READ A$(X):NEXT X
70 DO
80 IF CW=0 THEN 90 ELSE 110:REM CW=0 for clockwise, non-zero for CCW rotation
90 FOR STP=0 TO 3
100 GOTO 120
110 FOR STP=3 TO 0 STEP -1
120 FOR Y=0 TO 3
130 PIN(Y+1)=VAL(MID$(A$(STP),Y+1,1))
140 NEXT Y
150 PAUSE 5: REM increase PAUSE value to SLOW rotation.
160 I$=INKEY$:IF I$="" THEN 210
170 IF I$="Q" OR I$="q" THEN PRINT"STOPPED":END
180 IF I$="R" OR I$="r" THEN CW=NOT(CW):PRINT"REVERSE"
190 IF I$="F" OR I$="f" THEN PRINT"FASTER":DLY=DLY - 1: IF DLY<0 THEN DLY=0
200 IF I$="S" OR I$="s" THEN PRINT"SLOWER":DLY=DLY+1: IF DLY>MAX THEN DLY=MAX
210 NEXT STP
220 LOOP
goes CCW slow?
should I decare DLY as it doesn,t slow it or speed it up,shouldn't it change the pause value so how?
Thanks Again Martin
Heppy
 
BobDevries

Senior Member

Joined: 08/06/2011
Location: Australia
Posts: 266
Posted: 08:42am 06 Oct 2011
Copy link to clipboard 
Print this post

Hi Martin,

OOPS, my bad...
Change line 20 to:

20 MAX=100: DLY=5


and line 150 to:

150 PAUSE DLY: REM increase PAUSE value to SLOW rotation.


Hope that helps.

Regards,
Bob Devries
Dalby, QLD, Australia
 
heppy36

Regular Member

Joined: 29/07/2011
Location: Australia
Posts: 54
Posted: 09:04am 06 Oct 2011
Copy link to clipboard 
Print this post

Cheers That works Great!,its funny if you keep pushing F and make it faster it gets to a point and changes direction?
Thanks Bob,I bought two of them and I intend to make something for my kids!!they like to be dazzaled

Heppy
 
BobDevries

Senior Member

Joined: 08/06/2011
Location: Australia
Posts: 266
Posted: 09:19am 06 Oct 2011
Copy link to clipboard 
Print this post

Hi Martin,

I can't see how the stepper would change direction by getting faster. The value of DLY should go to 0 and stay there. I can't see a problem with my code (but that doesn't mean there's no problem...). Could it be a hardware thing? Dunno....

Regards,
Bob Devries
Dalby, QLD, Australia
 
BobDevries

Senior Member

Joined: 08/06/2011
Location: Australia
Posts: 266
Posted: 09:21am 06 Oct 2011
Copy link to clipboard 
Print this post

I'll have to dig around in my shed to see if I still have some stepper motors so I can try this myself.

Regards,
Bob Devries
Dalby, QLD, Australia
 
BobDevries

Senior Member

Joined: 08/06/2011
Location: Australia
Posts: 266
Posted: 09:28am 06 Oct 2011
Copy link to clipboard 
Print this post

Hmm, I see another error.....

Line 130 should read:


130 PIN(Y+15)=VAL(MID$(A$(STP),Y+1,1))


I can't see how that line worked at all???

Regards,
Bob Devries
Dalby, QLD, Australia
 
BobDevries

Senior Member

Joined: 08/06/2011
Location: Australia
Posts: 266
Posted: 09:30am 06 Oct 2011
Copy link to clipboard 
Print this post

That last modification is only valid if you're still using PINs 15, 16, 17, 18. As it was, the programme was driving PINs 1, 2, 3, 4.

Dunno how I missed that one.

Regards,
Bob Devries
Dalby, QLD, Australia
 
heppy36

Regular Member

Joined: 29/07/2011
Location: Australia
Posts: 54
Posted: 09:33am 06 Oct 2011
Copy link to clipboard 
Print this post

I went to 1234 as you first wrote and have been changing the value using 1234,seemed neater?
Heppy
 
BobDevries

Senior Member

Joined: 08/06/2011
Location: Australia
Posts: 266
Posted: 09:35am 06 Oct 2011
Copy link to clipboard 
Print this post

Ah, ok, Martin.

Then please ignore my previous two posts.

Regards,
Bob Devries
Dalby, QLD, Australia
 
BobDevries

Senior Member

Joined: 08/06/2011
Location: Australia
Posts: 266
Posted: 09:39am 06 Oct 2011
Copy link to clipboard 
Print this post

As you can see though, as long as you use sequential pins, you can easily use *any* 4 pins. If you were to use non-sequential pins, the programme would be more complex.

As you say, it's neater this way.

I'm happy it's working for you.

Regards,
Bob Devries
Dalby, QLD, Australia
 
BobDevries

Senior Member

Joined: 08/06/2011
Location: Australia
Posts: 266
Posted: 12:01am 07 Oct 2011
Copy link to clipboard 
Print this post

Hi Martin,
I had another think about using non-sequential pin numbers to drive the stepper motor, and adjusted the programme to suit:


10 DIM A$(3):DIM PN(3)
20 MAX=100:DLY=5:REM adjust to taste
30 CW=0:REM CW=1 for CCW rotation. Set to 1 or 0 depending on which direction to start in
40 FOR X=0 TO 3:READ PN(X):NEXT X:REM read which pin numbers to use into array PN()
50 DATA 15,16,17,18: REM PIN numbers used to drive stepper motor
60 FOR X=0 TO 3:SETPIN PN(X),8:NEXT X:REM set pins in PN() array to digital output
70 DATA "0110","0101","1001","1010":REM codes to drive pins on or off
80 FOR X=0 TO 3:READ A$(X):NEXT X:REM read codes into string array A$()
90 DO:REM main loop
100 IF CW=0 THEN 110 ELSE 130:REM CW=0 for clockwise, non-zero for CCW rotation
110 FOR STP=0 TO 3:REM there are 4 steps to do; refer line 70
120 GOTO 140
130 FOR STP=3 TO 0 STEP -1:REM as for line 110 but reverse direction
140 FOR Y=0 TO 3
150 PIN(PN(Y))=VAL(MID$(A$(STP),Y+1,1)):REM extract binary 0 or 1 from a$() array element
160 NEXT Y
170 PAUSE DLY: REM increase PAUSE value to SLOW rotation.
180 I$=INKEY$:IF I$="" THEN 230:REM read keypress
190 IF I$="Q" OR I$="q" THEN PRINT"STOPPED":END
200 IF I$="R" OR I$="r" THEN CW=NOT(CW):PRINT"REVERSE"
210 IF I$="F" OR I$="f" THEN PRINT"FASTER":DLY=DLY - 1: IF DLY<0 THEN DLY=0
220 IF I$="S" OR I$="s" THEN PRINT"SLOWER":DLY=DLY+1: IF DLY>MAX THEN DLY=MAX
230 NEXT STP:REM next step loop
240 LOOP:REM end of main loop


I also put in some comments to help you understand how it works.
You can change the pin numbers at line 50.

Regards,
Bob Devries
Dalby, QLD, Australia
 
heppy36

Regular Member

Joined: 29/07/2011
Location: Australia
Posts: 54
Posted: 08:28am 07 Oct 2011
Copy link to clipboard 
Print this post

Thanks Bob,I think its a hardware thing,as I go faster it stops and just vibrates,your very first code is the most powerful and smoothest,I need to increase the voltage to the stepper sometime to keep it from pausing (not sure on the quality of the stepper)
I am starting to understand it a little more,the demo code that come with it looks sequential?
Does it mean anything to you?
Cheers Martin

int i;
int key = 0;
int button = 11;
void motor1()
{
digitalWrite(motorPin[0],LOW);
digitalWrite(motorPin [1],HIGH);
digitalWrite(motorPin [2],HIGH);
digitalWrite(motorPin [3],HIGH);
}
void motor2()
{
digitalWrite(motorPin [0],HIGH);
digitalWrite(motorPin [1],LOW);
digitalWrite(motorPin [2],HIGH);
digitalWrite(motorPin [3],HIGH)

void motor3()
{
digitalWrite(motorPin [0],HIGH);
digitalWrite(motorPin [1],HIGH);
digitalWrite(motorPin [2],LOW);
digitalWrite(motorPin [3],HIGH);
}
void motor4()
{
digitalWrite(motorPin [0],HIGH);
digitalWrite(motorPin [1],HIGH);
digitalWrite(motorPin [2],HIGH);
digitalWrite(motorPin [3],LOW);
}
void motor5()
digitalWrite(motorPin [0],HIGH);
digitalWrite(motorPin [1],HIGH);
digitalWrite(motorPin [2],HIGH);
digitalWrite(motorPin[3],HIGH);
}
void setup()
{
Serial.begin(9600);
for(i=0;i<4;i++)
pinMode(motorPin ,OUTPUT);
pinMode(button,INPUT);
}
void loop()
{
key = digitalRead(button);
if(key==LOW)
{
motor1();
delay(5);
motor2 ();
delay(5);
motor3();
delay(5);
motor4();
Heppy
 
BobDevries

Senior Member

Joined: 08/06/2011
Location: Australia
Posts: 266
Posted: 09:07am 07 Oct 2011
Copy link to clipboard 
Print this post

The code in that you have there appears to be in C, and also is different as far as the steps are concerned. In my code (and the SC article agrees) the steps are:

0110
0101
1001
1010

In the example you displayed, the codes are:

0111
1011
1101
1110
1111

So there's 5 steps, and the values are different. I don't know which steppers this programme is for, however, you could try to modify my code to try it.

You's need to change the FOR/NEXT loop that uses the STP variable so it steps 0 to 4 instead of 0 to 3, and replace the data in line 70 to use the different values. Lines 70, 80, 110 and 130 need to be changed.

If you run into trouble, give me a yell, and I'll see what I can do.

Regards,
Bob Devries
Dalby, QLD, Australia
 
BobDevries

Senior Member

Joined: 08/06/2011
Location: Australia
Posts: 266
Posted: 09:12am 07 Oct 2011
Copy link to clipboard 
Print this post

Martin,

By the way, the line numbers refer to my latest version of the STEPPER.BAS programme.

Regards,
Bob Devries
Dalby, QLD, Australia
 
heppy36

Regular Member

Joined: 29/07/2011
Location: Australia
Posts: 54
Posted: 09:29am 07 Oct 2011
Copy link to clipboard 
Print this post

Thanks Bob I tired
10 DIM A$(4)
20 SETPIN 1,8:SETPIN 2,8:SETPIN 3,8:SETPIN 4,8
30 DATA "0111","1011","1101","1110","1111'
40 FOR X=0 TO 4:READ A$(x):NEXT X
50 DO
60 FOR STP=0 TO 4
70 FOR Y=0 TO 4
80 PIN(Y+1)=VAL(MID$(A$(STP),Y+1,1))
90 NEXT Y
100 NEXT STP
110 LOOP

and it did work,didn't seen very powerful
Cheers
Heppy
 
     Page 2 of 3    
Print this page
© JAQ Software 2024