Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[KC868-A16] Can't turn status leds on through HomeKit
#1
Hello everyone, we're trying to use a custom arduino script (with homespan) to control the board with apple homekit.
We managed to connect the board and homekit setting fake lightbulbs properly, but the problem is that the status leds of the outputs don't turn on.
We want to control every output (and related status leds) with homekit.
We've already checked the kc868-a16 schematic, but it doesnt' explain what pins to connect for the outputs
(we already tried pins 2 and 15, as your video for the A4 showed, and pins 1, 2, 3, 4, 5, but without results).
As your video explained (this video: https://www.youtube.com/watch?v=CkCJESr2n-U) we've uploaded the arduino script with homespan installed,
the connection works, but the pins don't correspond (for the kc868-a16)
Reply
#2
A16 board use PCF8574 for expend GPIOs, not use ESP32 pins directly.
Reply
#3
(06-29-2023, 10:47 PM)admin Wrote: A16 board use PCF8574 for expend GPIOs, not use ESP32 pins directly.

Do you have a guide for doing this and connect the board to homekit? Or could you please explain me how to do it? Thanks in advance
Reply
#4
A16 need to chanage code.
https://github.com/HomeSpan/HomeSpan/discussions/394
Reply
#5
(06-30-2023, 12:16 PM)admin Wrote: A16 need to chanage code.
https://github.com/HomeSpan/HomeSpan/discussions/394

I tried with this code:

Code:
//Apple Homekit for KC868-E16S/KC868-E16T
//first time to use: use serial port send "W" to config wifi ssid and password
//if you want to eraser all data, re-config, use serial port send "E"
//default qrcode is 46637726

#include "HomeSpan.h"
#include "DEV_LED.h" 
 

PCF8574 pcfIN_1(0x14,15,14);
PCF8574 pcfIN_2(0x31,15,14);
PCF8574 pcfOUT_1(0x16,15,14);
PCF8574 pcfOUT_2(0x32,15,14);

void pcf_init(){

  pcfIN_1.pinMode(0, INPUT);
  pcfIN_1.pinMode(1, INPUT);
  pcfIN_1.pinMode(2, INPUT);
  pcfIN_1.pinMode(3, INPUT);
  pcfIN_1.pinMode(4, INPUT);
  pcfIN_1.pinMode(5, INPUT);
  pcfIN_1.pinMode(6, INPUT);
  pcfIN_1.pinMode(7, INPUT);
 

  pcfIN_2.pinMode(0, INPUT);
  pcfIN_2.pinMode(1, INPUT);
  pcfIN_2.pinMode(2, INPUT);
  pcfIN_2.pinMode(3, INPUT);
  pcfIN_2.pinMode(4, INPUT);
  pcfIN_2.pinMode(5, INPUT);
  pcfIN_2.pinMode(6, INPUT);
  pcfIN_2.pinMode(7, INPUT);
 

  pcfOUT_1.pinMode(0, OUTPUT);
  pcfOUT_1.pinMode(1, OUTPUT);
  pcfOUT_1.pinMode(2, OUTPUT);
  pcfOUT_1.pinMode(3, OUTPUT);
  pcfOUT_1.pinMode(4, OUTPUT);
  pcfOUT_1.pinMode(5, OUTPUT);
  pcfOUT_1.pinMode(6, OUTPUT);
  pcfOUT_1.pinMode(7, OUTPUT);


  pcfOUT_2.pinMode(0, OUTPUT);
  pcfOUT_2.pinMode(1, OUTPUT);
  pcfOUT_2.pinMode(2, OUTPUT);
  pcfOUT_2.pinMode(3, OUTPUT);
  pcfOUT_2.pinMode(4, OUTPUT);
  pcfOUT_2.pinMode(5, OUTPUT);
  pcfOUT_2.pinMode(6, OUTPUT);
  pcfOUT_2.pinMode(7, OUTPUT);
 
  if (pcfIN_1.begin()) {
    Serial.println("pcfIN_1_OK");
  }
  else{
    Serial.println("pcfIN_1_ERROR");
  }
 
  if (pcfIN_2.begin()) {
    Serial.println("pcfIN_2_OK");
  }
  else{
    Serial.println("pcfIN_2_ERROR");
  }
 
  if (pcfOUT_1.begin()) {
    Serial.println("pcfOUT_1_OK");
  }
  else{
    Serial.println("pcfOUT_1_ERROR");
  }
 
  if (pcfOUT_2.begin()) {
    Serial.println("pcfOUT_2_OK");
  }
  else{
    Serial.println("pcfOUT_2_ERROR");
  }

}

void setup() {
 
  Serial.begin(115200);

  delay(200);

  pcf_init();

  homeSpan.begin(Category::Bridges,"HomeSpan Bridge");

  new SpanAccessory(); 
    new Service::AccessoryInformation();
      new Characteristic::Identify();

  new SpanAccessory();                                                         
    new Service::AccessoryInformation();
      new Characteristic::Identify();
      new Characteristic::Name("LED1");
   
    new DEV_DimmableLED(RELAY1,INPUT1);         

///////////////////
  new SpanAccessory();                                                         
    new Service::AccessoryInformation();
      new Characteristic::Identify();
      new Characteristic::Name("LED2");
   
    new DEV_DimmableLED(RELAY2,INPUT2);         

///////////////////
  new SpanAccessory();                                                         
    new Service::AccessoryInformation();
      new Characteristic::Identify();
      new Characteristic::Name("LED3");
   
    new DEV_DimmableLED(RELAY3,INPUT3);         

///////////////////
  new SpanAccessory();                                                         
    new Service::AccessoryInformation();
      new Characteristic::Identify();
      new Characteristic::Name("LED4");
   
    new DEV_DimmableLED(RELAY4,INPUT4);        

///////////////////
  new SpanAccessory();                                                         
    new Service::AccessoryInformation();
      new Characteristic::Identify();
      new Characteristic::Name("LED5");
   
    new DEV_DimmableLED(RELAY5,INPUT5);   

///////////////////
  new SpanAccessory();                                                         
    new Service::AccessoryInformation();
      new Characteristic::Identify();
      new Characteristic::Name("LED6");
   
    new DEV_DimmableLED(RELAY6,INPUT6);   

///////////////////
  new SpanAccessory();                                                         
    new Service::AccessoryInformation();
      new Characteristic::Identify();
      new Characteristic::Name("LED7");
   
    new DEV_DimmableLED(RELAY7,INPUT7);   

///////////////////
  new SpanAccessory();                                                         
    new Service::AccessoryInformation();
      new Characteristic::Identify();
      new Characteristic::Name("LED8");
   
    new DEV_DimmableLED(RELAY8,INPUT8);

///////////////////
  new SpanAccessory();                                                         
    new Service::AccessoryInformation();
      new Characteristic::Identify();
      new Characteristic::Name("LED9");
   
    new DEV_DimmableLED(RELAY9,INPUT9);

///////////////////
  new SpanAccessory();                                                         
    new Service::AccessoryInformation();
      new Characteristic::Identify();
      new Characteristic::Name("LED10");
   
    new DEV_DimmableLED(RELAY10,INPUT10);

///////////////////
  new SpanAccessory();                                                         
    new Service::AccessoryInformation();
      new Characteristic::Identify();
      new Characteristic::Name("LED11");
   
    new DEV_DimmableLED(RELAY11,INPUT11);

///////////////////
  new SpanAccessory();                                                         
    new Service::AccessoryInformation();
      new Characteristic::Identify();
      new Characteristic::Name("LED12");
   
    new DEV_DimmableLED(RELAY12,INPUT12);

///////////////////
  new SpanAccessory();                                                         
    new Service::AccessoryInformation();
      new Characteristic::Identify();
      new Characteristic::Name("LED13");
   
    new DEV_DimmableLED(RELAY13,INPUT13);


///////////////////
  new SpanAccessory();                                                         
    new Service::AccessoryInformation();
      new Characteristic::Identify();
      new Characteristic::Name("LED14");
   
    new DEV_DimmableLED(RELAY14,INPUT14);


///////////////////
  new SpanAccessory();                                                         
    new Service::AccessoryInformation();
      new Characteristic::Identify();
      new Characteristic::Name("LED15");
   
    new DEV_DimmableLED(RELAY15,INPUT15);

///////////////////
  new SpanAccessory();                                                         
    new Service::AccessoryInformation();
      new Characteristic::Identify();
      new Characteristic::Name("LED16");
   
    new DEV_DimmableLED(RELAY16,INPUT16);       

} // end of setup()

//////////////////////////////////////

void loop(){
 
  homeSpan.poll();
 
} // end of loop()
 
 




But it doesn't work (i managed to connect the board to homekit, but the status leds don't turn on). What am i doing wrong? i also tried wit addresses 0x21, 0x22, 0x24 and 0x25 for inputs and outputs
Reply
#6
This is DEV_LED.h:

Code:
////////////////////////////////////
//   DEVICE-SPECIFIC LED SERVICES //
////////////////////////////////////

#include "extras/PwmPin.h"                          // library of various PWM functions
#include <PCF8574.h>
////////////////////////////////////

extern PCF8574 pcfIN_1;
extern PCF8574 pcfIN_2;
extern PCF8574 pcfOUT_1;
extern PCF8574 pcfOUT_2;

#define RELAY1  1
#define RELAY2  2
#define RELAY3  3
#define RELAY4  4
#define RELAY5  5
#define RELAY6  6
#define RELAY7  7
#define RELAY8  8
#define RELAY9  9
#define RELAY10  10
#define RELAY11  11
#define RELAY12  12
#define RELAY13  13
#define RELAY14  14
#define RELAY15  15
#define RELAY16  16


#define INPUT1  1
#define INPUT2  2
#define INPUT3  3
#define INPUT4  4
#define INPUT5  5
#define INPUT6  6
#define INPUT7  7
#define INPUT8  8
#define INPUT9  9
#define INPUT10  10
#define INPUT11  11
#define INPUT12  12
#define INPUT13  13
#define INPUT14  14
#define INPUT15  15
#define INPUT16  16


boolean PCF_READ(int mPin) {
  if(mPin<9)
    return  !pcfIN_1.digitalRead(mPin-1);    //digitalRead(ex1, 0);    digitalRead(pcfIN_1, mPin-1);
  else
    return  !pcfIN_2.digitalRead(mPin-9);;
}
void PCF_WRITE(int mPin, boolean value ) {
  if(mPin<9)
    pcfOUT_1.digitalWrite((mPin-1), !value);      //digitalWrite(ex1, (mPin-1), value);
  else
    pcfOUT_2.digitalWrite((mPin-9), !value);
}


