Maker Pro
Maker Pro

Controlling a 28byj-48 stepper motor with picaxe 28x2 chip

Caitlin Sweet

Apr 25, 2017
2
Joined
Apr 25, 2017
Messages
2
Im a sixth form student and am looking for some advice on controlling this stepper motor. I need it to stop in a certain place after spinning but only when a button is pressed. I have got the motor to spin and stop but I cannot work out what bits of the program does what as its from the picaxe stepper motor page so I didn't write it myself. I am really struggling in writing the program as I have never done anything like this before.
Many thanks
 

hevans1944

Hop - AC8NS
Jun 21, 2012
4,878
Joined
Jun 21, 2012
Messages
4,878
Is the code snippet below anything like what you are trying to work with?

Code:
    let dirsB = %00001111            ; make pins output
main:    for b3 = 0 to 99             ; start a for...next loop
      gosub lstep                ; call left step sub-procedure
    next b3                    ; next loop
    for b3 = 0 to 99            ; start a for...next loop
      gosub rstep                ; call right step sub-procedure
    next b3                    ; next loop
    goto main                ; repeat

lstep:    let b1 = b1 + 1                ; add 1 to variable b1
    gosub stepit                ; do the step
    return

rstep:    let b1 = b1 - 1             ; subtract 1 from variable b1
    gosub stepit                ; do the step
    return

stepit:    let b1 = b1 & %00000011         ; mask lower two bits of b1
    lookup b1,(%1010,%1001,%0101,%0110),b2    ; lookup code into b2
    let pinsB = b2                ; output b2 onto control lines
    return

This code, a version of BASIC, was copied from this site, which turned up in a Google search using your title for this thread as a search string.
I am really struggling in writing the program as I have never done anything like this before.
So, what makes you think you are qualified to write code for the PICAXE microprocessor? Did you design and build the hardware interface motor-driver that the PICAXE controls? Do you know how the output bits must be sequenced to make the motor turn clock-wise and counter clock-wise? Can you explain the difference in operation between a bi-polar and a uni-polar stepper? What waveforms will be applied to the stepper motor coils (windings)? How will the current in those coils be controlled?
I need it to stop in a certain place after spinning but only when a button is pressed.
What does "a certain place" mean? How is the motor started spinning, and what determines the direction of rotation? How will you determine when to press a button so the motor will stop in a certain place?

What is the purpose of your project? What is the stepper motor supposed to DO (if anything)?
 

Caitlin Sweet

Apr 25, 2017
2
Joined
Apr 25, 2017
Messages
2
Is the code snippet below anything like what you are trying to work with?

Code:
    let dirsB = %00001111            ; make pins output
main:    for b3 = 0 to 99             ; start a for...next loop
      gosub lstep                ; call left step sub-procedure
    next b3                    ; next loop
    for b3 = 0 to 99            ; start a for...next loop
      gosub rstep                ; call right step sub-procedure
    next b3                    ; next loop
    goto main                ; repeat

lstep:    let b1 = b1 + 1                ; add 1 to variable b1
    gosub stepit                ; do the step
    return

rstep:    let b1 = b1 - 1             ; subtract 1 from variable b1
    gosub stepit                ; do the step
    return

stepit:    let b1 = b1 & %00000011         ; mask lower two bits of b1
    lookup b1,(%1010,%1001,%0101,%0110),b2    ; lookup code into b2
    let pinsB = b2                ; output b2 onto control lines
    return

This code, a version of BASIC, was copied from this site, which turned up in a Google search using your title for this thread as a search string.

So, what makes you think you are qualified to write code for the PICAXE microprocessor? Did you design and build the hardware interface motor-driver that the PICAXE controls? Do you know how the output bits must be sequenced to make the motor turn clock-wise and counter clock-wise? Can you explain the difference in operation between a bi-polar and a uni-polar stepper? What waveforms will be applied to the stepper motor coils (windings)? How will the current in those coils be controlled?

What does "a certain place" mean? How is the motor started spinning, and what determines the direction of rotation? How will you determine when to press a button so the motor will stop in a certain place?

What is the purpose of your project? What is the stepper motor supposed to DO (if anything)?

Thats exactly the code I found, its for my a level design project which is a child toy, its basically showing the child where to look for the missing piece. I need the stepper motor to spin and then point in a certain direction after a button is pressed, different directions for each button (I have 6 buttons). This is the first time I have used this type of electronics and have no idea how to use it and my teacher is also struggling with the program.
 
Top