4 comments on “Arduino port expansion

  1. i would like to have some help with the mcp23017 with the sketch ….
    if there is any example on how to do with input on A side and ouput on B side

    • Denis, as you can see my example has the outputs on port A and the inputs on port B. To switch that around, you could just swap the addresses for the IO Direction Registers and Data Registers. For example, so set the IO Direction:

      // This time, set Port B as outputs
      Wire.beginTransmission (addr1);
      Wire.write (0x01); // IO direction register port B
      Wire.write (0x00); // set all as outputs
      Wire.endTransmission ();

      // and set Port A as inputs
      Wire.beginTransmission (addr1);
      Wire.write (0x00); // IO direction register port A
      Wire.write (0xFF); // set all bits as inputs
      Wire.endTransmission ();

      When reading or writing data, change my code by swapping all occurrences of the Port A Data Register (0x12) and the Port B Data Register (0x13).

      You can also look at my EEPROM programmer project, where I’m using the 23017s in more sophisticated ways.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s