-->
Page 1 of 2

Stepper motor control

PostPosted: Tue May 17, 2016 7:51 am
by fsae99
Would it be possible to add stepper motor control to ESPBasic?

The Accel version would be nice but even the standard arduino version would be fine.

Regards,
Jim

Re: Stepper motor control

PostPosted: Fri Sep 23, 2016 9:34 am
by Mark_msn_
This code working fine with Stepper motor...

Need connect to pin 15,5,4 and 0 or change to other pins and change to code.

button "Paso" ,[paso1]
wait

[paso1]
For x = 1 to 20
io(po,16,1)
io(po,5,0)
io(po,4,0)
io(po,0,0)
io(po,16,0)
io(po,5,1)
io(po,4,0)
io(po,0,0)
io(po,16,0)
io(po,5,0)
io(po,4,1)
io(po,0,0)
io(po,16,0)
io(po,5,0)
io(po,4,0)
io(po,0,1)
io(po,0,0)
next
wait

Re: Stepper motor control

PostPosted: Fri Sep 23, 2016 4:13 pm
by livetv
I think this depends heavily on how the stepper motor is interfaced. If there is an agreed upon interface, this might make sense.

The code Mark_msn posted seems to energize coils directly (presumably through transistors). This would be very different code than if one was using a stepper motor driver (like the step stick). On an ESP8266, I'd save on GOPIs by using stepsticks. If I wanted to drive several stepper motors I'd multiplex the direction and step lines (plus an enable signal on another MUX that needs no GPIO). Just off the top of my head, driving 8 stepper motors might hook up this way:

4 - direction
5 - step
12 - MUX bit 0
13 - MUX bit 1
14 - MUX bit 2

Code might look like this:

Code: Select all[moveMotor]
' Variables you meed to set:
'    ID - stepper motor id, 0 to 7
'    DIRECTION - 1 = forward, 0 = reverse
'    STEPS - Number of steps to go
'    STEPDELAY - milliseconds to delay between steps

' Start by setting multiplexers to address the correct stepper motor driver
if id>3 then io(po,14,1) else io(po,14,0)
if (id and 2) >0 then io(po,13,1) else io(po,13,0)
if (id and 1) >0 then io(po,12,1) else io(po,12,0)

' Set direction
io(po,4,direction)

' Perform all requested steps
for stepcount=1 to steps
  io(po,5,1)
  io(po,5,0)
  delay stepdelay
  next stepcounter
return


This is generic code, not taking into account specific requirements of the various dirt cheap stepper motor driver boards out there, but the concept is quite simple and may work with little or no modification. More sophisticated code could move motors simultaneously. How fast would this go? The current speed of the IO() function is about 4ms each. That plus the delay and loop would probably limit you to 100 steps per second at very best. For drivers that do microstepping, this could get a bit slow but It's a fairly easy interface and code for 8 stepper motors!

Re: Stepper motor control

PostPosted: Thu Sep 29, 2016 8:12 pm
by Oldbod
Interesting topic. I tend to think of stepper motors and cnc, but tht's obviously only one aspect. I'm wondering what the context of the request is?