Back to basics

I have this code for the cerbuino

        void ProgramStarted()
        {
            Debug.Print("Program Started");
            OutputPort led = new OutputPort(Cpu.Pin.GPIO_Pin13, true);
        }   

I shove an led in the digital pin 13 and one into ground

I checked both ways, its not a faulty led. its not in the wrong orientation, and I don’t understand how I cannot figure out how to turn on a damn LED!

Update: Error

first, when the ProgranStart method is exited, the Output goes out of scope, and gets disposed.

Also, check to see if the pin that is giving you the exception is not already in use.

1 Like

@ Mike - I want to power the pin that would be digital pin 13 on the arduino

This is on the cerbuino bee.

Would that be the gpio 13 pin?

Check out this doc on locating I/O pins:

https://www.ghielectronics.com/docs/6/locating-ios

Also this, on Digital Outputs:

https://www.ghielectronics.com/docs/7/digital-outputs

You need to start with the schematic for the Cerbuino Bee (or whatever board you may be working with), and determine what pin you’re dealing with. Schematic for the Cerbuino Bee is here:

http://www.ghielectronics.com/downloads/schematic/FEZ_Cerbuino_Bee_SCH.PDF

I’ve snipped the relevant section and highlighted what you need to look for, in the attached pic.

Once you have the pin info (in this case, PB3, you can create your digital output like so in Program.cs (note that you’ll need to add a reference to the GHI.Pins assembly for GHI.Pins.Generic.GetPin to resolve):

using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Microsoft.SPOT.Hardware;

namespace Pin13Blink
{
    public partial class Program
    {
        static OutputPort blinkPort;
        bool isLEDOn = false;

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            blinkPort = new OutputPort(GHI.Pins.Generic.GetPin('B', 3), isLEDOn);

            GT.Timer timer = new GT.Timer(1000);
            timer.Tick += timer_Tick;
            timer.Start();

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

        void timer_Tick(GT.Timer timer)
        {
            isLEDOn = !isLEDOn;
            blinkPort.Write(isLEDOn);
        }
    }
}

Note that for a pin PB3, you don’t include the “P”, and the call to GetPin takes a Char, not a string, so the letter portion of the pin label should be in single quotes, not double quotes.

Hope that helps.

4 Likes

@ devhammer - YOU ARE AWESOME
:dance:
It works!!!

Im surprised how many lines this took but ohwell, atleast you had intellisence with the code

My pleasure. Next time, though, you get to look up the pin on the schematic. :smiley:

While I included the entire Program.cs, pretty much all but 5 lines of code is boilerplate. Or 11 lines if you include all the timer code (including the curly braces).

Not a lot of code at all, given that you’re doing non-Gadgeteer stuff inside a Gadgeteer project. :wink:

what, two lines is hard ?

     static OutputPort blinkPort;
<snip>
          blinkPort = new OutputPort(GHI.Pins.Generic.GetPin('B', 3), isLEDOn);