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.

EasyFull instructions provided1 hour261

Things used in this project

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

10 projects • 12 followers
bryan costanich

bryan costanich

10 projects • 12 followers
Adrian Stevens

Adrian Stevens

10 projects • 9 followers

Comments