Remarks

A4988
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Motors.Stepper.A4988

Code Example

A4988 a4988;

public override Task Initialize()
{
    a4988 = new A4988(
        device: Device, 
        step: Device.Pins.D01,
        direction: Device.Pins.D00, 
        ms1: Device.Pins.D04, 
        ms2: Device.Pins.D03, 
        ms3: Device.Pins.D02);

    return base.Initialize();
}

public override Task Run()
{
    var stepDivisors = (StepDivisor[])Enum.GetValues(typeof(StepDivisor));
    while (true)
    {
        foreach (var step in stepDivisors)
        {
            for (var d = 2; d < 5; d++)
            {
                Console.WriteLine($"180 degrees..Speed divisor = {d}..1/{(int)step} Steps..{a4988.Direction}...");
                a4988.RotationSpeedDivisor = d;
                a4988.StepDivisor = step;
                a4988.Rotate(180);

                Thread.Sleep(500);
            }
        }
        a4988.Direction = (a4988.Direction == RotationDirection.Clockwise) ? RotationDirection.Counterclockwise : RotationDirection.Clockwise;
    }

    return base.Run();
}

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 ms1Pin, IPin ms2Pin, IPin ms3Pin)

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 ms1Pin

The (optional) Meadow pin connected to the MS1 pin of the A4988

IPin ms2Pin

The (optional) Meadow pin connected to the MS2 pin of the A4988

IPin ms3Pin

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 enablePin, IPin ms1Pin, IPin ms2Pin, IPin ms3Pin)

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 enablePin

The (optional) Meadow pin connected to the ENABLE pin of the A4988

IPin ms1Pin

The (optional) Meadow pin connected to the MS1 pin of the A4988

IPin ms2Pin

The (optional) Meadow pin connected to the MS2 pin of the A4988

IPin ms3Pin

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 Angle StepAngle { get; set; }

Property Value

Type Description
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

Degrees to rotate

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

Degrees to rotate

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