So what do you do if the inputs and outputs on your Arduino are not enough for you and you need to add more.  In this episode we talk about just one of the ways.  We introduce you to a 16 bit I/O chip that runs over i2C.  You can put up to 8 of these chips on the i@c bus to add 112 I/O ports to your Arduino using just 2 pins on the Arduino itself.

The chip we demonstrate is a Microchip MCP23017.  You can get that chip from our online store at tech-zen.tv.

Downloads

HD Apple HD Apple SD Audio MP3

Basic MCP23017 Input Test

/*######################### 23017 Basic Input Test ############################
       This is a basic program that scans the pins on the 23017 and outputs
       what the 23017 chip is sending out.
 
   From: Mike Myers (http://mikemyers.me)  @netnutmike
       Let's Make It Episode 36 at http://tech-zen.tv
       
       http://tech-zen.tv
       
       For the sample code, show notes, contact information and many more
       videos, visit the show page at http://tech-zen.tv/letsmakeit

       Please subscribe to our YouTube channel or our netcasts at any of
       your favorite netcast / podcast outlets.

       We normally record Let's Make It live on Monday evenings around
       9pm eastern. You can watch it live by going to tech-zen.tv and clicking
       the live link at the top of the page.

       We also have a community setup for our viewers and listeners. You can
       join the community by going to community.tech-zen.tv.

       We love input on what you would like to know or if you have an idea for
       a new Let's Make it episode, you can contact us via email or phone at
       the show information page.
################################################################################*/

#include <Wire.h>
#include <MCP23017.h>

bool cled = true;

MCP23017 GPIOchip;

void setup()
{
  Serial.begin(9600); // set up serial
  Serial.println("Serial Started");

  Wire.begin();           // Wire must be started!
  GPIOchip.begin(B000);  // Address set to zero.
  GPIOchip.init();

  GPIOchip.pinMode(0,  OUTPUT);
  GPIOchip.pinMode(1,  INPUT);
  GPIOchip.pinMode(2,  INPUT);
  GPIOchip.pinMode(3,  INPUT);
  GPIOchip.pinMode(4,  INPUT);
  GPIOchip.pinMode(5,  INPUT);
  GPIOchip.pinMode(6,  INPUT);
  GPIOchip.pinMode(7,  INPUT);
  GPIOchip.pinMode(8,  INPUT);
  GPIOchip.pinMode(9,  INPUT);
  GPIOchip.pinMode(10,  INPUT);
  GPIOchip.pinMode(11,  INPUT);
  GPIOchip.pinMode(12,  INPUT);
  GPIOchip.pinMode(13,  INPUT);
  GPIOchip.pinMode(14,  INPUT);
  GPIOchip.pinMode(15,  INPUT);
}

void loop()
{
  word buttonStatus = GPIOchip.digitalWordRead();
  //Serial.println(buttonStatus,BIN);
  delay(100);
  Serial.println(GPIOchip.digitalRead(15));
  GPIOchip.digitalWrite(0, !cled);
  cled = !cled;
}