|
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
|