Skip to main content

Input/Output (IO)

IO is a big part of what makes Meadow powerful. Meadow boards expose a wide variety of ways to control and interact with external peripherals and hardware via Input/Output (IO) ports.

Pins + Connectors

IO ports are exposed physically on the board via pins and other connectors. These physical connections can be accessed from your application code to read sensors, listen to button presses, light LEDs, drive motors, communicate with other systems, and lots more.

Many of the pins on a Meadow board are multifunction, which means that they can serve as different types of IO, depending on how they're configured in code.

Types of IO

Meadow IO ports are generally divided into two categories: Digital and Analog. There is also another type of IO, Power, which is discussed in the power guide.

Digital and analog refer to the type of electrical signal used; either HIGH/LOW for digital, or a range of voltages for analog, and they're used for different things.

Digital IO

Digital IO is often referred to as General Purpose, Input/Output or GPIO.

Digital ports can be set to be HIGH (powered at 3.3V), or LOW (grounded at 0V) which correspond to digital 1 and 0, respectively. They can also be setup as input ports which can read signal inputs to know if they're HIGH, LOW, and can also raise notifications on change, via interrupts.

For more information, see the Digital IO guide.

Digital Communications Protocols

Additionally, the digital ports have built-in support for a host of different types of common digital communication protocols including:

  • I2C (Inter Integrated Circuit)
  • SPI (Serial Peripheral Interface)
  • UART (Serial)

Pulse-Width-Modulation (PWM)

Additionally, digital output ports can be used to generate a Pulse-Width-Modulation (PWM) signal, which approximates an intermediate voltage between LOW or HIGH by switching between ON and OFF very quickly. PWM signals are frequently used to control the brightness of LEDs, as well as serve as the control signal for precision motors such as servos and stepper motors.

For more information, see the PWM guide.

Analog IO

Analog ports can operate at a range of voltages between 0V and 3.3V, which is especially useful when reading analog sensors that supply their data as a voltage reading, rather than a digital signal. For instance an analog temperature sensor that is able to detect temperatures from 0ºC to 100ºC might output a voltage of 1.6V (halfway between 0V and 3.3V) for 50º.

For more information, see the Analog IO guide.

I/O Power Tolerance

Important:

Both the digital and analog I/O on the Meadow F7 board nominally operate at a range of 0V to 3.3V. However, when they are configured for digital operation, they are 5V tolerant; meaning that they can accept input voltages up to 5V. When they are configured for analog operation, they are only 3.3V tolerant, and any input voltages higher than that, may burn out that I/O, and or damage the chip.

For reading analog voltages higher than 3.3V, see the analog I/O guide

F7 Feather IO Pinout

GPIO ports are available via pins (as well as the onboard LED) on the Meadow F7 Feather, and many of these pins are actually overloaded to support multiple functions, as shown in the below illustrations.

Meadow F7v2 Feather Pinout

Meadow F7v2 pinout diagram showing pins used for multiple functions

Meadow F7v1 Feather Pinout

Meadow F7v1 pinout diagram showing pins used for multiple functions

The function that they serve depends on how they are configured when a port is instantiated on one of the pins. For instance, pin D00 can be configured to be used a digital input or output, or as the RX (receive) half of a Serial UART port available as "COM4".

Pins, Ports, and ChannelInfos

When working with IO in Meadow, there are three different terms/concepts to be aware of:

  • IPin - Represents a physical connection point on a device, such as pin D01.
  • IPort - Represents the underlying IO feature that allows communication, such as a Meadow.Hardware.DigitalInputPort which reads digital input signals on a particular pin.
  • IChannelInfo - Describes the capabilities of a particular pin or port, for instance, whether or not a pin supports digital interrupts (a notification when the state changes).

IIOController

A device that supports IO (such as the F7 Feather device itself, or an external IO Expander) is represented by an IIOController, which exposes a Pins collection of IPin objects.

