Remarks
A4988 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
public MeadowApp()
{
var a = new A4988(Device, Device.Pins.D01, Device.Pins.D00, Device.Pins.D04, Device.Pins.D03, Device.Pins.D02);
var s = (StepDivisor[])Enum.GetValues(typeof(StepDivisor));
while (true)
{
foreach (var sd in s)
{
for (var d = 2; d < 5; d++)
{
Console.WriteLine($"180 degrees..Speed divisor = {d}..1/{(int)sd} Steps..{a.Direction}...");
a.RotationSpeedDivisor = d;
a.StepDivisor = sd;
a.Rotate(180);
Thread.Sleep(500);
}
}
a.Direction = (a.Direction == RotationDirection.Clockwise) ? RotationDirection.Counterclockwise : RotationDirection.Clockwise;
}
}
Sample project(s) available on GitHub
Wiring Example
To wire a A4988 to your Meadow board, connect the following:
A4988 | Meadow Pin |
---|---|
GND | GND |
VCC | 5V |
STEP | D01 |
DIRECTION | D00 |
M1 | D04 |
M2 | D03 |
M3 | D02 |
It should look like the following diagram:
Characteristic | Locus |
---|---|
Inheritance | System.Object > A4988 |
Namespace | Meadow.Foundation.Motors.Stepper |
Assembly | A4988.dll |
Syntax
public class A4988 : object
Constructors
A4988(IDigitalOutputController, IPin, IPin)
Creates an instance of the A4988 Stepper Motor Driver
Declaration
public A4988(IDigitalOutputController device, IPin step, IPin direction)
Parameters
Type | Name | Description |
---|---|---|
IDigitalOutputController | device | The IIoDevice instance that can create Digital Output Ports |
IPin | step | The Meadow pin connected to the STEP pin of the A4988 |
IPin | direction | The Meadow pin connected to the DIR pin of the A4988 |
Remarks
You must provide either all of the micro-step (MS) lines or none of them
A4988(IDigitalOutputController, IPin, IPin, IPin)
Creates an instance of the A4988 Stepper Motor Driver
Declaration
public A4988(IDigitalOutputController device, IPin step, IPin direction, IPin enable)
Parameters
Type | Name | Description |
---|---|---|
IDigitalOutputController | device | The IIoDevice instance that can create Digital Output Ports |
IPin | step | The Meadow pin connected to the STEP pin of the A4988 |
IPin | direction | The Meadow pin connected to the DIR pin of the A4988 |
IPin | enable | The (optional) Meadow pin connected to the ENABLE pin of the A4988 |
A4988(IDigitalOutputController, IPin, IPin, IPin, IPin, IPin)
Creates an instance of the A4988 Stepper Motor Driver
Declaration
public A4988(IDigitalOutputController device, IPin step, IPin direction, IPin ms1, IPin ms2, IPin ms3)
Parameters
Type | Name | Description |
---|---|---|
IDigitalOutputController | device | The IIoDevice instance that can create Digital Output Ports |
IPin | step | The Meadow pin connected to the STEP pin of the A4988 |
IPin | direction | The Meadow pin connected to the DIR pin of the A4988 |
IPin | ms1 | The (optional) Meadow pin connected to the MS1 pin of the A4988 |
IPin | ms2 | The (optional) Meadow pin connected to the MS2 pin of the A4988 |
IPin | ms3 | The (optional) Meadow pin connected to the MS3 pin of the A4988 |
Remarks
You must provide either all of the micro-step (MS) lines or none of them
A4988(IDigitalOutputController, IPin, IPin, IPin, IPin, IPin, IPin)
Creates an instance of the A4988 Stepper Motor Driver
Declaration
public A4988(IDigitalOutputController device, IPin step, IPin direction, IPin enable, IPin ms1, IPin ms2, IPin ms3)
Parameters
Type | Name | Description |
---|---|---|
IDigitalOutputController | device | The IIoDevice instance that can create Digital Output Ports |
IPin | step | The Meadow pin connected to the STEP pin of the A4988 |
IPin | direction | The Meadow pin connected to the DIR pin of the A4988 |
IPin | enable | The (optional) Meadow pin connected to the ENABLE pin of the A4988 |
IPin | ms1 | The (optional) Meadow pin connected to the MS1 pin of the A4988 |
IPin | ms2 | The (optional) Meadow pin connected to the MS2 pin of the A4988 |
IPin | ms3 | The (optional) Meadow pin connected to the MS3 pin of the A4988 |
Remarks
You must provide either all of the micro-step (MS) lines or none of them
Properties
Direction
Sets or gets the direction of rotation used for Step or Rotate methods.
Declaration
public RotationDirection Direction { get; set; }
Property Value
Type | Description |
---|---|
RotationDirection |
RotationSpeedDivisor
Divisor used to adjust rotaional speed of the stepper motor
Declaration
public int RotationSpeedDivisor { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
StepAngle
Gets or sets the angle, in degrees, of one step for the connected stepper motor.
Declaration
public Units.Angle StepAngle { get; set; }
Property Value
Type | Description |
---|---|
Units.Angle |
StepDivisor
Divisor for micro-stepping a motor. This requires the three micro-step control lines to be connected to the motor.
Declaration
public StepDivisor StepDivisor { get; set; }
Property Value
Type | Description |
---|---|
StepDivisor |
StepsPerRevolution
Gets the number of steps/micro-steps in the current configuration required for one 360-degree revolution.
Declaration
public int StepsPerRevolution { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
Rotate(Single)
Rotates the stepper motor a specified number of degrees
Declaration
public void Rotate(float degrees)
Parameters
Type | Name | Description |
---|---|---|
System.Single | degrees |
Rotate(Single, RotationDirection)
Rotates the stepper motor a specified number of degrees
Declaration
public void Rotate(float degrees, RotationDirection direction)
Parameters
Type | Name | Description |
---|---|---|
System.Single | degrees | |
RotationDirection | direction | Direction of rotation |
Step(Int32)
Rotates the stepper motor a specified number of steps (or microsteps)
Declaration
public void Step(int count)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | count | Number of steps to rotate |
Step(Int32, RotationDirection)
Rotates the stepper motor a specified number of steps (or microsteps)
Declaration
public void Step(int count, RotationDirection direction)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | count | Number of steps to rotate |
RotationDirection | direction | Direction of rotation |