Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem using KC868-A8S
#1
I just received a KC868-A8S board and am not able to get it to work. I started with the relay sample program. I copied pin_arduino.h to the project and changed SDA and SCL to 4 and 5 respectively as indicated. I also added static_assert statements to make sure that the correct values were picked up. The program compiled and loaded successfully. The pcf.begin() statement returns false indicating an error occurred. I then tried the sample I2CScanner project, mad the same changes and ran it. It indicated that there were no I2C devices detected. I also have a KC868-A4 which works correctly. The code is different but all the wiring is the same so I don't thing I have any cable problems.

// Visual Micro is in vMicro>General>Tutorial Mode
//
/*
    Name:      KC868_01.ino
    Created: 1/4/2023 4:15:15 PM
    Author:   
*/

// Define User Types below here or use a .h file
//
// Import required libraries
#include <Arduino.h>
#include <PCF8574.h>

#define I2C_RELAYS_ADDR  0x24

/**/

static_assert ((SDA!=4),"SDA not defined correctly for KC878-A8S");
static_assert ((SCL!=5),"SCL not defined correctly for KC878-A8S");

PCF8574 pcf(I2C_RELAYS_ADDR,SDA,SCL);

// The setup() function runs once each time the micro-controller starts
void setup()
{
  Serial.begin(115200);
  delay(1000);

  Serial.println(F("Start Kincony KC868 - A8S Relays example..."));

  pcf.pinMode(P0, OUTPUT);
  pcf.pinMode(P1, OUTPUT);
  pcf.pinMode(P2, OUTPUT);
  pcf.pinMode(P3, OUTPUT);
  pcf.pinMode(P4, OUTPUT);
  pcf.pinMode(P5, OUTPUT);
  pcf.pinMode(P6, OUTPUT);
  pcf.pinMode(P7, OUTPUT);
  Serial.print("Initialize PCF8574 ");
  if (pcf.begin())
    Serial.println(F("OK"));
  else
    Serial.println(F("Error"));
  delay(20);
}

// Add the main program code into the continuous loop() function
void loop()
{
  pcf.digitalWrite(P4,HIGH);
  Serial.print(F("Relay #"));
  Serial.print(P4);
  Serial.println(F("ON"))  ;
  delay(10000);
  pcf.digitalWrite(P4,LOW);
  Serial.print(F("Relay #"));
  Serial.print(P4);
  Serial.println(F("OFF"))  ;
}



Sketch uses 214946 bytes (16%) of program storage space. Maximum is 1310720 bytes.
Global variables use 14688 bytes (4%) of dynamic memory, leaving 312992 bytes for local variables. Maximum is 327680 bytes.
esptool.py v3.0-dev
Serial port COM3
Connecting........_
Chip is ESP32-D0WD-V3 (revision 3)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: c4:de:e2:ce:cc:74
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.0 seconds (effective 6553.6 kbit/s)...
Hash of data verified.
Compressed 17120 bytes to 11164...
Writing at 0x00001000... (100 %)
Wrote 17120 bytes (11164 compressed) at 0x00001000 in 0.1 seconds (effective 951.1 kbit/s)...
Hash of data verified.
Compressed 215056 bytes to 113168...
Writing at 0x00010000... (14 %)
Writing at 0x00014000... (28 %)
Writing at 0x00018000... (42 %)
Writing at 0x0001c000... (57 %)
Writing at 0x00020000... (71 %)
Writing at 0x00024000... (85 %)
Writing at 0x00028000... (100 %)
Wrote 215056 bytes (113168 compressed) at 0x00010000 in 1.9 seconds (effective 927.0 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 128...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (128 compressed) at 0x00008000 in 0.0 seconds (effective 3072.0 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

Start Kincony KC868 - A8S Relays example...
Initialize PCF8574 Error
Relay #4ON
Relay #4OFF
Relay #4ON
Relay #4OFF
Relay #4ON
Relay #4OFF
Relay #4ON
Relay #4OFF
Relay #4ON
Relay #4OFF
Relay #4ON




// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//    Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    https://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>

static_assert ((SDA!=4),"SDA not defined correctly for KC878-A8S");
static_assert ((SCL!=5),"SCL not defined correctly for KC878-A8S");


void setup()
{
  Serial.begin(115200);
  delay(1000);
  while (!Serial);            // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");

if (Wire.begin(SDA,SCL))
  Serial.println("I2C Initialized");
else
  Serial.println("I2C Init Failed");

}


void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }   
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);          // wait 5 seconds for next scan
}





Scanning...
No I2C devices found

Scanning...
No I2C devices found

Scanning...
No I2C devices found

Scanning...
No I2C devices found
Reply
#2
now it's IIC issue. can you download our A8S relay arduino demo code for a test firstly?
here is our relay output demo , that used PCF8574: https://www.kincony.com/forum/showthread.php?tid=1956
here is our arduino pcf8574 library, you can copy to your library folder to use.

.zip   PCF8574_library.zip (Size: 23.8 MB / Downloads: 213)
Reply
#3
Interesting, the demo program works fine. I will figure out what the difference is. The only immediate difference is you defined the PCF variable with literals and I did it with defines and variables. Will work through it when I get a chance. It does seem to be working so that is good.
Reply
#4
Apparently copying pins_arduino.h and changing SDA and SCL defines causes the compile to get screwed up. I deleted the header and recompiled with values in the pcf constructor and my program now works. On to the next thing. One question, it appears that the relay led is on when the relay pin is low. Is that what is expected? Does that mean that NO is powered when low as well? I will test that so will figure it out. The relay buttons don't seem to do anything. Do they trigger the input pins which I would read from 0x22? I will test that as well just to understand how this board works.

I2CScanner gets the expected results as well:

I2C Scanner
I2C Initialized
Scanning...
I2C device found at address 0x22 !
I2C device found at address 0x24 !
done
Reply
#5
yes, relay GPIO LOW , led will be ON, relay's COM and NO will be ON.
if you want input trigger output, just need write code for driver. it's easy.
Reply
#6
if INPUT=xx then RELAY=yy
Reply
#7
I realised when you want to activate relays on this dont use the latest version of PCF8574_library found on arduino IDE library. Use the version indicated on the kincony documentation
Reply
#8
whether work well? use our PCF8574 library?
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)