Jorge Ramírezbryan costanichAdrian Stevens
Published © MIT

Expanding IO Ports of a Netduino with an MCP23008

Sometimes you run out IO ports on your main prototype board. Netduino works seamlessly with different IO expanders, like an MCP23008.

BeginnerFull instructions provided1 hour1,267

Things used in this project

Hardware components

Netduino
Wilderness Labs Netduino
×1
Breadboard (generic)
Breadboard (generic)
×1
LED (generic)
LED (generic)
×8

Software apps and online services

Visual Studio 2015
Microsoft Visual Studio 2015

Story

Read more

Schematics

Circuit diagram

Code

App.cs

C#
using Microsoft.SPOT;
using Netduino.Foundation.ICs.IOExpanders.MCP23008;
using System.Threading;

namespace Blinky_MCP23008
{
    public class App
    {
        static MCP23008 _mcp = null;

        public App()
        {
            InitializePeripherals();
        }

        protected void InitializePeripherals()
        {
            _mcp = new MCP23008(39);
        }

        public void Run()
        {
            // create an array of ports
            DigitalOutputPort[] ports = new DigitalOutputPort[8];
            for (byte i = 0; i <= 7; i++)
            {
                ports[i] = _mcp.CreateOutputPort(i, false);
            }

            while (true)
            {
                // count from 0 to 7 (8 leds)
                for (int i = 0; i <= 7; i++)
                {
                    // turn on the LED that matches the count
                    for (byte j = 0; j <= 7; j++)
                    {
                        ports[j].State = (i == j);
                    }

                    Debug.Print("i: " + i.ToString());
                    Thread.Sleep(250);
                }
            }
        }
    }
}

Program.cs

C#
using System.Threading;

namespace Blinky_MCP23008
{
    public class Program
    {
        public static void Main()
        {
            App app = new App();
            app.Run();
            Thread.Sleep(Timeout.Infinite);
        }
    }
}

Credits

Jorge Ramírez

Jorge Ramírez

74 projects • 76 followers
Developer advocate for Wilderness Labs.
bryan costanich

bryan costanich

70 projects • 55 followers
Adrian Stevens

Adrian Stevens

70 projects • 45 followers

Comments