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.

MacGuffin

Member Since 28 Dec 2013
Offline Last Active Jan 10 2014 12:39 AM
-----

Posts I've Made

In Topic: SeeedStudio Motorshield

29 December 2013 - 07:08 AM

I have a Netduino (series 1), and am trying to convert the above code to run my motor shield. I have made some progress, considering that I know little programming. I think I have it set up to power the motor back and forth when it starts, but it is not powering it very much (barely powers the small motor I got to check if it was working, let alone the large motor I want it to power)

 

Here is what I have:

SeeedMotorShield.cs

using System;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.Netduino;using System.Collections;namespace Seeed.MotorShield{    class Motor    {	    public enum motors { M1, M2, Stepper };	    private static int[] activeMotors=new int[2];   	 public static int[] ActiveMotors   	 {       	 get { return activeMotors;}   	 }	    public /*readonly*/ Microsoft.SPOT.Hardware.PWM SpeedPin /*= new PWM(PWMChannels.PWM_PIN_D9, 20000, 1500, false)*/;	    //Pins.GPIO_PIN_D9, 20000, 1500, Microsoft.SPOT.Hardware.PWM.ScaleFactor.Microseconds, false	   		 public /*readonly*/ OutputPort pinPos; //= new OutputPort(Pins.GPIO_PIN_D8, false);	    public /*readonly*/ OutputPort pinNeg; //= new OutputPort(Pins.GPIO_PIN_D11, false);	   	    		 //public readonly OutputPort pin_step1;	    //public readonly OutputPort pin_step2;	    //public readonly OutputPort pin_step3;	    //public readonly OutputPort pin_step4;	    //public readonly Microsoft.SPOT.Hardware.PWM		  public void spinPositive()	    {		    SpeedPin.Start();		    pinNeg.Write(false);		    pinPos.Write(true);	    }	    public void spinNegative()	    {		    SpeedPin.Start();		    pinPos.Write(false);		    pinNeg.Write(true);	    }	    public void stop()	    {		    SpeedPin.Stop();		    pinPos.Write(false);		    pinNeg.Write(false);	    }    }}

And Program.cs

using System;using System.Threading;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.Netduino;using Seeed.MotorShield;namespace HelloMotor{    public class Program    {	    private static Motor motorA;	    private static bool moveForward = true;	    private static bool motorOn = false;	    public static void Main()	    {		    motorA = new Motor();		    /*InputPort button =				    new InputPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled);*/		    /*OutputPort */motorA.pinPos = new OutputPort(Pins.GPIO_PIN_D8, false);		    /*OutputPort */motorA.pinNeg = new OutputPort(Pins.GPIO_PIN_D11, false);		    /*public readonly Microsoft.SPOT.Hardware.PWM*/		    motorA.SpeedPin = new PWM(PWMChannels.PWM_PIN_D9, 20000, 5000, Microsoft.SPOT.Hardware.PWM.ScaleFactor.Microseconds, false);		    motorA.SpeedPin.SetDutyCycle(65)		    motorA.spinPositive();		    System.Threading.Thread.Sleep(800);		    motorA.spinNegative();		    System.Threading.Thread.Sleep(200);		    motorA.spinPositive();		    System.Threading.Thread.Sleep(200);		    motorA.spinNegative();		    System.Threading.Thread.Sleep(800);		    motorA.spinPositive();		    System.Threading.Thread.Sleep(200);		    motorA.spinNegative();		    System.Threading.Thread.Sleep(800);		    motorA.stop();		    /*while (true)		    {			   			    				 motorOn = True;			   				 if (motorOn)			    {				    if (moveForward)					    forward();				    else					    backward();			    }			    else			    {				    motorA.stop();			    }			    //ledPort.Write(!ledPort.Read());			    //System.Threading.Thread.Sleep((int)(pot.GetValue()*1000));		    }*/	    }	    private static void forward()	    {		    motorA.spinPositive();		    System.Threading.Thread.Sleep(200);	    }	    private static void backward()	    {		    motorA.spinNegative();		    System.Threading.Thread.Sleep(200);	    }	    private static void onboardButton_OnInterrupt(uint data1, uint data2, DateTime time)	    {		    motorOn = !motorOn;	    }	    private static void button_ButtonReleased(object sender, bool buttonState)	    {		    moveForward = !moveForward;	    }    }}

I am very new to this, and would appreciate any feedback!

.

 

 

Edit: update! I have worked on the code, and I now get a series of blinking lights but the motor is way under powered, can anyone tell why by the code?


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.