struct DEV_DimmableLED : Service::LightBulb {       // Dimmable LED

  //LedPin *ledPin;                                   // reference to Led Pin
  int powerPin;                                     // NEW! pin with pushbutton to turn on/off LED
  int ledPin;
  SpanCharacteristic *power;                        // reference to the On Characteristic
  SpanCharacteristic *level;                        // reference to the Brightness Characteristic
  int favoriteLevel=50;                             // NEW! keep track of a 'favorite' level
  // NEW!  Consructor includes 3 additional arguments to specify pin numbers for power, raise, and lower buttons
 
  DEV_DimmableLED(int pin, int powerPin) : Service::LightBulb(){

    power=new Characteristic::On();    
    //new SpanButton(powerPin);                       // NEW! create new SpanButton to control power using pushbutton on pin number "powerPin"
    new SpanButton(powerPin,PCF_READ);

    this->powerPin=powerPin;                        // NEW! save power pushbutton pin number

    //this->ledPin=new LedPin(pin);                   // configures a PWM LED for output to the specified pin
    this->ledPin=pin;
   
    Serial.print("Configuring Dimmable LED: Pin="); // initialization message
    Serial.print(pin);
    Serial.print("\n");
   
  } // end constructor


 


  boolean update(){                              // update() method

    if(power->updated()){
      LOG1("  New Power=");
      LOG1(power->getNewVal()?"true":"false");
    }

    LOG1("\n");
    //ledPin->set(power->getNewVal()*100);   
    PCF_WRITE(ledPin,power->getNewVal());
    return(true);                               // return true
 
  } // update

  // NEW!  Here is the button() method where all the PushButton actions are defined.   Take note of the signature, and use of the word "override"

  void button(int pin, int pressType) override {

    int newLevel;

    if(pin==powerPin){
      if(pressType==SpanButton::SINGLE){            // if a SINGLE press of the power button...
        power->setVal(1-power->getVal());           // ...toggle the value of the power Characteristic
      }      
    }
   
    //ledPin->set(power->getVal()*100);       // update the physical LED to reflect the new values
    PCF_WRITE(ledPin,power->getNewVal());
  }

};
Reply
#7
any questions about Homespan, you can post to their github FAQ zone.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)