Locating IOs

Last modified September 15, 2014

In many of the GHI Electronics tutorials and documentation, there are specific references in code referring to pin. Pins are connection pieces. They connect two or more pieces of hardware. When writing NETMF programs pins are referred to using names provided in namespaces for the hardware and contained in assemblies supplied by the hardware manufacturers.

Throughout this document, we are careful to use two different non-interchangeable terms when referring to pins: "pin name" versus "pin number."  Pin numbers are the underlying values represented by the "pin names". Their values are determined by the chip manufacturers, board designers, and the firmware. Their derivation is beyond the scope of this explanation. In general, pin numbers refer to actual physical connections to hardware. For example a socket with 6 pins will have pins numbered 1 through 6, perhaps 0 through 5, but they may be named PA1, PA2, PA3, PB1, PB2, PB3.

When using examples that use pins, unless your hardware exactly matches the hardware used in the example, you will probably need to change the pin names. If you are using the Gadgeteer level of programming, you can use socket names/numbers and module names along with Visual Studio's Intellisense to choose the correct pin names for your hardware. For NETMF or non-gadgeteer hardware, you will need to look at the labels on the board or use the hardware schematics to get the pin name and number and then find that pin in the enumerations for your device. This document will teach you how to find the pin name via an example: we will find the pin names used to connect an LED and a Button to our FEZ Cerberus mainboard.

For other manufacturers, supporting NETMF and/or Gadgeteer, or compatible devices make sure you get access to the schematic for the hardware. With GHI Electronics, our online product catalog also serves as a convenient library of public information; each product description includes (where applicable) the schematic of the device as well as other key performance critieria. We need two schematics, the one for the Cerberus board and one for the Button module. Lets start with the Cerberus board.

You can find the Cpu.Pin enum used below in the Microsoft.SPOT.Hardware library. You will also need our GHI.Pins library.

Tip

In the event that you cannot find the enumeration value that matches your pin but you do have the pin number, you can cast that number to the correct NETMF enumeration (such as Cpu.Pin) and pass that in. But make sure you have the correct pin. If you accidently use an analog output pin as an input, damage could result. Additionally, not all pins can support every feature. As you will see in later tutorials, only a few pins can support hardware PWM.

Navigate to the product Catalog from www.ghielectronics.com by clicking on the Catalog tab.

The panel on the left hand is the Catalog table of contents, click on Mainboards.

Locate and click on the Cerberus Mainboard icon.

On the Cerberus Mainboard page, click on the Resources tab.

Find the link to the Schematic and click on it.

On the Cerberus schematic you find the Green LED and it's labeled with PC4. Your C# code, after adding a reference to our GHI.Pins library, for example, will be:

OutputPort LED = new OutputPort(GHI.Pins.Generic.GetPin('C', 4), true);

Notice the call to Generic.GetPin(). This function is provided for our boards that are not based on one of our System on Modules.

If you do have a board that is based on one of our SoMs, then you can find that SoM under the GHI.Pins namespace. For example, the below code will create a port using the PB2 pin on the G400. Make sure to consult the schematic as detailed above for information on finding the needed pin.

OutputPort LED = new OutputPort(GHI.Pins.G400.PB2, true);

Looking at the Cerberus schematic again, we see all kinds of pin names associated with Socket 2. Remember socket 2 is where we are plugging in the Gadgeteer Button module.  Time to go look at the schematic for the Button module. Using the same scheme as above navigate Catalog->Modules->Button->Resources->Schematic.

Examing the schematic we see that the button assembly is attached to the socket pin number 3, looking back at the Cerberus mainboard schematic for socket 2 shows us the pin number 3 is labeled with pin name PA6.  So an example reference in C# would be:

InputPort Button = new InputPort(GHI.Pins.Generic.GetPin('A', 6),false,Port.ResistorMode.PullUp);
Leave feedback about this document.
Let us know if the information presented here was accurate, helpful and if you have any suggestions.
Leave feedback about this document.
Let us know if the information presented here was accurate, helpful and if you have any suggestions.

* Indicates required fields.
This form is only for feedback not support.
Review our how to find information guide on locating helpful resources.