IO Devices are self describing with a mapping of Device > Pins > Channels. For instance, the following Meadow sample code enumerates all the pins and what type of IO is possible for each pin:

foreach(var pin in Device.Pins.AllPins) {
Console.WriteLine("Found pin: " + pin.Name);
foreach (var channel in pin.SupportedChannels) {
Console.WriteLine("Contains a " + channel.GetType()
+ "channel called: " + channel.Name + ".");
}
}

Here's an excerpt from the output the above code returns:

Found pin: A05
Contains a Meadow.Hardware.DigitalChannelInfochannel called: PC1.
Contains a Meadow.Hardware.AnalogChannelInfochannel called: ADC1_IN11.

Found pin: D00
Contains a Meadow.Hardware.DigitalChannelInfochannel called: PI9.
Contains a Meadow.Hardware.UartChannelInfochannel called: UART4_RX.

Found pin: D01
Contains a Meadow.Hardware.DigitalChannelInfochannel called: PH13.
Contains a Meadow.Hardware.PwmChannelInfochannel called: TIM8_CH1N.
Contains a Meadow.Hardware.UartChannelInfochannel called: UART4_TX.

With these IChannelInfo objects, the IO is also self-documenting, and you can see what kind of ports are available from each pin without having to refer to the IO pinout diagram.

Creating Ports

When interacting with peripherals, the actual control and interaction happens via IPort objects, which are typically created via the device from one or more pins:

IDigitalOutputPort redLED = Device.CreateDigitalOutputPort(Device.Pins.OnboardLedRed);

Meadow F7 Feather Pinout Table

The following table lists all the accessible pins on the Meadow F7 Feather dev board and their functions:

Meadow Pin NameMCU Pin NameDigital ChannelAnalog ChannelPWM Timer ChannelInterrupt Group
A00PA4PA4AC1_IN44
A01PA5PA5ADC1_IN55
A02PA3PA3ADC1_IN33
A03PA7PA7ADC1_IN77
A04PC0PC0ADC1_IN100
A05PC1PC1ADC1_IN111
SCKPC10PC10
MOSIPB5PB55
MISOPC11PC1111
D00PI9PI99
D01PH13PH13
D02PC6PC616
D03PB8PB838
D04PB9PB949
D05PC7PC727
D06PB0PB0ADC1_IN830
D07PB7PB727
D08PB6PB616
D09PB1PB1ADC1_IN941
D10PH10PH101
D11PC9PC949
D12PB14PB14114
D13PB15PB15215
D14PG3PG33
D15PE3PE33
OnboardLedRedPA2PA23
OnboardLedGreenPA1PA12
OnboardLedBluePA0PA01

Meadow F7v2 Feather Pinout Table

Meadow Pin NameMCU Pin NameDigital ChannelAnalog ChannelPWM Timer ChannelInterrupt Group
A00PA4PA4ADC1_IN44
A01PA5PA5ADC1_IN55
A02PA3PA3ADC1_IN33
A03PB0PB0ADC1_IN80
A04PB1PB1ADC1_IN91
A05PC0PC0ADC1_IN100
SCKPC10PC10
COPIPB5PB55
CIPOPC11PC1111
D00PI9PI99
D01PH13PH1313
D02PH10PH101
D03PB8PB838
D04PB9PB949
D05PB4PB44
D06PB13PB1313
D07PB7PB727
D08PB6PB616
D09PC6PC616
D10PC7PC727
D11PC9PC94
D12PB14PB14114
D13PB15PB15215
D14PB12PB12
D15PG12PB12
OnboardLedRedPA2PA232
OnboardLedGreenPA1PA121
OnboardLedBluePA0PA010

Meadow.Foundation

When building Meadow applications, most of the time, you'll use high-level peripheral drivers via Meadow.Foundation instead of interacting with ports directly, as we'll explore in the next section.

Next - Meadow.Foundation