• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomeArduinoShieldsIncrease the number of IO pins using I/O Expander ...
Previous Next

Increase the number of IO pins using I/O Expander Shield for Arduino

Posted by: Alvin Jin , April 13, 2014

[vc_row][vc_column width=”1/1″][vc_column_text]


图片1
I/O Expander shield is a shield used to expand the number of I/Os of an Arduino Uno. It is based on the chipset MCP23017. The chipset MCP23017 communicates with Arduino Uno through I2C interface. It adds GPIOA and GPIOB, a total of 16 I/Os. There are two LEDs and two buttons on the shield. User can decide if they want to use the built-in LED/buttons or not by using the 4-bit DIP switch.

[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”Features” tab_id=”1397390811-1-46″][vc_column_text]

  1. 16 bidirectional I/O ports. Default is input state.
  2. High-speed IIC interface (MCP23017): 100kHz, 400kHz, 1.7MHz
  3. Three hardware address pins allow up to eight devices on the bus
  4. Configurable interrupt output pin: can be configured for active-high (output), active-low (output) or open-drain (output)
  5. INTA and INTB can be configured to work independently or jointly
  6. Configurable interrupt sources: the interrupt changes according to the configured register defaults or pin level changes
  7. External reset input
  8. Low standby current: 1μA (max)
  9. Operating voltage:
    1. 1.8V to 5.5V (-40 ° C to +85 ° C)
    2. 2.7V to 5.5V (-40 ° C to +85 ° C)
    3. 4.5V to 5.5V (-40 ° C to +125 ° C)

[/vc_column_text][/vc_tab][vc_tab title=”Parts List” tab_id=”1397390811-2-32″][vc_column_text]

  1. 1 x [bigcommerce link=”/arduino-uno-compatible-usb-board-r3/” target=”_blank”]Arduino UNO[/bigcommerce]
  2. 1 x I/O Expander Shield

[/vc_column_text][/vc_tab][vc_tab title=”Code” tab_id=”1397392325545-2-1″][vc_column_text]

#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
const byte  IODIRA=0x00;            // IODIRA register
const byte  IODIRB=0x01;            // IODIRB register

void setup()
{
  //Send settings to MCP device
  Wire.begin();              // join i2c bus (address optional for master)
  Wire.beginTransmission(mcp_address);
  Wire.write((byte)IODIRA); // IODIRA register
  Wire.write((byte)0x03); // set GPIOA-0/GPIOA-1 to inputs
  Wire.endTransmission();
}

void loop()
{
  Wire.beginTransmission(mcp_address);
  Wire.write((byte)GPIOA); // set MCP23017 memory pointer to GPIOB address
  Wire.endTransmission();
  Wire.requestFrom(0x20, 1); // request one byte of data from MCP20317
  int inputs=Wire.read(); // store the incoming byte into "inputs"

  if((inputs&0x01)==0)
  {
    Wire.beginTransmission(mcp_address);
    Wire.write(GPIOA);    // address bank A
    Wire.write((byte)0x04);  // value to send GPIOA-2 HIGH
    Wire.endTransmission();
  }
  if((inputs&0x02)==0) 
  {
    Wire.beginTransmission(mcp_address);
    Wire.write(GPIOA);    // address bank A
    Wire.write((byte)0x08);  // value to send GPIOA-3 HIGH
    Wire.endTransmission();
  }
  else
  {
    Wire.beginTransmission(mcp_address);
    Wire.write(GPIOA);     // address bank A
    Wire.write((byte)0x00);  // value to send GPIOA LOW
    Wire.endTransmission();
  }
}

[/vc_column_text][/vc_tab][vc_tab title=”Testing” tab_id=”1397392385128-3-0″][vc_column_text]1. Install I/O Expander Shield onto Arduino UNO and power on,

图片2

2. Open Arduino IDE and copy the code, then upload to Arduino

图片3

3. Set all Jumpers to ON, press the button S1 and S2 respectively.

Press S1, L1 (RED) will turn on.

图片4

Press S2, L2 (GREEN) will turn on.

图片5[/vc_column_text][/vc_tab][vc_tab title=”Schematics” tab_id=”1397392598006-4-2″][vc_column_text]io expander shield SCH[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]

Tags: Shields

Share!
Tweet

Alvin Jin

About the author

One Response to “Increase the number of IO pins using I/O Expander Shield for Arduino”

  1. Log in to Reply
    David
    August 26, 2014 at 1:02 am

    Could you have a sample of code, perhaps a single pin of one of the banks acting as an output.

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors