So I create an another program that can run stepper motor nema 34 using leadshine DM860 driver and this is the example of my code:

import time
import pigpio

START_DELAY=580
FINAL_DELAY=480
STEP=1

GPIO=20

pi = pigpio.pi()

pi.set_mode(GPIO, pigpio.OUTPUT)
pi.set_mode(21, pigpio.OUTPUT)
pi.set_mode(26,pigpio.INPUT)
pi.set_mode(16,pigpio.INPUT)
#pi.write(21,1)
pi.wave_clear()

statee = 0
run = True
try:
    while run == True:

        pi.write(21,statee)
        pi.wave_clear()

        wf=[]
        offset = pi.wave_get_micros()
        for delay in range(START_DELAY, FINAL_DELAY, -STEP):
           wf.append(pigpio.pulse(1<<GPIO, 0,       delay))
           wf.append(pigpio.pulse(0,       1<<GPIO, delay))

        for i in range(500):
            wf.append(pigpio.pulse(1<<GPIO, 0,       FINAL_DELAY))
            wf.append(pigpio.pulse(0,       1<<GPIO, FINAL_DELAY))
        wf.append(pigpio.pulse(0, 0, offset))

        for delay in range(FINAL_DELAY, START_DELAY, STEP):
           wf.append(pigpio.pulse(1<<GPIO, 0,       delay))
           wf.append(pigpio.pulse(0,       1<<GPIO, delay))

        pi.wave_add_generic(wf)

        wid2 = pi.wave_create()

        #pi.wave_send_once(wid2)
        pi.wave_send_using_mode(wid2, pigpio.WAVE_MODE_ONE_SHOT_SYNC)

        if pi.read(26) == 0:
            pi.wave_tx_stop()
            run = False
        if pi.read(16) == 0:
            pi.wave_tx_stop()
            run = False

        time.sleep(0.7429)
        if statee == 0:
            statee = 1
        elif statee == 1:
            statee = 0
except KeyboardInterrupt:
    print ("\nCtrl-C pressed.  Stopping PIGPIO and exiting...")
    pi.wave_tx_stop()
    pi.stop()

it run without code error but sometimes the stepper motor when moving got random long delay even I already decrease the value from START_DELAY,FINAL_DELAY, and time.sleep() (with the range between START_DELAY and FINAL_DELAY value is 100 and time.sleep() value depend how smooth movement). And when I use START_DELAY,FINAL_DELAY, and time.sleep() value like the example code (the lowers speed) sometime the raspberry pi got powers cut (stepper motor stop moving and lcd monitor show blank screen wit text 'no signal'). So, is the problem realy cause from my code? I already update pigpiod to v68. Thank You

  • There a reason for that very specific sleep time 0.7429 Seconds? – Chad G Dec 5 at 17:39
  • 1
    @ChadG absolutly smoothing the movement when changing thre direction. minimize the bump when changing the direction. you need a match delay to minimize the bump when changing the direction – Jan sebastian Dec 5 at 17:46

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.