Main Site Documentation

Pin Capture


#1

Hi,

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.

:slight_smile:


#2

Is this on spider?


#3

sorry - yeah it’s the spider.


#4

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!


#5

Thanks - works a treat.

Now to read the pin.


#6

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

            readRanger();


            // 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);

        }



#7

shapingstuff,

Is that for an ultrasonic range finder?


#8

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