PWM Servo and Mountaineer

Hello guys,
I have HS-322HD and I’m trying to driving using Mountaineer Ethernet board and it’s not working… I’m using the extender and I get an error when I create the PWMoutput…

I also noticed that the extender code have changed from 4.2 to 4.3 we no longer have setPulse but instead only Set …

can someone please post an example on how to drive a servo using Gadgeteer and an extender?

even in Plain NETMF Would be nice too…


    private GT.SocketInterfaces.PwmOutput servo;
        private static uint high = 2100000;
        private static uint low =  900000;
        private static uint delta = high - low;
        private uint percent = 10;

        void ProgramStarted()
        {
            servo = extender.CreatePwmOutput(GT.Socket.Pin.Nine);
           uint pulse = low + (delta * percent / 100);
            servo.Set(20000,pulse);
}


here is the exception I get:


An unhandled exception of type 'System.ArgumentException' occurred in Gadgeteer.dll
Additional information: dutyCycle


cheers,
Jay.

Vanilla enough?

using System.Threading;
using Microsoft.SPOT.Hardware;

namespace ServoTest
{
    public class Program
    {
        private static PWM _servo;
        public static void Main()
        {
            _servo = new PWM((Cpu.PWMChannel)9, 20000, 1500, PWM.ScaleFactor.Microseconds, false);
            _servo.Start();
            new Thread(TheWheelsOnTheBusGo);
            Thread.Sleep(Timeout.Infinite);
        }

        static void TheWheelsOnTheBusGo()
        {
            for (;;)
            {
                _servo.Duration = 750; // The wheels on the bus go left
                Thread.Sleep(2000);
                _servo.Duration = 2250; // The wheels on the bus go right
                Thread.Sleep(2000);
                _servo.Duration = 1500; // Drunk driving over - going straight
                Thread.Sleep(2000);
            }
        }
    }
}
2 Likes

Thanks Justin,

Well I found two issues:

one the Servo was a bust :(…
second the extender module have changed from 4.2 t0 4.3 not sure why certain functions were dropped and it’s not documented anywhere…

anyway I adjusted Justin’s Code to be used in Gadgeteer and 4.3 as follow, and it works…



//hook your Extender to any Socket with P, in my case below it is Socket 4 as i'm using Mountaineer Ether board. adjust the code below to the number of the socket you are using.

   private static PWM _servo;
      void ProgramStarted()
        {
            var getExtender= Gadgeteer.Socket.GetSocket(4, true, extender, (string)null);

            _servo = new PWM(getExtender.PWM9, 20000, 1500, PWM.ScaleFactor.Microseconds, false);
            _servo.Start();
            new Thread(TheWheelsOnTheBusGo).Start();
}
        static void TheWheelsOnTheBusGo()
        {
            while (true)
            {
                _servo.Duration = 750; // The wheels on the bus go left
                Thread.Sleep(2000);
                _servo.Duration = 2250; // The wheels on the bus go right
                Thread.Sleep(2000);
                _servo.Duration = 1500; // Drunk driving over - going straight
                Thread.Sleep(2000);
            }
        }

thanks Justin for your help…

cheers,
Jay.

1 Like