PCF8574A Pushbutton Current Consumption

Hi all, (long time reader, first time poster)

I'm trying to do some testing using GPIO expanders for input (as opposed to output as I've done for LCD / 7 segs). Every schematic I find online to try and use the PCF IC for input shows that the pin input should be directly pulled high to Vdd (through a button, switch or otherwise).

When testing this out, I notice the current consumption is pretty significant, rising by about 45mA on my supply. Inserting any medium-size resistance to try and limit current flow stops the PCF from reading the input and responding to it.

I'm really struggling to find the correct way to read - while I could continue using this sort of setup the project I'm planning for will use Power over USB and is limited to 0.5A in practice.

More details about my setup:

  • ATMega324pa 40 PDIP, 20MHz XTAL
  • Reading Decoded I2C bus on Scope with Decoder
  • PCF8574a, address 0x39 (A0,A1!,A2!)

I can provide a few sketches and my code, but they won't be of much more use as I know the I2C bus and supply readings show the chip is working normally and my test LED is working fine. Below is the schematic I have been working off of:

many thanks!!

edit: I have decided to show off my code just in case I'm screwing up without noticing:

#include <Wire.h>

#include <PCF8574.h>

PCF8574 pcf(0x39);

const byte AVRLED = 24;
const byte PCFLEDpin = 0;

void setup() {
  // put your setup code here, to run once:
  
  pinMode(AVRLED, OUTPUT);
  digitalWrite(AVRLED,HIGH);
  pcf.begin(0);
  pcf.setButtonMask(0xF0);
  pcf.write(0,LOW);
  
}

void loop() {
  // put your main code here, to run repeatedly:
  if(pcf.read(7))
  {
    pcf.write(0,HIGH);
    digitalWrite(AVRLED,HIGH);
  }
 
  else
  {
    pcf.write(0,LOW);
    digitalWrite(AVRLED,LOW);
  }
    
  delay(50);
}

Because they are not written by competent engineers. :roll_eyes: That is simply wrong. :astonished:

Connect each switch from the pin to ground. The PCF8574 will pull the inputs up by itself or you could add pull-ups if there seems to be any problem with dodgy pushbuttons or long wires and interference pickup.

1 Like

Paul_B is right on! You need to pull the switch inputs high with and or without internal pull up resistors. I use external pull up resistors so I can keep at least one mA through the contact to keep it clean from oxide etc. This also increases my noise margin. I feel the reason you see that they are not comfortable with a negative true signal. Logic high is a one so the pin must be high to be on is there thinking. You simply complement the negative true reading and it works fine. This reduces the current and makes the batteries last longer.

They are also asking for problems when the wires go off the board, the longer the wire the better antenna it is. This makes it much more difficult to stabilize the power supply.

Actually, having had a little think about it, that is the silly error in the original program. You must not write the outputs LOW, as when you then attempt to pull them up, you are fighting the drivers - and the button wins as the driver can only pull down 45 mA.

It was simply unclear what

meant, but obviously you meant that is what happens when you press a button.

Removing the bad line of code will "fix" the problem, but wiring the buttons correctly to ground is not only more correct, but safer against coding blunders. :sunglasses:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.