Pcf8574 wont work right

i have salvaged a couple pcf8574's from some lcd's. I downloaded library RobTillaart/PCF8574

I cant seem to get write8() to work properly. if seems if i use write8(1) or write8(HIGH) the pins just stay low but i can write8(0) and it seems to work.

Here is my code. it currently dont work. however if i uncomment the single write and get rid of write8(HIGH) the code works?

Any idea why i experience this behavior?

#include "PCF8574.h"

PCF8574 PCF(0x27, &Wire);

void setup()
  if (!PCF.begin(D2, D1, HIGH))
    Serial.println("could not initialize...");
  if (!PCF.isConnected())
    Serial.println("=> not connected");
    while (1);

void loop() {
//  PCF.write(0, 1);
//  PCF.write(1, 1);
//  PCF.write(2, 1);
//  PCF.write(3, 1);
//  PCF.write(4, 1);
//  PCF.write(5, 1);
//  PCF.write(6, 1);
//  PCF.write(7, 1);

Why not use the PCF.write(0,HIGH); if that works then there is no problem.

For PCF.write8 function, you need to specify each bit for each pin.
All high: PCF.write8( 0b11111111);
All low: PCF.write8( 0b00000000);
Only "pin" 5 high: PCF.write8( 0b00100000);

1 Like

Apparently i misinterpreted the functions arguments. i though it was just asking for a 1 or a 0.

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