Skip to main content

Meadow.Foundation.Motors.Stepper.A4988

A4988
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.Motors.Stepper.A4988

Code Example

private A4988 a4988;

public override Task Initialize()
{
a4988 = new A4988(
step: Device.Pins.D01,
direction: Device.Pins.D00,
ms1Pin: Device.Pins.D04,
ms2Pin: Device.Pins.D03,
ms3Pin: 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++)
{
Resolver.Log.Info($"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;
}
}

Sample project(s) available on GitHub

Wiring Example

To wire a A4988 to your Meadow board, connect the following:

A4988Meadow Pin
GNDGND
VCC5V
STEPD01
DIRECTIOND00
M1D04
M2D03
M3D02

It should look like the following diagram:

Class A4988

This class is for the A4988 Stepper Motor Driver

Assembly: A4988.dll
View Source
Declaration
public class A4988 : IDisposable

Implements:
System.IDisposable

Properties

StepAngle

Gets or sets the angle, in degrees, of one step for the connected stepper motor

View Source
Declaration
public Angle StepAngle { get; set; }

RotationSpeedDivisor

Divisor used to adjust rotational speed of the stepper motor

View Source
Declaration
public int RotationSpeedDivisor { get; set; }

Direction

Sets or gets the direction of rotation used for Step or Rotate methods

View Source
Declaration
public RotationDirection Direction { get; set; }

StepDivisor

Divisor for micro-stepping a motor
This requires the three micro-step control lines to be connected to the motor

View Source
Declaration
public StepDivisor StepDivisor { get; set; }

StepsPerRevolution

Gets the number of steps/micro-steps in the current configuration required for one 360-degree revolution

View Source
Declaration
public int StepsPerRevolution { get; }

IsDisposed

Is the object disposed

View Source
Declaration
public bool IsDisposed { get; }

Methods

Rotate(float, RotationDirection)

Rotates the stepper motor a specified number of degrees

View Source
Declaration
public void Rotate(float degrees, RotationDirection direction)
Parameters
TypeNameDescription
System.SingledegreesDegrees to rotate
Meadow.Peripherals.RotationDirectiondirectionDirection of rotation

Rotate(float)

Rotates the stepper motor a specified number of degrees

View Source
Declaration
public void Rotate(float degrees)
Parameters
TypeNameDescription
System.SingledegreesDegrees to rotate

Step(int, RotationDirection)

Rotates the stepper motor a specified number of steps (or microsteps)

View Source
Declaration
public void Step(int count, RotationDirection direction)
Parameters
TypeNameDescription
System.Int32countNumber of steps to rotate
Meadow.Peripherals.RotationDirectiondirectionDirection of rotation

Step(int)

Rotates the stepper motor a specified number of steps (or microsteps)

View Source
Declaration
public void Step(int count)
Parameters
TypeNameDescription
System.Int32countNumber of steps to rotate

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

View Source
Declaration
public void Dispose()

Dispose(bool)

Dispose of the object

View Source
Declaration
protected virtual void Dispose(bool disposing)
Parameters
TypeNameDescription
System.BooleandisposingIs disposing

Implements

  • System.IDisposable