By dave | August 10, 2018

Using Arduino Pins and Io Expanders at the same time

Sometimes there is a need for more IO than can be catered for using an single set of pins, even on the MEGA, or maybe you just want to combine Arduino pins with some pins on an PCF8574 IO expander chip.

In this case IoAbstraction now supports that, you create an abstraction of type MultiIoAbstraction. See the sketch that has Arduino pins and PCF8574 on the same IoAbstraction in the packaged examples.

We have an example that you can look at, build the circuit exactly as per the standard i2c expander example, but this time this sketch also switches on and off the built in LED pin as well, showing it is possible to use both built in pins and the expander at the same time.


Using MultiIoAbstraction

Step 1 create an instance globally, telling it how many pins to allocate to Arduino (defaults to 100):

MultiIoAbstraction multiIo(100);

Step 2 in the setup method register additional devices. You can add up to 7 more IO expanders, and the pins follow on sequentially.

void setup() {
    Wire.begin();
    // add an 8574 expander on address 0x20 allocating 10 pins (IE from 100-109)
    multiIo.addExpander(ioFrom8574(0x20), 10);
    // and the next follows sequentially with another 10 pins, from 110-119,
    multiIo.addExpander(ioFrom8574(0x20), 10);

    // other setup tasks..    
}

Then use it just like you would any other IoAbstractionRef.

Go back to the IoAbstraction page

Other pages within this category

This site uses cookies to analyse traffic, and to record consent. We also embed Twitter and Youtube content on some pages, these companies have their own privacy policies.

Our privacy policy applies to all pages on our site

Should you need further guidance on how to proceed: External link for information about cookie management.