584,817 active members*
4,742 visitors online*
Register for free
Login
IndustryArena Forum > OpenSource CNC Design Center > OpenSource Software > Code for running 3 stepper motors with raspberry pi
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2019
    Posts
    3

    Code for running 3 stepper motors with raspberry pi

    Hi,
    I wan to run 3 stepper motors with raspberry pi and:

    https://www.ebay.com/itm/5x-DRV8825-...53.m2749.l2649
    https://www.ebay.com/itm/SALE-Wantai...53.m2749.l2649

    Its a special CNC-machine so I cant use some CNC-software + I want to learn how to program. I cant find any example how to write the code in python, so i ask anyone here if they know any example?

    As I understand the drivers has auto sequence for the motors so I dont need to program that. If I can get the answer to write the code for 1 full turn for 3 motors at the same time I think I can figure out the rest.

    Thanks!

  2. #2
    Join Date
    Dec 2019
    Posts
    2
    Hi esod, use this code, and repeat for other 2 motors :

    import RPi.GPIO as GPIO
    import time

    # Variables

    delay = 0.0015
    steps = 30

    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)

    # Enable pins for IN1-4 to control step sequence

    coil_A_1_pin = 13
    coil_A_2_pin = 5
    coil_B_1_pin = 23
    coil_B_2_pin = 24

    # Set pin states

    GPIO.setup(coil_A_1_pin, GPIO.OUT)
    GPIO.setup(coil_A_2_pin, GPIO.OUT)
    GPIO.setup(coil_B_1_pin, GPIO.OUT)
    GPIO.setup(coil_B_2_pin, GPIO.OUT)

    # Function for step sequence

    def setStep(w1, w2, w3, w4):
    GPIO.output(coil_A_1_pin, w1)
    GPIO.output(coil_A_2_pin, w2)
    GPIO.output(coil_B_1_pin, w3)
    GPIO.output(coil_B_2_pin, w4)

    try:
    while True:
    for i in range(0, 50): $
    setStep(1,0,1,0)
    time.sleep(delay)
    setStep(0,1,1,0)
    time.sleep(delay)
    setStep(0,1,0,1)
    time.sleep(delay)
    setStep(1,0,0,1)
    time.sleep(delay)
    sleep(0.01)
    finally:
    GPIO.cleanup()

Similar Threads

  1. Running 2 stepper motors off a single drive
    By laserpilot in forum Stepper Motors / Drives
    Replies: 10
    Last Post: 12-05-2018, 06:24 AM
  2. Stepper motors not running well
    By tomips in forum Open Source CNC Machine Designs
    Replies: 4
    Last Post: 02-10-2018, 09:25 PM
  3. Replies: 3
    Last Post: 06-06-2017, 02:02 PM
  4. Running Stepper Motors
    By tmd019 in forum Hobbycnc (Products)
    Replies: 3
    Last Post: 05-04-2007, 04:10 AM
  5. Unsure About Running Stepper Motors
    By tmd019 in forum Hobbycnc (Products)
    Replies: 29
    Last Post: 04-22-2007, 06:28 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •