So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Phathak
#75198 Hi,

I'm trying to make this simple project.
http://www.instructables.com/id/Motoriz ... h-ESP8266/

For now, I've not been able to make the motor spin. A colleague told me to replicate it on a breadboard using LEDs instead of the motor itself to see if there was any activity going to the motor. But, all I have is the LEDs lighting up. I would have thought that they would have flickered on and off two at a time to mimic the coils of the motor. I don't understand what's going on.

NodeMCU_LEDs_Test_bb.png


Here's the code on the ESP. The schematic of the breadboard is attached.

Thank you!

init.lua
Code: Select all--init.lua<br>--
dofile('stepper.lua')
--
FWD=1
REV=-1
--
ROTATION_FULL=4096 --One revolution, 28BYJ-48 geared stepper motor
ROTATION_HALF=ROTATION_FULL / 2
FEW_STEPS=10
--
step_move(FEW_STEPS,FWD,1)
tmr.register(0, 5000, tmr.ALARM_SINGLE, function()
    step_move(FEW_STEPS,REV,1)
end);
tmr.start(0);



stepper.lua
Code: Select all-- stepper.lua<br>-- code from: http://www.esp8266.com/viewtopic.php?f=19&t=2326
-- simple stepper driver for controlling a stepper motor with a
-- l293d driver
-- nodemcu pins:  0  5  6  7
stepper_pins = {1,3,2,4} -- (A-)blue, (A+)pink, (B-)yellow, (B+)orange
-- half or full stepping
step_states4 = {
 {1,0,0,1},
 {1,1,0,0},
 {0,1,1,0},
 {0,0,1,1}
}
step_states8 = {
 {1,0,0,0},
 {1,1,0,0},
 {0,1,0,0},
 {0,1,1,0},
 {0,0,1,0},
 {0,0,1,1},
 {0,0,0,1},
 {1,0,0,1},
}
step_states = step_states8 -- choose stepping mode
step_numstates = 8 -- change to match number of rows in step_states
step_delay = 20 -- choose speed
step_state = 0 -- updated by step_take-function
step_direction = 1 -- choose step direction -1, 1
step_stepsleft = 0 -- number of steps to move, will de decremented
step_timerid = 4 -- which timer to use for the steps
-- setup pins
for i = 1, 4, 1 do
  gpio.mode(stepper_pins[i],gpio.OUTPUT)
end
-- turn off all pins to let motor rest
function step_stopstate()
  for i = 1, 4, 1 do
    gpio.write(stepper_pins[i], 0)
  end
end
-- make stepper take one step
function step_take()
  -- jump to the next state in the direction, wrap
  step_state = step_state + step_direction
  if step_state > step_numstates then
    step_state = 1;
  elseif step_state < 1 then
    step_state = step_numstates
  end
  -- write the current state to the pins
  for i = 1, 4, 1 do
    gpio.write(stepper_pins[i], step_states[step_state][i])
  end
  -- might take another step after step_delay
  step_stepsleft = step_stepsleft-1
  if step_stepsleft > 0 then
    tmr.alarm(step_timerid, step_delay, 0, step_take )
  else
    step_stopstate()
  end
end
-- public method to start moving number of 'int steps' in 'int direction'
function step_move(steps, direction, delay)
  tmr.stop(step_timerid)
  step_stepsleft = steps
  step_direction = direction
  step_delay = delay
  step_take()
end
-- public method to cancel moving
function step_stop()
  tmr.stop(step_timerid)
  step_stepsleft = 0
  step_stopstate()
end
You do not have the required permissions to view the files attached to this post.