Stepper Motor Arduino Mega Program:
- Controlling stepper motors
- There are 4 stepper motors
- Each Stepper motor is controlled by a driver board.
- The driver board is controlled by 3 digital signals
1) EN: enables the motor
2) STP: When gets high and low the motor will take one step, The duration of each cycle defines the speed of the motor
3) DIR: Defines the direction of rotation (0 or 1)
- Link to the driver board: https://www.amazon.com/gp/product/B016ZJS1FA/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1
- Each motor has 2 limit switchs connected to digital inputs of the Arduino board. When a motor reaches the limit switch it has to stop independent of the remaining steps and commands.
- In the main loop a function will be called "driveMotor ()" to drive a motor in certain direction at certain speed for a specific number of steps.
"driveMotor ()" Function:
- When this function is called, it receives the following:
1) Stepper Motor Number (0,1,2,3)
2) Direction (0,1)
3) Number of Steps
- The function translates the Speed and Number of Steps into proper PWM signal that drives the motor in the proper direciton with the proper number of steps at the required speed.
- PWM cycle length has to be adjusted according to the speed which will be a number between (1 to 255)
- This function will command the right motor to drive in the proper direction.
- At all times during the drive, it checks for the limit switch that belongs to that motor and if the switch is hit (independent of the number of steps left) it will stop the motion.
- Clean modular design of the program
- Comment all the main modules
- Provide all the required libraries for compiling the program