Raspberry Pi Step Motor

Hello All,

I finally got the 28BYJ 5v step motor working on the Raspberry Pi. I’d like some advice on controlling the duration between phases. I’m currently using app.DoEvent(duration) as a delay. Any duration value smaller than 2 and the step motor does not move, I think it has something to do with electromagnetic energizing speed. To improve my coding etiquette should app.DoEvent be replaced with a thread?

Thanks in advance

[code]GPIO.SetupGPIO

//28BYJ 5v Step Motor Pins
Const pin1 = 5
Const pin2 = 13
Const pin3 = 19
Const pin4 = 6

// Set the pin to accept output
GPIO.PinMode(pin1, GPIO.OUTPUT)
GPIO.PinMode(pin2, GPIO.OUTPUT)
GPIO.PinMode(pin3, GPIO.OUTPUT)
GPIO.PinMode(pin4, GPIO.OUTPUT)

// 8 steps for 1 revolutions
for i As integer = 0 to Val(rotation.text)
'step1() = Array(1,0,0,0)
GPIO.DigitalWrite(pin1, GPIO.ON)
GPIO.DigitalWrite(pin4, GPIO.OFF)
App.DoEvents(Val(Duration.text))

'step2() = Array(1,1,0,0)
GPIO.DigitalWrite(pin2, GPIO.ON)
App.DoEvents(Val(Duration.text))

'step3() = Array(0,1,0,0)
GPIO.DigitalWrite(pin1, GPIO.OFF)
App.DoEvents(Val(Duration.text))

'step4() = Array(0,1,1,0)
GPIO.DigitalWrite(pin3, GPIO.ON)
App.DoEvents(Val(Duration.text))

'step5() = Array(0,0,1,0)
GPIO.DigitalWrite(pin2, GPIO.OFF)
App.DoEvents(Val(Duration.text))

'step6() = Array(0,0,1,1)
GPIO.DigitalWrite(pin4, GPIO.ON)
App.DoEvents(Val(Duration.text))

'step7() = Array(0,0,0,1)
GPIO.DigitalWrite(pin3, GPIO.OFF)
App.DoEvents(Val(Duration.text))

'step8() = Array(1,0,0,1)
GPIO.DigitalWrite(pin1, GPIO.ON)
App.DoEvents(Val(Duration.text))
Next

GPIO.DigitalWrite(pin1, GPIO.OFF)
App.DoEvents(1)
GPIO.DigitalWrite(pin2, GPIO.OFF)
App.DoEvents(1)
GPIO.DigitalWrite(pin3, GPIO.OFF)
App.DoEvents(1)
GPIO.DigitalWrite(pin4, GPIO.OFF)
App.DoEvents(1)[/code]

My experience with the 28BYJ is that it doesn’t like pulse widths much less than 8ms, so 2ms is probably not enough. App.doevents is not quite as evil in simple single-thread programs as some say, but a timer may be a better way to go.