Bipolar Nema11 Stepper motor with A4988 Driver Carrier -------------------------------------------- ![ScreenShot Nema](https://github.com/gavinlyonsrepo/RpiMotorLib/blob/master/extra/images/nema11.jpg) ![ScreenShot A4988](https://github.com/gavinlyonsrepo/RpiMotorLib/blob/master/extra/images/A4988.jpg) 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 ](https://raw.githubusercontent.com/gavinlyonsrepo/RpiMotorLib/master/extra/images/nema11pinout.jpg) 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](http://www.hobbytronics.co.uk/a4988-stepper-motor-driver) [A4988 Datasheet](http://www.hobbytronics.co.uk/datasheets/a4988_DMOS_microstepping_driver_with_translator.pdf) [A4988 How to Setup with A4988 Arduino, Blog by DroneBot Workshop](https://dronebotworkshop.com/stepper-motors-with-arduino/) 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](https://github.com/gavinlyonsrepo/RpiMotorLib/blob/master/extra/images/A4988-Stepper-Controller-Pinout.jpg) * 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](https://github.com/gavinlyonsrepo/RpiMotorLib/blob/master/extra/images/wiringdiagram1.jpg) 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.