PCF8574 Remote 8-bit I/O expander for I2C-bus
Vendor's Description:
Description:
If you're ever in need of additional digital inputs or outputs then this chip may be an answer to your prayers. It only requires two connections from your microcontroller (the I2C bus wires) and it provides you with 8 pins that can be configured individually to be input or output.
What's great about this chip is that if you need even more inputs or outputs you can just add another one of these without the need for extra connections to your microcontroller - I2C rocks! The hardware I2C slave address can be configured to any of 8 different addresses meaning you can have a total of 8 of these chips on the same I2C bus.



Cool!I have some 7.1
Cool!
I have some 7.1 digit-led's, but have never used them as it would take too many outputs, even when som other chips was put in front.
But as I read it, I can just put one of these in front of every 7.1, and then control a whole row of these with just one out?
Halelulja, old-school-displays, here I come!!
/ Frits
Use display driversdrivers
You could do that... Or you could get yourself a handfull of 4511 chips. It's a display driver that can convert a 4-bit number to the signals a 7-segment display needs. It has build-in latches to keep digit on the display, even if you turn off or change the input. What you do is:
Connect the 4-bit input of 4 4511s to bit 0-3. Bit 4-7 is connected to the EL inputs of the 4 chips, one for each input. You then do:
Set the first digit on pin 0-3, set bit 4 low and 5-7 high to turn EL low on the first chip and high on the other three. This will make the first display show the digit. Then you turn bit 4 high. This will store the digit in the latches of the 4511. Then you select the next digit on bit 0-3, bit 5 low and 4,6,7 high. Then turn bit 5 high to store the second digit on the second display etc. Did this make sense? The bottom line is, that by using some external drivers, you can connect 4 displays to an 8-bit output, instead of just 1. Read about the 4511 here: http://www.doctronics.co.uk/pdf_files/4511.pdf
That's good to know. I just
You only need to connect the
You only need to connect the I2C bus wire pins (SDA and SCL) of your microcontroller to each of the PFC8574 chips corresponding SDA and SCL pins and then you need some pull-up resistors on both the wires (I used 82k resistors for my LEGO compatible sensor).
This means you can control eight LED segments (plus any other I2C hardware not using the same fixed address prefix as the PCF8574) with just two pins on the microcontroller. By combining the segment drivers JKA mentioned with the PCF8574 chips, you can control as much as 32 LED segments so a scrolling effect would be in its place :-).
- Jimmy
Wow, and this chip is only
Wow, and this chip is only $1.58 from what I'm seeing online. Nice, I'll have to pick some up. Although, looking at the two options they list (PCF8574N and PCF8574AN) I can't tell what the difference is. I'm comparing the datasheets for each, and they're not identical but I don't see functionally how they differ. Any experience with that? Would both versions work equally well for this type of use, or is there one in particular we should choose?
Dan
I know one difference is the
I know one difference is the fixed part of the I2C address and that really tricked me in the beginning since I had bought the other version than the one used in the tutorial I was reading :-). Other than that I don't know of any differences.
The price I listed is from the Danish shop where I normally do my online shopping. I totally forgot to check other online stores. Thanks for the info - I'll update the price right away :-).
By the way NXP (the artist... erh... company formerly known as Philips) makes a lot of cool I2C chips. I know I'm interested in the I2C 4 channel analog to digital converter that also has a digital to analog converter onboard.
- Jimmy
Question --Servos...
Any thoughts about using this with servos? Can a pulsed signal be sent using the write command? --is it too much to ask for some code (for a picaxe)?
--Actually, I am curious about "sending" or "receiving" any of the picaxe codes. I.e. serout/in pulsin etc...
Handy
This chip is driving me nuts!
Config then send, just a guess.
The PCF8574 appears to need to be configured to an address, by tying the pins A2, A1, and A0 either high or low according to what you want. The PCF8574A starts at address 0111xxx0 where xxx depends on what you wire A2,A1,A0 as. The PCF8574 starts at address 0100xxx0, shown on page 8 Figure 9. What I read on the PICAxe I2C tutorial page 4 is some commands you are probably already familiar with, working with the I2C EPROM before. It looks like the writei2c command can be used, as in :
i2cslave %0111xxx0, i2cslow, i2cbyte ' for PCF8574A at address 0111xxx0
writei2c 0, (00000001,00000010,00000100,00001000,00010000,00100000,01000000,10000000,11111111)
I'd guess that code to run each of the IO pins individually on and off at a rate near 12 kHz, to lastly leave them all on til something else was sent. You could have a meter check the last, or have a slow loop that turned on each pin in turn for a second or so, before going on to address the next. The data sent might need a % in from as in %00001000 as that may be what the PICAxe uses.The readi2c could be used if you wanted to read what the pins are set from some external sensors or switches.
@robo
Hey, thanks again for the code -It worked great!... and did need the "%"...
At any rate, I noticed that it doesn't latch. It seems that it sets it's pins high only for a very short time following the write command. If I run a good loop, I can keep a LED on, if there is any pause, I only get a short blink. -- any thoughts?
Latched outputs
I was guessing that the latched outputs meant that they stay set as the last data byte sent. It appears that they only stay "latched" for roughly 9 clock pulses at 100 (or 400) kHz from Figure 10 (page 9). I kinda wonder what sending just one byte would do, to see if it would hold it longer, but would really only expect it to hold it for that 9 100kHz clocks, after it had been sent. Something like :
i2cslave %0111xxx0, i2cslow, i2cbyte ' for PCF8574A at address 0111xxx0
writei2c 0, (%00000001)
What you have done already may be the only answer possible, to get a sustained high or low on any one pin. If you divide up 100 kHz by 9 first, you get 11 kHz, which inverts to 9 microseconds for the time it takes for holding 1 byte. It might be possible to send out servo pulses with 9 usec resolution, which would give 11 different servo positions between 1 and 2 ms. Or if shifting to 400 kHz data rate, there should be a 4x resolution, for 44 or so positions. What I'm picturing is sending a continuous data stream for 2 ms of what you want 8 servos to be positioned at, then resting 20 ms to do other chores, then sending another 2 ms of data. That would be 22 bytes or so at 100 kHz, or 88 bytes sent at 400 kHz. The first 11 (at 100 kHz) would be all ones to get to the minimum 1 ms for the servo, but the rest could be whatever wanted for an individual servo, up to another 11 ones for the far end of the servo swing. Think that might be right, don't have a way of trying it out.