Connect with us

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

Discussion in 'Microcontrollers, Programming and IoT' started by Caitlin Sweet, Apr 25, 2017.

Scroll to continue with content
  1. Caitlin Sweet

    Caitlin Sweet

    Apr 25, 2017
    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
  2. hevans1944

    hevans1944 Hop - AC8NS

    Jun 21, 2012
    Is the code snippet below anything like what you are trying to work with?

        let dirsB = %00001111            ; make pins output
    main:    for b3 = 0 to 99             ; start a loop
          gosub lstep                ; call left step sub-procedure
        next b3                    ; next loop
        for b3 = 0 to 99            ; start a 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
    rstep:    let b1 = b1 - 1             ; subtract 1 from variable b1
        gosub stepit                ; do the step
    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
    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)?
  3. Caitlin Sweet

    Caitlin Sweet

    Apr 25, 2017
    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.
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day