Results 1 to 10 of 10

Thread: PCF8574 i2c 8-bit IO Expanders driving LEDs

  1. #1
    Moderator
    Join Date
    Mar 2008
    Location
    Western Australia
    Posts
    11,230

    Post PCF8574 i2c 8-bit IO Expanders driving LEDs

    I started looking at the PCF8574 i2c 8-bit IO expanders as an alternative to the trusty 74HC595 shift registers. Internally the PCF8574 is really still a form of shift register but has quasi-bidirectional ports.

    Purpose was to enable me to free up 4 Output lines (3 to the 74HC595 which drives 8 x LED’s and 1 for direct drive via transistor to an indicating LED).for other needs.

    I have no problem controlling the PCF8574 and can set the outputs on and off without drama.

    What I have identified is that the “High Current” outputs of the PCF8574 are only high current for sinking current up to 25mA from devices using a Low Output state. But when using more conventional High = ON type logic (as per the PICAXE), the PCF8574 outputs can only source/supply 300uA max on a High Output. In fact the Texas Instruments datasheet shows better schematics than the Philips datasheet and shows a 100uA current source for each output.

    I would prefer to stay with the logic high for switching on the LED’s
    So that:
    1. interchangeable with the already built module using the 74HC595 to drive LED’s
    2. more conventional logic
    3. initial state on circuit energisation would not cause LED’s to flash until PCF8574 written to at program initialisation.

    I can think of a couple of options:
    1. use a BC109 type transistor as an interface from each PCF8574 to drive the LED’s (tested on breadboard and works but more components, transistors and space required.
    2. look for a 74CXX type IC as an octal (8-bit) non inverting buffer capable of driving the LED’s (eg 74HC241 is an option - CMOS 4050 no good as low level for high current as well).

    I would be interested to see what others may have done in using the PCF8574 with conventional logic (high = on, like the PICAXE outputs) for LED or other higher current (10 to 20mA) loads.
    Last edited by westaust55; 15-05-2008 at 06:08.

  2. #2
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    20,139

    Default

    The usual trick for dealing with inverse logic for outputs ( active low turns LED on ) is to use active high logic within a program and invert the bits when setting the actual outputs. This would normally be done by holding the bits which represent the outputs in a variable then calling a routine to set the outputs, inverting them or not depending on how the hardware / program is configured.

    The problem for PICAXE programming is the often constrained memory capacity, calling output routines slows processing down and eats up available GOSUB's, and it's not well suited to individual I/O line control.

    There's no simple answer, it's one of those trade-offs which has to be accepted when choosing a PICAXE. If I were designing CPU's I'd make sure there were registers which could be set to invert every input and output line.

  3. #3
    Moderator
    Join Date
    Mar 2008
    Location
    Western Australia
    Posts
    11,230

    Default PCF8574 i2c 8-bit IO Expanders driving LEDs

    Thanks Hippy.

    Agree that the program capacity of the PICAXE range could prove to be a future limiting factor. Heck, I can use around around 10% of the available space just doing a simple test routine for some hardware I am attaching - that's before getting into anything exotic. Program otimisation will almost certainly be at the fore when I get going on more complex programs.

    Have "bitten the bullet" this evening and gone down the interfacing transistor route. Had enough spare transistors and resistors. At least that way I am consistently using a high state for ON throughout. Some of the 74xx and 4xxx series buffers I looked at today were the same as the PCF8574 with high sinking current capacity for a low output and minimal source current for High Output.

    So right now I have tonight built a small module with two PCF8574's which are currently driving a total of 9 LED's (still 7 spare I/O on the module for any future needs in that area. This module is basically a drop in replacement for the 74HC595 + 1 transistor (for 9th LED) module that I had previously built. All with no need to modify the ribbon wiring loom from the module to the LED's mounted on the lid of my Experimenters box.

    And I now have 4 spare port B output pins on my 40X1 picaxe for anything else that later needs commands like SHIFTOUT, etc and cannot use i2c.

  4. #4

    Default no success with PCF8574 yet

    Hi mate, I've been trying to interface a picaxe 18X chip to a PCF8574 with no success. I know the base address is 01000000 but have tried that in my code and it just doesn't work. The lines are :

    i2cslave 64,i2cfast,i2cbyte 'configure d/a as slave operating at 400khz
    writei2c 64,(170) 'test data

    I have connected pin 10 of the Picaxe to pin 14 of the PCF8574 and
    pin 7 of the picaxe to pin 15 of the PCF8574.

    Any ideas?

  5. #5
    Senior Member
    Join Date
    Jan 1970
    Location
    Uppsala, Sweden
    Posts
    455

    Default

    The PCF8574 is a quite old type of I/O chip with - in comparison to today's standards - a rather limited set of options. One of the limitations has been addressed already; the very limited drive capability; basically only current sinking is an option.

    Another limitation is the 100KHz maximum i2c frequency operation for the PCF8574; nowadays much higher freqs are almost standard. This may be the cause of problems for jasper500 in his application: use i2cslow instead of i2cfast to see what happens.

    A lot of modern, cheap I/O chips that talk i2c are available (for example mCP23008/mcp 23017; see the code snippets section for examples by forum members). For LED drivers I use the mAX6955/mAX6956, but there are many other available; a detailed search on the forum as well a some main producers will certainly give results as the topic emerged several times. Furthermore different technologies are used, each with advantages/disadvantages.

    Sometimes a standard I/O device like a MCP23008 can be used as a LED driver; be aware though that the maximum specified total current consumption for these devices are often limited to approx 125mA; LED drivers handle much larger currents.

    /Jurjen
    Last edited by kranenborg; 09-11-2008 at 14:42.

  6. #6
    Moderator
    Join Date
    Mar 2008
    Location
    Western Australia
    Posts
    11,230

    Default PCF8574 i2c 8-bit IO Expanders driving LEDs

    Based on your slave address of 64 (%01000000) have you connected pins 1, 2 and 3 all to 0V?
    Officially the PCF8574 only operate at the slow i2c bus speed (the max clock speed is 100kHz). I have had no problems with 400kHz but it is not guaranteed. So, you should have at least to start with:
    Code:
    i2cslave 64, i2cslow, i2cbyte
    then in the writei2c command we need the register location not the slave address. So
    Code:
    writei2c (170) 'test data
    If you have various different i2c devices, then you need to put the relevant i2cslave command in front of each group of reads and writes to that device. Certainly easier with the X1 devices as the ability exists to put the slave address in the command to write and read when using the commands starting with hi2c . . .
    The PCF8574 can sink up to 20mA just like other IO Expanders including the MCP230xx range. It cannot source the same high currents only 0.3mA which is enoght to drive a transistor such as a BC548. I went the way of the transistor to keep what I consider to be “normal” signal levels and it was being used as a drop in replacement to a 74HC595 when I started this thread.
    I am about to switch to MCP23017 chips myself to get 16 IO per chip / slave address rather than just 8 IO points.
    Last edited by westaust55; 09-12-2009 at 01:16.
    westaust55

    Hey Hamlet, 2B OR NOT 2B = $FF

  7. #7
    New Member
    Join Date
    Jan 2010
    Location
    Perth WA
    Posts
    12

    Default

    One trick i use with pcf series i2c is to interface the output with a hc245 and use it as a buffer. One day i will implement it and use the bi directional feature for pcfs used as i/o.

  8. #8
    Moderator
    Join Date
    Mar 2008
    Location
    Western Australia
    Posts
    11,230

    Default

    @ Toggyhead,
    Welcome to the PICAXE forum.

    The thread you have linked to is over a year old now.

    While I am still using a couple of PCF8574's, I have predominantly changed to MCP23017's which provide 16 IO per chip.

    I have also used the 74LVC245 type octal buffers - as a combined buffer and level shifter. I use the LVC type as they have 5V tolerant in inputs when powered at 3.3V without a 5V input signal driving the entire chip to 5V
    westaust55

    Hey Hamlet, 2B OR NOT 2B = $FF

  9. #9
    New Member
    Join Date
    Jan 2010
    Location
    Perth WA
    Posts
    12

    Default

    ops and yes i am new to picaxe and spending most of my evenings getting it up and running playing on my breadboard
    Moving to picaxe in an attempt to automate my farm which currently is driven by an old laptop using the parallel port as i2c.

  10. #10
    Moderator
    Join Date
    Mar 2008
    Location
    Western Australia
    Posts
    11,230

    Default

    Using PICAXE controllers to run your farm could result in a number of interesting projects.

    Keep us informed through the Completed Projects area of those projects you complete.

    And . . . certainly ask in the Active Forum area any questions where you need help to resolve the hurdles . While this is predominantly a PICAXE forum, the off question on non-PICAXE are also fielded form time to time.
    westaust55

    Hey Hamlet, 2B OR NOT 2B = $FF

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •