Nodemcu lua module to help with driving a unipolar stepper motor 28BYJ-48 when using ULN2003 IC
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
LICENSE
README.md
Stepper_Connection_bb.png
stepper.lua
stepper_test.lua

README.md

nodemcu_stepper

Nodemcu(esp8266) lua module to simplify driving a unipolar stepper motor 28BYJ-48 when using ULN2003 Driver. With this module you can drive a stepper motor in 3 lines like this

stepper  = require ('stepper')
stepper.init({5,6,7,8})
stepper.rotate(stepper.FORWARD,2500,5,0,function () print('Rotation done.') end)

As you can see, your code trigger rotate and let the module finish rotation and trigger callback.

Background

I needed a simple lua module (with callbacks) that I can use to drive the cheap 28BYJ-48 & ULN2003 Combo. I did search online around to see if there is a readymade one available. when I couldnt find any exact matches, Just wrote this based on bits and pieces I found online. Hope you find it useful. Feel free create a issue or get in touch with me for any feature requests.

TODO : Insert pic here Fig: 28BYJ-48 & ULN2003 Combo

Here are two good links that helped me understand how to get the stepper working https://www.geeetech.com/wiki/index.php/Stepper_Motor_5V_4-Phase_5-Wire_%26_ULN2003_Driver_Board_for_Arduino http://chilipeppr2.blogspot.in/2016/10/controlling-byj48-stepper-motor-from.html

Download

since this is a single module file, I suggest raw file download for stepper.lua instead of a checkout. this is ment to be used in your project.

Usage

Connections

Any nodemcu gpio pins shoud work. here is the combination that worked for me.

NODEMCU ULN2003
D5 IN1
D6 IN2
D7 IN3
D8 IN4

Alt text

Compilation

THis is a big module. It takes a lot of your esp8266's precious memory. I suggest you compile this in to a .lc file to reduce memory consumption.

Loading module

load the lua module in your main program

stepper  = require ('stepper')

initailization

initialize the module with necessary variables parameters : table with 4 nodemcu pins that are connected to ULN2003, for exmaple, {5,6,7,8} is expected if uln2003 motor driver is connected as mentioned in Connections section.

pins = {5,6,7,8}
stepper.init(pins)

Rotation

Once the initalization is done, you can call rotate method like this. On successfull completion of given rotation the callback you passed as a last parameter will be invoked. Note : this is a async method. It'll trigger rotation and return immediately.

Signature :
rotate( direction, desired_steps, interval, timer_to_use, callback)
Parameters :
Parameter Description
direction stepper.FORWARD or stepper.REVERSE
desired_steps number between 0 to infinity - 2500 is default which is roughly half a rotation
interval time delay in milliseconds between steps, smaller self number is, faster the motor rotates . 5 is default
timer_to_use which nodemcu timer to use, 0 is default
callback _callback to invoke on completion of given rotation
Example :
direction = stepper.FORWARD 
desired_steps = 2500 
interval = 5 
timer_to_use = 0 
stepper.rotate(direction,desired_steps,interval,timer_to_use,function ()
    print('Rotation done. inside callback.')
    -- do some thing useful 
    end)
Full example
stepper  = require ('stepper')
stepper.init({5,6,7,8})
stepper.rotate(stepper.FORWARD,2500,5,0,function () print('Rotation done.') end)