FEZ Cobra III: Can I wire a LED to pin D42?

I have wired the long end of a LED to pin D42 on my FEZ Cobra III, and the short end to a 3V3 pin.

Now the LED remains on, whereas I intended it to start in the off state.

What did I do wrong?

You need to use a current limiting resistor for starters or the LED will burn out.

Your wiring is also wrong.

The long lead is the ANODE and this should be connected to the 3.3V via a resistor. Something like 120ohm will do for starters.

The short lead is the cathode and goes to the IO pin. When the IO is LOW, the LED will light. In normal state the IO should be in the INPUT state and be pulled HIGH or floating. The LED should remain off until you set the GPIO to output and then drive it LOW to switch the LED on.

@ Derrick - Further, don’t attempt to run a relay like this. The I/O pins of a µC are not intended to drive inductive loads.

I apologize. I did not explain myself completely.

I do have a resister between the cathode and D50 on my FEZ Cobra III.

And it works.

Thanks for your concern and patience with me. I greatly appreciate it.

i must really apologize…for some reason, it seems to not work anymore…

My code crashes on this line:
_LED = new OutputPort(GHI.Pins.FEZCobraIII.Gpio.D50, true);

Does D50 here mean the pin D50 on my FEZ Cobra III?

What is the error output in the debug window?

“crashes” is a pretty harsh word. As @ Dave suggests, telling us exactly what you mean instead of “crashes” and showing the error message will help understand this much quicker

I encapsulated the call in a try/catch block, and get a System.Exception thrown with the following HRESULT code : 3556769792.

It gives me a stack trace, but no actual error message except Error thrown: System.Exception.

@ Derrick - Please post a small complete code sample that displays the issue.

This is a little helper class I made to represent the LED:

namespace Learning2
{
    public class LED
    {
        private OutputPort _LED = null;

        public LED()
        {
            try
            {
                _LED = new OutputPort(GHI.Pins.FEZCobraIII.Gpio.D5, true);
            }
            catch (Exception ex)
            {
                string error = ex.ToString();
            }
        }

        public void On()
        {
            _LED.Write(false);
        }

        public void Off()
        {
            _LED.Write(true);
        }

    }
}

I instantiate it here:

namespace Learning2
{
    public class Program
    {

        protected static LED _LED = new LED();
        protected static SerialCommunicator _serialCommunicator = null;

        public static void Main()
        {
            Debug.Print(Resources.GetString(Resources.StringResources.String1));
            _serialCommunicator = new SerialCommunicator();
            _LED.Off();
            //_LED.On();

            ThreadStart messageHandler = new ThreadStart(_serialCommunicator.MessageFromBrain);
            Thread messageHandlingThread = new Thread(messageHandler);
            messageHandlingThread.Start();

        }
    }
}

It crashes in the constructor of the LED class, regardless of the pin I chose.

That’s why I suspect the issue is me being stupid and plugging the wire into the wrong pin now.

Funny thing it worked before I took ports D0 and D1 for UART communication.

@ Derrick - Put a Thread.Sleep(Timeout.Infinite) at the end of Main.

It still throws the exception. It never reaches the Thread.Sleep call. The exception is thrown here:

        public static void Main()
        {
            Debug.Print(Resources.GetString(Resources.StringResources.String1));
            _serialCommunicator = new SerialCommunicator();
            _LED.Off();  //EXCEPTION THROWN HERE
            //_LED.On();

            ThreadStart messageHandler = new ThreadStart(_serialCommunicator.MessageFromBrain);
            Thread messageHandlingThread = new Thread(messageHandler);
            messageHandlingThread.Start();

            Thread.Sleep(Timeout.Infinite);

        }

Sorry…it was a bug in my code…I resolved.

I was trying to instantiate a new OutputPort on the same GPIO pin twice.