PCF8574T Module IO Expansion Module For Arduino - on Spark

First off - this has to be said - i’m utterly new to Particle/Spark development, and my knowledge of code in general is quite limited, so please bear that in mind :smiley:

Right then - the project that I have in mind requires a multitude of digital IO pins for a load of switches and LEDs - 8 digital IO just isn’t going to cut it. I’ve stumbled across this particular bit of kit PCF8574T Module IO Expansion Module For Arduino and it touts itself as a stackable 8-pin IO expansion running off of i2c.

The only example code that I have been able to find (towards the bottom of that page, although that code is replicated elsewhere on the internet) sets P0-P7 on the expansion board to a high signal, and it’s doing that through a Wire.write(0xff)

I, on the other hand, could do with P0-P7 being initialised as individual pins (in both input and output modes) - has anyone had any experience with this particular IO board, and has anyone done individual pin addressing on it?

Any assistance in this one will be sincerely appreciated.



You can also use the analog pins as digital pins if you are ok with that idea.

What exact problem are you having with the module?

I’m sorry if I am not making much sense - I’ve been awake now for 23 hours now with no sign of sleep in sight as yet - damn you, Insomnia >_<

Yeah, I was planning on using some of the analog pins as digital pins through a voltage latch in code (0-1.5v = 0 // 1.51v-3.3v = 1 or something similar) but I’m still going to need more pins ! Too many inputs, perhaps, but the number of physical switches and individual LEDs in the project require individual discrete inputs.

< edit > Yeah, I now know that I can do a digitalRead(A1) or whatnot as well, which would make life simpler when it comes to hooking switches up to analog pins - but the base issue remains the same - not enough IO pins :smiley: < /edit >

I’ve found the datasheet for the PCF8574/A chipset, and I have figured out that each expansion module is addressable (and set through the DIP switches) but what I seem to be missing somewhere is the addressing for the individual pins (the only two known commands I can find at the moment are 0xff (for all pins thrown HIGH) and 0x00 (for all pins dropped LOW)

Am I missing something fundamental and basic in my sleep-deprived state?

@SteveBlackLight, from the looks of it, each bit in an 8-bit byte represents a pin. By adding and subtracting bit values to a byte variable, you build the value you need to write to each pin on the board. In coding, it is called bit masking. For example:

#define PIN1  0B00000001  // binary value of the first pin
#define PIN2  0B00000010  // binary value of the second pin
#define PIN3  0B00000100  // third pin
#define PIN4  0B00001000  // fourth pin
#define PIN5  0B00010000  // fifth pin
#define PIN6  0B00100000  // sixth pin
#define PIN7  0B01000000  // seventh pin
#define PIN8  0B10000000  // eighth pin

To write pins 1, 5 and 8 at the same time:

byte OUT = PIN1 + PIN5 + PIN8;

To turn of just pin 5 but leave the others on:


A better form would use logical operators (AND, OR, XOR) instead of add and subtract but this is to illustrate the point. :smiley:

1 Like

@peekay123 - After getting a couple of hours sleep and “recharging the batteries” a little, I’ve just seen your post, and now I have some brainpower, your suggestion looks more than likely.

Many thanks to both yourself and @kennethlimcp for putting some brainpower into this for me :slight_smile:


you should also be able to read from the module to find what its set as, you then change the value to turn on or off each bit.