Software apps and online services
This project shows you how to use a MCP23008 I/O port expander to extend peripheral support seamlessly. We'll control eight (8) LEDs as an example for using all pings as Output Ports using only two (2) control wires. You'll code as if the LEDs are connected directly to Meadow using Meadow.Foundation's Unified GPIO Architecture.
The MCP23008 chip is an 8-bit (8 port) digital I/O expander chip that communicates over I2C. It provides eight (8) IP ports and can be used to add additional digital input and output ports to an MCU. It can also be combined with up to seven (7) additional MCP23008 chips, providing up to sixty four additional ports.
To connect the MCP23008 chip, consider the Pin Datasheet below.
MCP23008 is a common integrated circuit in the hardware world and is the typical interface chip for hardware such as I2C LCD backpacks. You can read more here.
Meadow.Foundationa platform for quickly and easily building connected things using.NET on Meadow. Created by Wilderness Labs, it's completely open source and maintained by the Wilderness Labs community.
If you're new working with Meadow, I suggest you go to the Getting Started w/ Meadow by Controlling the Onboard RGB LEDproject to properly set up your development environment.Using MCP23008 pins as output portsStep 1 - Assemble the circuit
For this project, wire up your breadboard and Meadow as shown in the Fritzing diagram:
Create a new Meadow Application project in Visual Studio 2019 for Windows or macOS and name it McpLeds.Step 3 - Add the required NuGet packages
Right-click on your McpLeds project and click Manage NuGet Packages. In the Browse tab, search for Meadow.Foundation.ICs.IOExpanders.Mcp23x08 and click Install to add it to your project.
Alt-click on your McpLeds project in the Solution Explorer, and click Add => Add Nuget Package to open the NuGet Package window. Search for Meadow.Foundation.ICs.IOExpanders.Mcp23x08 and click Install to add it to your project.Step 4 - Write the code for McpLeds
Copy the following code below:
public class MeadowApp : App<F7Micro, MeadowApp>
mcp = new Mcp23x08(Device.CreateI2cBus(), true, true, true);
leds = new List<Led>();
foreach(var led in leds)
led.IsOn = true;
foreach (var led in leds)
led.IsOn = false;
Contructor, you can see how the
Mcp23x08 gets initialized, passing all Address pins true since they're all connected to 3V3, and then we populate a list of LEDs using all the general IO ports calling
CycleLeds(), the app steps in an infinite while loop, and turns all LEDs on in one foreach, and the next foreach it turns them off.
Click the Run button in Visual Studio. It should look like to the following GIF:
This project is only the tip of the iceberg in terms of the extensive exciting things you can do with Meadow.Foundation.
- It comes with a huge peripheral driver library with drivers for the most common sensors and peripherals.
- The peripheral drivers encapsulate the core logic and expose a simple, clean, modern API.
- This project is backed by a growing community that is constantly working on building cool connected things and are always excited to help new-comers and discuss new projects.