Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Adafruit MotorShield v2.3 and TA.NetMF.MotorControl

Adafruit MotorControl

  • Please log in to reply
2 replies to this topic

#1 muhq

muhq

    New Member

  • Members
  • Pip
  • 2 posts

Posted 15 June 2015 - 04:56 PM

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
	}
}



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 15 June 2015 - 06:27 PM

Hi muhq,

What version of NETMF is the driver library compiled for? Do you have access to the source (so you can just add it into your project)?

Also...what is the error you are getting, exactly?

Chris

#3 muhq

muhq

    New Member

  • Members
  • Pip
  • 2 posts

Posted 16 June 2015 - 06:47 PM

Hi Chris,

 

thanks for your reply.

I'm using NETMF 4.3 with Visual Studio 2013.

 

The problem is, the sample will not compile as it uses the wrong objects (I guess). As soon as I change it to the above, it is running on the netduino. The Main function takes nearly 2 minutes to step through my calls until it reaches the sleep function.

After that there is no error, but nothing is happening...

 

I'll try to add the sources to my project, maybe I can figure out what is going on...

 

I was hoping somebody is running this shield by using this lib already :)






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.