Hi,
I'm trying to get a stepper running by using the adafruit motorshield v2.3
I use the nuget package TA.NetMF.MotorControl. The included samples say it is possible to use this shield, but as soon as I uncomment the needed shield, it isn't possible to compile the code anymore.
I guess the following code (changed sample) should run, but my stepper is not running. If I use the shield on a arduino uno the stepper is working so I guess my wiring seems ok.
Does anybody have a working sample of controlling a stepper motor by this library and this shield?
Many thanks in advance!
using System; using System.Diagnostics; using System.Threading; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware.NetduinoPlus; using TA.NetMF.Motor; using TA.NetMF.ShieldDriver; //This using isn't working... //using TA.NetMF.AdafruitMotorShieldV2; namespace AdafruitMotorShield { public class Program { static IStepSequencer StepperM1M2; static IStepSequencer StepperM3M4; static readonly Random randomGenerator = new Random(); public static void Main() { //this line seems to be wrong, should't that be //var adafruitMotorShieldV2 = new SparkfunArdumoto(); // use shield at default I2C address. var adafruitMotorShieldV2 = new AdafruitV2MotorShield(); adafruitMotorShieldV2.InitializeShield(); StepperM1M2 = adafruitMotorShieldV2.GetMicrosteppingStepperMotor(MicrostepsPerStep, 1, 2); StepperM3M4 = adafruitMotorShieldV2.GetMicrosteppingStepperMotor(MicrostepsPerStep, 3, 4); // Create the stepper motor axes and link them to the Adafruit driver. var axis1 = new AcceleratingStepperMotor(LimitOfTravel, StepperM1M2) { MaximumSpeed = MaxSpeed, RampTime = RampTime }; // Now we subscribe to the MotorStopped event on each axis. When the event fires, // we start the axis going again with a new random target position. axis1.MotorStopped += HandleAxisStoppedEvent; // We need to call our event handler once manually to get things going. // After that it is fully automatic. HandleAxisStoppedEvent(axis1); // Finally, we sleep forever as there is nothing else to do in the main thread. // The motors continue to work in the background all by themselves. Thread.Sleep(Timeout.Infinite); } /// <summary> /// Handles the axis stopped event for an axis. /// Picks a new random position and starts a new move. /// </summary> /// <param name="axis">The axis that has stopped.</param> static void HandleAxisStoppedEvent(StepperMotor axis) { // Be careful, both axes appear to run on the same thread, so using Thread.Sleep() here will affect both. //Thread.Sleep(3000); // Wait a short time before starting the next move. var randomTarget = randomGenerator.Next(LimitOfTravel); //Debug.Print("Starting move to " + randomTarget); axis.MoveToTargetPosition(randomTarget); } #region Stepper Configuration - Change these values to your liking. const int LimitOfTravel = 20000; /// <summary> /// The maximum speed in steps per second. /// Although the theoretical maximum is 1,000 steps per second, in practice /// the netduino plus can handle about 400 steps (or microsteps) per second, total. /// </summary> const int MaxSpeed = 400; /// <summary> /// The number of microsteps per whole step. /// Specify 4 to use whole steps, 8 to use half-steps, or 9+ to use microsteps. /// The higher the value, the smoother the motor motion will be but the slower it will turn. /// </summary> const int MicrostepsPerStep = 256; /// <summary> /// The ramp time, i.e. the number of seconds taken to reach <see cref="MaxSpeed" />. /// Setting <see cref="AcceleratingStepperMotor.RampTime" /> affects <see cref="AcceleratingStepperMotor.Acceleration" /> /// and vice versa. /// </summary> const double RampTime = 5; // seconds to reach full speed (acceleration) #endregion } }