Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Arduino IDE demo source code for KC868-A6]--#07-PCF8574-Digital input code
#1
Heart 
[Arduino IDE demo source code for KC868-A6]--#07-PCF8574-DI_code

Code:
#include "Arduino.h"
#include "PCF8574.h"

// Set i2c address
PCF8574 pcf8574(0x22,4,15);
unsigned long timeElapsed;
void setup()
{
Serial.begin(115200);
delay(1000);

pcf8574.pinMode(P0, INPUT);
pcf8574.pinMode(P1, INPUT);
pcf8574.pinMode(P2, INPUT);
pcf8574.pinMode(P3, INPUT);
pcf8574.pinMode(P4, INPUT);
pcf8574.pinMode(P5, INPUT);
pcf8574.pinMode(P6, INPUT);
pcf8574.pinMode(P7, INPUT);

    Serial.print("Init pcf8574...");
    if (pcf8574.begin()){
        Serial.println("OK");
    }else{
        Serial.println("KO");
    }
}

void loop()
{
uint8_t val1 = pcf8574.digitalRead(P0);
uint8_t val2 = pcf8574.digitalRead(P1);
uint8_t val3 = pcf8574.digitalRead(P2);
uint8_t val4 = pcf8574.digitalRead(P3);
uint8_t val5 = pcf8574.digitalRead(P4);
uint8_t val6 = pcf8574.digitalRead(P5);
uint8_t val7 = pcf8574.digitalRead(P6);
uint8_t val8 = pcf8574.digitalRead(P7);
if (val1==LOW) Serial.println("KEY1 PRESSED");
if (val2==LOW) Serial.println("KEY2 PRESSED");
if (val3==LOW) Serial.println("KEY3 PRESSED");
if (val4==LOW) Serial.println("KEY4 PRESSED");
if (val5==LOW) Serial.println("KEY5 PRESSED");
if (val6==LOW) Serial.println("KEY6 PRESSED");
if (val7==LOW) Serial.println("KEY7 PRESSED");
if (val8==LOW) Serial.println("KEY8 PRESSED");
    delay(300);
}
Reply
#2
not work! manual ?
Reply
#3
???
Reply
#4
It won't compile because it references an external library (PCF8574.h). But there's several libraries called that... I'm not sure which one Kincony uses:

https://github.com/RobTillaart/PCF8574
https://github.com/xreef/PCF8574_library

? Or something else?
Reply
#5
here is PCF8574 arduino library we are using.

.zip   PCF8574_library.zip (Size: 23.8 MB / Downloads: 588)
Reply
#6
(01-26-2025, 12:59 AM)admin Wrote: here is PCF8574 arduino library we are using.

That is the xreef one. BTW, you also need the I2C "Wire.h" library for your project to work.
Both libraries (RobTillart and Mischianti) are maintained, and they are both using C++ approach : a chip is an object from PCF8574 class.
So the same code is used for bothchips, with only the parameters of the chip stored separately.

However, note that one PCF is for digital inputs and the other for relays, so don't expect too much synergies ;-)
Reply
#7
Hi! The Arduino.h and pcf8574.h librsrys on must be in the SAME directory or different ones?
Reply
#8
PCF8574 arduino library copy to your arduino system library folder.
Reply
#9
(06-30-2025, 02:07 PM)ksarz Wrote: Hi! The Arduino.h and pcf8574.h librsrys on must be in the SAME  directory or different ones?

The usual rule is that 
#include <library1.h> // is for libraries in your library forlder
#include "library2.h" // is for libraries in the same directory as your .ino file.

You can go both ways, but the .zip file given by the admin is 20MB big (lots of "resources', most unrelated to KC868), while the .h and .cpp (the only two files needed) are 40kB. However, if you copy locally (my preference), you'll have to do that in all the directories if you have several programs.

BTW, the WifiManager.h library is not by default in my library folder either. I downloaded it using the library manager. The PCF8574 library is there as well, but you may need to scroll down a lot, it is called "PCF8574 library by Renzo Mischianti". It is now version 2.3.7, more recent than the .zip file, but that shouldn't make a difference.
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)