Skip to content

Latest commit

 

History

History
170 lines (117 loc) · 7.03 KB

Nema11A4988.md

File metadata and controls

170 lines (117 loc) · 7.03 KB

Bipolar Nema11 Stepper motor with A4988 Driver Carrier

ScreenShot Nema ScreenShot A4988

Hardware

Nema 11 Stepper Motor:

This library was tested
with a typical bipolar NEMA-11 stepper motor with four wires: should work with any similar type motor.

ScreenShot motor pinout

It has 200 steps per revolution, and can operate at at 60 RPM. It was a step to angle ratio of 1.8 degrees per step.

You will need to determine the A, B, C and D wires on the stepper motor. With our example motor these are green, blue, black and red.

coil 2.

  • Motor black wire A == 2B (A4988)
  • Motor green wire C == 2A

coil 1.

  • Motor red wire B == 1A
  • Motor blue wire D == 1B

A4988:

Good info!

A4988 News Article

A4988 Datasheet

A4988 How to Setup with A4988 Arduino, Blog by DroneBot Workshop

The A4988 is a very common and inexpensive stepper motor controller, With a heatsink the device can handle up to 2 amperes.

Pinout of the A4988 module:

ScreenShot A4988 pinout

  • VMOT – The motor DC supply voltage (positive). The maximum voltage is 35 volts.
  • GND – The motor supply voltage ground.
  • 2B, 2A – The connections to coil 2 of the bipolar stepper motor.
  • 1A, 1B – The connections to coil 1 of the bipolar stepper motor.
  • VDD – The logic supply DC voltage. This can range from 3 to 5.5 volts.
  • GND – The logic supply ground.
  • ENABLE – This is an active low connection, when brought low (ground) the A4988 module is enabled. By default this is pulled low so the module is always enabled unless you apply a logic high here.
  • MS1, MS2, MS3 – These three connections determine the microstepping mode of the A4988 module. By setting the logic levels here you can set the motor to Full, Half, Quarter, Eighth, Sixteenth steps.
  • RESET – This is an active low line that will reset the module. By default it is pulled high.
  • SLEEP – If this line is set low the module will enter a low-powered sleep mode and consume minimal current. By tying this line to the Reset pin the module will always be on at full power consumption.
  • STEP – This is how you drive the motor from an external microcontroller or square wave oscillator. Each pulse sent here steps the motor by whatever number of steps or microsteps that has been set by MS1, MS2 and MS3 settings. The faster you pulse this the faster the motor will travel.
  • DIR – The direction control A high input here drives the motor clockwise, a low will drive it counterclockwise.

A4988 wiring diagram:

ScreenShot A4988 wiring diagram

Make sure to observe the motor connections, described in Motor section above the A4988 is conveniently laid out to match the 4-pin connector that is common on several bipolar motors but you should check your motor connections to be sure they are correct.

Connect 5 GPIO pins to MS1, MS2, MS3, STEP and DIR. if you do not wish to use GPIO for MS_X pins and hard wire MS-X to logic levels.You can also pass in (-1, -1, -1) to software. Do this if your project only uses one type of resolution and you wish to save GPIO pins.

Connect Reset to Sleep. Connect pi Vcc 5V and GND to A4988 at VDD and GND

The capacitor is essential to decouple the power supply. Any value from 47uf up will suffice, try and mount the capacitor as close to the A4988 VMOT and GND pins as possible. Connect up capacitor and Motor leads.

Advisable to carry out a Current Adjustment before using motor, see links at top of section for instructions. Also do not disconnect motor when in operation, as it will damage controller.

There are 5 step modes for A4988.

MicroStep Step increment degrees Steps for 1 revolution(360)
Full 1.8 200
Half 0.9 400
1/4 0.45 800
1/8 0.225 1600
1/16 0.1125 3200

Microstep Resolution Truth Table.

MS1 MS2 MS3 Resolution
Low Low Low Full step
High Low Low Half step
Low High Low 1/4
High High Low 1/8
High High High 1/16

Software

The library file RpiMotorLib.py contains the class which controls the motor. The class is called A4988Nema. Test file is called A4988_Nema_Test.py

The class is initialized with four arguments. A4988Nema(direction_pin, step_pin, mode_pins, motor_type)

ID Name Type Default Help
(1) direction int GPIO pin connected to DIR pin of IC.
(2) step_pin int GPIO pin connected to STEP of IC.
(3) mode_pins tuple of 3 ints GPIO pins connected to, Microstep Resolution pins MS1-MS3 of IC. Pass in (-1, -1, -1) for hardwired MS-X connection
(4) motor_type string A4988 type of motor, three options "A4988" or "DRV8825" or "LV8729"

The main method that moves motor is called motor_go, takes 6 inputs.

motor_go(clockwise, steptype, steps, stepdelay, verbose, initdelay)

ID Name Type Default Help
(1) clockwise bool false Turn stepper counterclockwise
(2) steptype string Full type of drive to step motor 5 options, Full, Half, 1/4, 1/8, 1/16
(3) steps int 200 Number of steps sequence's to execute. Default is one revolution , 200 in Full mode.
(4) stepdelay float 0.05 Time to wait (in seconds) between steps.
(5) verbose bool false Write pin actions
(6) initdelay float 1mS Intial delay after GPIO pins initialized but before motor is moved

Another function is called to stop the motor when the motor is moving. motor_stop(), if you wish to stop motor before end of its run. You can also stop with keyboard interrupt.

Example: Should do a 180 degree turn. To run A stepper motor clockwise in Full mode for 100 steps. for step delay of .01 second. verbose output off , with 50mS init delay.

 
import RPi.GPIO as GPIO

# import the library
from RpiMotorLib import RpiMotorLib
    
#define GPIO pins
GPIO_pins = (14, 15, 18) # Microstep Resolution MS1-MS3 -> GPIO Pin
direction= 20       # Direction -> GPIO Pin
step = 21      # Step -> GPIO Pin

# Declare an named instance of class pass GPIO pins numbers
mymotortest = RpiMotorLib.A4988Nema(direction, step, GPIO_pins, "A4988")


# call the function, pass the arguments
mymotortest.motor_go(False, "Full" , 100, .01, False, .05)