I'm pretty new to 3D printing as there is a need for me to control the stepper motor for the X,Y and Z axis. I have two stepper motors and a Micro-step Driver (CW-5045) and of course Raspberry pi 3 with an extension board.
I want the Z-axis to move for the 3D printer by clicking on the desired button. Buttons are for the given position to move the Z axis up and down. I was thinking to have 2-3 buttons which are supposed to move 25 micro layers, 50 micro layers and 100 micro layers. (I'm not sure whether it is micro layer or micro meters).
The code below mentioned is the one which I tried but the Stepper motor is making some noise but I haven't seen any movement in the axis.
I have tried with this reference: setup leadshine DM860 bipolar driver motor on raspberry pi
I know I could use external printer controllers like Octoprint and others but the project is in initial stage as I don't have all the equipments. So I wanted to start with Stepper motor.
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
CW = 1 # Clockwise Rotation
CCW = 0 # Counterclockwise Rotation
SPR = 200 # Steps per Revolution (360 / 1.8)
GPIO.setup(21,GPIO.OUT)
GPIO.setup(20,GPIO.OUT)
GPIO.output(21,False)
microStep = 0
step_count = SPR
delay = .0208
GPIO.output(20, GPIO.HIGH)
while True:
for x in range(step_count):
GPIO.output(20, GPIO.HIGH)
sleep(delay)
GPIO.output(20, GPIO.LOW)
sleep(delay)
sleep(.5)
GPIO.output(20, GPIO.LOW)
for x in range(step_count):
GPIO.output(20, GPIO.HIGH)
sleep(delay)
GPIO.output(20, GPIO.LOW)
sleep(delay)
microStep = microStep + 1
print(microStep)
GPIO.cleanup()
I think I'm missing to control the speed of the motor. I would like to control the motor in micro-steps accurately by giving desired positional value not just the motor running from top to bottom.
With the help of one of the members from raspberry pi forum the the problem has been solved.
For the future references to someone like me
import RPi.GPIO as GPIO
import time
from time import sleep
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(21,GPIO.OUT) # direction
GPIO.setup(20,GPIO.OUT) # step
step_count = 72727 # number of step to run change this to change where it stops
delay = 0.001
# drive motor clockwise number of steps set by step count
GPIO.output(21, GPIO.HIGH)
print (" Drive CW ", step_count ,"steps")
for x in range(step_count):
GPIO.output(20, GPIO.HIGH)
sleep(delay)
GPIO.output(20, GPIO.LOW)
sleep(delay)
# stop motor for 5 seconds
print (" Stop")
sleep(5)
input("Press Enter to continue...")
# drive motor counter clockwise number of steps set by step count
print (" Drive CCW ", step_count ,"steps")
GPIO.output(21, GPIO.LOW)
for x in range(step_count):
GPIO.output(20, GPIO.HIGH)
sleep(delay)
GPIO.output(20, GPIO.LOW)
sleep(delay)
# end of program
print (" End program")
GPIO.cleanup()
step_count would change according to the calculations(depends on motor angle and the count of the distance moved for one revolution).
Peace