Interfacing Stepper Motor with STM32F407 Disc board

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Interfacing Stepper Motor with STM32F407 Disc board

Post by nikhiledutech » Fri May 04, 2018 10:29 am

Hello,

I am currently interfacing STM601 stepper motor with stm32f4 disc board. The stepper motor pins are PE9 , PE11, PE 13 , PE15.

I need to set the following pins sequence for Clockwise and anti Clockwise rotation.
SmAntClk = 0x0A,0x88,0xA0,0x22
SmClk = 0x22,0xA0,0x88,0x0A

In the code i have created a list of functions, for setting up each pin sequence in Clockwise / Anti Clockwise Direction. In main function, i am using a for loop which will iterate over the pin sequence function based on the rotation selected.


Problem: The program gets executed without any error, but the motor is not rotating. The for loop is working fine i guess, but it seems the sequence of pins are not sent properly OR is there any error which i cant find.


Below i have given the code. Can anyone try to help me out ?



Code: Select all



from pyb import Pin

#Defining Directions
MotorClockwise = 0
MotorAntiClockwise = 1

#Defining Calibre angle of ST_Motor
CAL_ANGLE = 18


#Stepper_Motor_Pins Initialisation
st_motor_pins = [Pin('PE9'), Pin('PE11'), Pin('PE13'), Pin('PE15')]



#Stepper Motor Initialisation 
def ASK25_SM_Init():
	for pin in st_motor_pins:
		pin.init(Pin.OUT_PP, Pin.PULL_NONE)



# @brief This function rotates stepper motor in desired direction and angle
# @param StMotorDirection specifies direction of rotation
#        This parameter should be: StMotorClockwise
#                                  StMotorAntiClockwise
# @param Angle specifies rotation angle
# @param Delay specifies delay between steps
def ASK25_SM_Rotate (StMotorDirection, Angle, Delay):
	i = Count = 0
	Count = ((Angle * 10) / CAL_ANGLE)
	for x in range (Count):
		ASK25_SM_Send_Sequence(StMotorDirection, Delay)



#Sequence of Stepper Motor Pins
def pins_reset():
	st_motor_pins[0].value(0)
	st_motor_pins[1].value(0)	
	st_motor_pins[2].value(0)
	st_motor_pins[3].value(0)




#Function to set  the Pins Sequence
def Zero_A():
	st_motor_pins[0].value(1)
	st_motor_pins[1].value(1)		


def Eight_Eight():
	st_motor_pins[1].value(1)
	st_motor_pins[3].value(1)		


def A_Zero():
	st_motor_pins[2].value(1)
	st_motor_pins[3].value(1)		


def Two_Two():
	st_motor_pins[0].value(1)
	st_motor_pins[2].value(1)		




# This function will send sequence to Stepper motor
# StMotorDirection specifies direction of rotation
# This parameter should be: StMotorClockwise
#                          StMotorAntiClockwise
# @param Delay specifies delay between steps


def ASK25_SM_Send_Sequence(StMotorDirection, Delay):

	SmAntClk = [Zero_A, Eight_Eight, A_Zero, Two_Two]
	SmClk = [Two_Two, A_Zero, Eight_Eight, Zero_A]

	for x in range(4):
		if (StMotorDirection == MotorClockwise):
			pins_reset()
			SmClk[x]	#Sending the appropriate sequence from list 
			print("Clockwise")
			
		elif (StMotorDirection == MotorAntiClockwise):
			pins_reset()
			SmAntClk[x]	#Sending the appropriate sequence from list 
		
		pyb.delay(Delay)




def main():
	# Initialize Stepper Motor pins 
	ASK25_SM_Init()

	# Rotate stepper motor 360 degree with delay 60 
	ASK25_SM_Rotate(MotorClockwise,360,60)


main()

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: Interfacing Stepper Motor with STM32F407 Disc board

Post by OutoftheBOTS_ » Fri May 04, 2018 7:42 pm

The pins themselfves won't create enough current to drive thje stepper motor. You will have to have an external power source to all 4 inputs of the motor that is just switched by your pogrom.

By far the easiest way to drive a stepper motor with a MCU is with a stepper motor driver. You connect the power source to the stepper driver and the stepper motor to the driver then the driver has a Step pin and direction pin that the MCU drives. The driver usually has setting for size of step from full to to half step to micro step and normally these driver are chopper drivers too.

The DRV8825 is a very popular stepper motor driver for small driver you can buy it for under $2 and is what most 3D printers use.

see https://www.youtube.com/watch?v=1kx5Ofavfbc

nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Re: Interfacing Stepper Motor with STM32F407 Disc board

Post by nikhiledutech » Mon May 07, 2018 4:41 am

I have given the external power source of 12 V.

Post Reply