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?
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);
}
}
}
}
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);
}
}