Toll-Free Customer Support 24/7

IO Expander Board MCP23017 IC

#include <Wire.h>

 

const byte  mcp_address=0x20;      // I2C Address of MCP23017 Chip

const byte  GPIOA=0x12;            // Register Address of Port A

const byte  GPIOB=0x13;            // Register Address of Port B

 

void setup()

{

  //Send settings to MCP device

  Wire.begin();              // join i2c bus (address optional for master)

 

  // IOCON.BANK defaults to 0 which is what we want.

  // So we are using Table 1-4 on page 9 of datasheet

  

  Wire.beginTransmission(mcp_address);

  Wire.write((byte)0x00); // IODIRA register

  Wire.write((byte)0x00); // set all of bank A to outputs

  Wire.write((byte)0x00); // set all of bank B to outputs 

  Wire.endTransmission();

  

}

 

void loop()

{

  Wire.beginTransmission(mcp_address);

  Wire.write(GPIOA);      // address bank B

  Wire.write((byte)0xFF);  // value to send - all HIGH

  Wire.endTransmission();

  

  delay(500);

 

  Wire.beginTransmission(mcp_address);

  Wire.write(GPIOA);    // address bank B

  Wire.write((byte)0x00);  // value to send - all LOW

  Wire.endTransmission();

  

  delay(500);

   Wire.beginTransmission(mcp_address);

  Wire.write(GPIOB);      // address bank B

  Wire.write((byte)0xFF);  // value to send - all HIGH

  Wire.endTransmission();

  

  delay(500);

 

  Wire.beginTransmission(mcp_address);

  Wire.write(GPIOB);    // address bank B

  Wire.write((byte)0x00);  // value to send - all LOW

  Wire.endTransmission();

  

  delay(500);

}

IO Expander Board MCP23017 IC

Back to top