Using the GPIO with a switch MCP23008

I feel retarded for even posting this, but I’m a bit lost here. I have some experience with Arduino scripting, but I have none when it comes to i2c. How do I program the gpio pins on this board so that I can turn on/off the relays in a certain sequence or simply turn on/off one relay with one switch? I can’t figure it out, even through the examples on github, how to specify which pins I want to be inputs and outputs through i2c. The examples have code for changing all the pins at once, but not each individually. Thanks for any help!

Hi Thomas,
You can use this lib

turning on off any io is super easy.

  1. set all io as output
    // Select IODIR register
    Wire.write(0x00);
    // All pins are configured as output
    Wire.write(0x00);
  2. set the bit
    so there are 8 ios. each io is controlled by a bit
    for example if you want to control 4 io
    0b00001000 – this will set 4th io high
    now lets say you want to turn on relay 5
    before doing that you will need to read the existing io states
    once you do that
    existing io state | 0b00010000 ( or operator)

hope this helps

You might also take a look at this library:

It was developed for Particle but a port to your Arduino module should be simple. It allows you to specify the direction of the I/O lines as needed.

Thanks! I have been able to figure out how it works now based off of your answers.