Pin Capture


I’m trying to use PinCaputre (GHIElectronics.NETMF.Hardware.PinCapture) on a socket in order to read a PWM signal on an extender.

Firstly, I’m a chancer, but I’d be grateful if anyone had an example of this?

And, how do you associate or access a particular socket and pin in order to use the PinCapture?

Thanks in advance for any help with this - it would be a great example.


Is this on spider?

sorry - yeah it’s the spider.

If you want to get a particular pin from a socket, you should be able to use this:

GT.Socket.GetSocket(socketNumber, true, null, null).CpuPins[pinNumber]

Hope this helps!

Thanks - works a treat.

Now to read the pin.

Got it. I’ll paste the code here in case someone else can use it. If anyone has suggestions for better code then please share - I’m new to C# - and not a great coder either!

public partial class Program
        // This method is run when the mainboard is powered up or reset.  

        GHIElectronics.NETMF.Hardware.PinCapture ranger;
        static uint[] readings = new uint[1];

        void ProgramStarted()
            GT.Socket socketEight = GT.Socket.GetSocket(8, true, null, null);

            ranger = new GHIElectronics.NETMF.Hardware.PinCapture(socketEight.CpuPins[3], Microsoft.SPOT.Hardware.Port.ResistorMode.Disabled);


            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");

        void readRanger()
            ranger.Read(true, readings, 0, readings.Length, 3000);
            double readingMicro = double.Parse(readings.GetValue(0).ToString());
            double conversion = (readingMicro / 147) * 2.54;
            int roundedCM = (int)conversion;

            Debug.Print("Distance: " + roundedCM);



Is that for an ultrasonic range finder?

Yeah - the calculation is for a maxbotix ranger in particular.