B4R Library rTinyStepper_28BYJ_48 - A library for the 28BYJ_48 stepper motor(s)

Johan Schoeman

Expert
Licensed User
It is a wrap for this Github project. Read the documentation in the provided link to get a clear understanding of how to use/apply this library.

"....This Arduino library is used to control one or more 28BYJ-48 stepper motors. These motors are very small with a built in gear reduction. The advantage of these motors is that they are inexpensive and easily available on Amazon. Their downside is that they're very slow (0.3 revolutions/second max), and only suitable for light-duty applications.

The primary advantage of using this stepper library with the 28BYJ-48 motors is easy control and faster speeds. This is achieved by accelerating and decelerating the motor as they travel to their destination....."


All the methods have popup help.

Methods other than "Initialize":

B4X:
    void connectToPins(byte in1PinNumber, byte in2PinNumber, byte in3PinNumber, byte in4PinNumber);
    void setCurrentPositionInSteps(long currentPositionInSteps);
    long getCurrentPositionInSteps();
    void setupStop();
    void setSpeedInStepsPerSecond(float speedInStepsPerSecond);
    void setAccelerationInStepsPerSecondPerSecond(float accelerationInStepsPerSecondPerSecond);
    void moveRelativeInSteps(long distanceToMoveInSteps);
    void setupRelativeMoveInSteps(long distanceToMoveInSteps);
    void moveToPositionInSteps(long absolutePositionToMoveToInSteps);
    void setupMoveInSteps(long absolutePositionToMoveToInSteps);
    bool motionComplete();
    float getCurrentVelocityInStepsPerSecond();
    bool processMovement(void);
    void disableMotor();
Sure you will know what to do with the attached lib files (folder with files and the xml file)

I am using pins 8, 9, 10, and 11 in the attached project.
B4X:
    ts.connectToPins(8, 9, 10,11)
I believe you can control more than 1 stepper motor at the same time. I don't have more than 1 motor to test with.




20190713_173845.jpg


B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    
    Dim ts As TinyStepper
    Dim t As Timer
    
    Dim sequence As Byte = 0
    Dim completed As Boolean = True
    
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    ts.Initialize
    ts.connectToPins(8, 9, 10,11)
    t.Initialize("t_tick", 200)
    t.Enabled = True
    
End Sub

Sub t_tick

    If sequence = 0 And completed = True Then
        seq0
    End If
    If sequence = 1 And completed = True Then
        seq1
    End If
    If sequence = 2 And completed = True Then
        seq2
    End If
    If sequence = 3 And completed = True Then
        seq3
    End If
    If sequence = 4 And completed = True Then
        seq4
    End If
    If sequence = 5 And completed = True Then
        seq5
    End If
    If sequence = 6 And completed = True Then
        seq6
    End If
    If sequence = 7 And completed = True Then
        seq7
    End If
    If sequence = 8 And completed = True Then
        seq8
    End If
    If sequence = 9 And completed = True Then
        seq9
    End If
    
End Sub

Sub seq0
    
    completed = False
    ts.SpeedInStepsPerSecond = 4096
    ts.AccelerationInStepsPerSecondPerSecond = 512
    ts.CurrentPositionInSteps = 0
    ts.moveToPositionInSteps(1024)
    Log("current position = ", ts.WhatIsCurrentPositionInSteps)
    Delay(2000)
    completed = ts.motionComplete
    sequence = sequence + 1
    
End Sub

Sub seq1
    
    completed = False
    ts.SpeedInStepsPerSecond = 256
    ts.AccelerationInStepsPerSecondPerSecond = 512
    ts.moveToPositionInSteps(0)
    Log("current position = ", ts.WhatIsCurrentPositionInSteps)
    Delay(1000)
    completed = ts.motionComplete
    sequence = sequence + 1
 
End Sub

Sub seq2
    
    completed = False
    ts.SpeedInStepsPerSecond = 200
    ts.AccelerationInStepsPerSecondPerSecond = 1000
    ts.moveRelativeInSteps(-4096)
    Log("current position = ", ts.WhatIsCurrentPositionInSteps)   
    Delay(1000)
    completed = ts.motionComplete
    sequence = sequence + 1
    
End Sub

Sub seq3
    
    completed = False
    ts.SpeedInStepsPerSecond = 500
    ts.AccelerationInStepsPerSecondPerSecond = 1000
    ts.moveRelativeInSteps(4096)
    Log("current position = ", ts.WhatIsCurrentPositionInSteps)
    Delay(2000)
    completed = ts.motionComplete
    sequence = sequence + 1
    
End Sub

Sub seq4
    
    completed = False
    ts.SpeedInStepsPerSecond = 500
    ts.AccelerationInStepsPerSecondPerSecond = 1000
    ts.moveRelativeInSteps(-2048 * 2)
    Log("current position = ", ts.WhatIsCurrentPositionInSteps)
    Delay(2000)
    completed = ts.motionComplete
    sequence = sequence + 1
End Sub

Sub seq5
    
    completed = False
    ts.SpeedInStepsPerSecond = 500
    ts.AccelerationInStepsPerSecondPerSecond = 1000
    ts.moveRelativeInSteps(2048 * 2)
    Log("current position = ", ts.WhatIsCurrentPositionInSteps)
    Delay(2000)
    completed = ts.motionComplete
    sequence = sequence + 1

End Sub

Sub seq6
    
    completed = False
    ts.SpeedInStepsPerSecond = 100
    ts.AccelerationInStepsPerSecondPerSecond = 1000
    ts.moveRelativeInSteps(512)
    Log("current position = ", ts.WhatIsCurrentPositionInSteps)
    Delay(100)
    completed = ts.motionComplete
    sequence = sequence + 1
    
End Sub

Sub seq7
    
    completed = False
    ts.SpeedInStepsPerSecond = 200
    ts.AccelerationInStepsPerSecondPerSecond = 1000
    ts.moveRelativeInSteps(-512)
    Log("current position = ", ts.WhatIsCurrentPositionInSteps)
    Delay(100)
    completed = ts.motionComplete
    sequence = sequence + 1
    
End Sub

Sub seq8
    
    completed = False
    ts.SpeedInStepsPerSecond = 50
    ts.AccelerationInStepsPerSecondPerSecond = 200
    ts.moveRelativeInSteps(-248)
    Log("current position = ", ts.WhatIsCurrentPositionInSteps)
    Delay(100)
    completed = ts.motionComplete
    sequence = sequence + 1
    
End Sub

Sub seq9
    
    completed = False
    ts.SpeedInStepsPerSecond = 40
    ts.AccelerationInStepsPerSecondPerSecond = 100
    ts.moveRelativeInSteps(-248)
    Log("current position = ", ts.WhatIsCurrentPositionInSteps)
    Delay(100)
    completed = ts.motionComplete
    sequence = 0
    
End Sub
 

Attachments

Top