Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 8,860
» Latest member: richardjhon
» Forum threads: 3,880
» Forum posts: 19,788

Full Statistics

Online Users
There are currently 32 online users.
» 0 Member(s) | 21 Guest(s)
AhrefsBot, Amazonbot, Applebot, Crawl, Google, bot

Latest Threads
KC868-COLB - How to Conne...
Forum: KC868-HxB series Smart Controller
Last Post: upstream
5 hours ago
» Replies: 4
» Views: 27
Interface T16M E/S et AIO
Forum: News
Last Post: H_spadacini
Today, 10:42 AM
» Replies: 2
» Views: 69
Instal ESP HA with ethern...
Forum: Getting Started with ESPHome and Home Assistant
Last Post: kulibin
Today, 10:33 AM
» Replies: 2
» Views: 14
KC868-A4 USB not detected...
Forum: KC868-A series and Uair Smart Controller
Last Post: stansvec
Today, 02:04 AM
» Replies: 4
» Views: 1,614
KCS_Z1_V3.24.2.zip firmwa...
Forum: "KCS" v3 firmware
Last Post: admin
Today, 01:55 AM
» Replies: 4
» Views: 42
N10 wire case diagram for...
Forum: N10
Last Post: admin
Today, 12:22 AM
» Replies: 0
» Views: 8
"KCS" v2.2.20 firmware BI...
Forum: "KCS" v2 firmware system
Last Post: admin
Today, 12:15 AM
» Replies: 0
» Views: 33
N20 wire case diagram for...
Forum: N20
Last Post: admin
Yesterday, 11:34 PM
» Replies: 0
» Views: 9
Adding a debounce capabil...
Forum: KC868-A16v3
Last Post: admin
Yesterday, 11:31 PM
» Replies: 4
» Views: 122
KinCony ESP32 Tuya IoT ad...
Forum: KC868-ATC / Tuya adapter V2
Last Post: admin
Yesterday, 11:28 PM
» Replies: 1
» Views: 18

  [arduino code examples for A8v3]-05 Read free GPIO state
Posted by: admin - 04-20-2025, 06:37 AM - Forum: KC868-A8v3 - No Replies

Code:
/*
* ESP32 GPIO State Reader
* Reads the state of GPIO47, GPIO48, GPIO7, GPIO40, GPIO0, and GPIO5
* and prints the results to the serial monitor.
*
* Made by KinCony IoT: https://www.kincony.com
*/

#define GPIO_13  13
#define GPIO_40  40
#define GPIO_14  14
#define GPIO_48  48
#define GPIO_0   0


void setup() {
    Serial.begin(115200); // Initialize serial communication at 115200 baud rate
   
    // Set GPIOs as input
    pinMode(GPIO_13, INPUT);
    pinMode(GPIO_40, INPUT);
    pinMode(GPIO_14, INPUT);
    pinMode(GPIO_48, INPUT);
    pinMode(GPIO_0, INPUT);
}

void loop() {
    // Read GPIO states
    int state_13 = digitalRead(GPIO_13);
    int state_40 = digitalRead(GPIO_40);
    int state_14  = digitalRead(GPIO_14);
    int state_48 = digitalRead(GPIO_48);
    int state_0  = digitalRead(GPIO_0);
   
    // Print GPIO states to the serial monitor
    Serial.printf("GPIO13: %d, GPIO40: %d, GPIO14: %d, GPIO48: %d, GPIO0: %d\n",
                  state_13, state_40, state_14, state_48, state_0);
   
    delay(1000); // Read GPIO states every second
}
arduino ino file download:

.zip   5-free-gpio-state.zip (Size: 621 bytes / Downloads: 415)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   5-free-gpio-state.ino.merged.zip (Size: 179.32 KB / Downloads: 400)

Print this item

  [arduino code examples for A8v3]-04 RS485 communication test
Posted by: admin - 04-20-2025, 06:35 AM - Forum: KC868-A8v3 - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* RS485 Communication Test
*
* This program is a simple test for RS485 communication using ESP32-S3.
* It will send a message over RS485 and then read incoming messages.
* The TXD pin is defined as GPIO 18 and RXD pin is defined as GPIO 8.
*/

#include <HardwareSerial.h>

// Define RS485 pins
#define RS485_RXD 38
#define RS485_TXD 39

// Create a hardware serial object
HardwareSerial rs485Serial(1);

void setup() {
  // Start serial communication for debugging
  Serial.begin(115200);
  while (!Serial);

  // Initialize RS485 Serial communication
  rs485Serial.begin(9600, SERIAL_8N1, RS485_RXD, RS485_TXD);
 
  Serial.println("RS485 Test Start");
}

void loop() {
  // Send a test message
  rs485Serial.println("Hello from KinCony B8M!");

  // Wait for a short period
  delay(1000);

  // Check if data is available to read
  if (rs485Serial.available()) {
    String receivedMessage = "";
    while (rs485Serial.available()) {
      char c = rs485Serial.read();
      receivedMessage += c;
    }
    // Print the received message
    Serial.print("Received: ");
    Serial.println(receivedMessage);
  }

  // Wait before sending the next message
  delay(2000);
}
arduino ino file download:

.zip   4-RS485-Test.zip (Size: 763 bytes / Downloads: 405)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   4-RS485-Test.ino.merged.zip (Size: 184.35 KB / Downloads: 387)

Print this item

  [arduino code examples for A8v3]-03 Read analog input ports value
Posted by: admin - 04-20-2025, 06:34 AM - Forum: KC868-A8v3 - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* Description:
* This Arduino program reads analog values from four analog input pins (A1, A2)
* and prints the values to the Serial Monitor. The analog inputs are defined with specific
* GPIO pins and the program reads the voltage levels from these pins every 2 seconds.
*
* Pin Definitions:
* - A1: GPIO 7
* - A2: GPIO 6

*/

#define ANALOG_A1   7   // Define GPIO pin for analog input A1
#define ANALOG_A2   6   // Define GPIO pin for analog input A2


void setup()
{
    Serial.begin(115200); // Initialize serial communication at 115200 baud rate
    delay(500); // Short delay to allow serial communication to start

    pinMode(ANALOG_A1, INPUT); // Set GPIO 5 as an input for analog signal A1
    pinMode(ANALOG_A2, INPUT); // Set GPIO 7 as an input for analog signal A2

}

void loop()
{
    // Read and print analog values from the defined pins
    Serial.print("A1=");
    Serial.println(analogRead(ANALOG_A1)); // Read and print the value from A1
    Serial.print("A2=");
    Serial.println(analogRead(ANALOG_A2)); // Read and print the value from A2   
    delay(2000); // Wait for 2 seconds before the next reading
}
arduino ino file download:

.zip   3-analog-input.zip (Size: 698 bytes / Downloads: 393)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   3-analog-input.ino.merged.zip (Size: 184.59 KB / Downloads: 382)

Print this item

  [arduino code examples for A8v3]-02 Read digital input ports state
Posted by: admin - 04-20-2025, 06:32 AM - Forum: KC868-A8v3 - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* Description:
* This Arduino program reads the state of a 16-channel PCF8575 I/O expander
* and prints the state of all input pins to the Serial Monitor. The state of
* each pin is represented as a bit in a 16-bit value, where each bit corresponds
* to an input pin. The program prints the input state in binary format.
*
* Pin Definitions:
* - SDA: GPIO 8
* - SCL: GPIO 18
* - PCF8575 I2C Address: 0x22
*/

#include "Arduino.h"
#include "PCF8575.h"

// Define I2C pins
#define I2C_SDA 8  // Define SDA pin
#define I2C_SCL 18  // Define SCL pin

// Set I2C address
PCF8575 pcf8575_IN1(0x22); // The I2C address of the PCF8575

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

    // Initialize I2C communication
    Wire.begin(I2C_SDA, I2C_SCL); // Initialize I2C with defined SDA and SCL pins

    pcf8575_IN1.begin(); // Initialize the PCF8575

    Serial.println("KinCony B8M 8 channel input state 0:ON  1:OFF");
}

void loop() {
    uint16_t state = 0;

    // Read the state of each pin (assuming 16 pins)
    for (int pin = 8; pin < 16; pin++) {
        if (pcf8575_IN1.read(pin)) {
            state |= (1 << pin); // Set the bit for the active pin
        }
    }

    Serial.print("Input state: ");
    Serial.println(state, BIN); // Print the state of inputs in binary

    delay(500); // Delay 500ms
}
arduino ino file download:

.zip   2-digital-input.zip (Size: 839 bytes / Downloads: 444)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   2-digital-input.ino.merged.zip (Size: 189.5 KB / Downloads: 412)

Print this item

  [arduino code examples for A8v3]-01 Turn ON/OFF relay
Posted by: admin - 04-20-2025, 06:18 AM - Forum: KC868-A8v3 - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* This program controls a 16-channel relay board via a PCF8575 I/O expander.
* It sequentially turns on each relay and then turns them off in a loop.
*
* Pin Definitions:
* - SDA: GPIO 8
* - SCL: GPIO 18
*
* Delay Time:
* - 200 milliseconds between switching relays
*/

#include <Wire.h>        // Include the Wire library for I2C communication
#include <PCF8575.h>     // Include the PCF8575 library to control the I/O expander

#define SDA 8           // Define the SDA pin
#define SCL 18          // Define the SCL pin
#define DELAY_TIME 200   // Define the delay time in milliseconds

// Set I2C address of the PCF8575 module
#define I2C_ADDRESS 0x22 // I2C address of the PCF8575 module

PCF8575 pcf8575_R1(I2C_ADDRESS); // Create a PCF8575 object with the specified I2C address

void setup() {
  // Initialize I2C communication
  Wire.begin(SDA, SCL); // SDA on GPIO 8, SCL on GPIO 18 (according to your board's configuration)
 
  // Initialize serial communication for debugging (optional)
  Serial.begin(115200);
  Serial.println("PCF8575 Relay Control: Starting...");

  // Initialize the PCF8575 module
  pcf8575_R1.begin();

  // Turn off all relays initially (set all pins HIGH)
  for (int i = 0; i < 8; i++) {
    pcf8575_R1.write(i, HIGH); // Set all relays to OFF (assuming HIGH means OFF for relays)
  }
}

void loop() {
  // Sequentially turn on each relay
  for (int i = 0; i < 8; i++) {
    pcf8575_R1.write(i, LOW);   // Turn on the relay at pin i (LOW means ON for the relay)
    delay(DELAY_TIME);          // Wait for DELAY_TIME milliseconds
  }

  // Sequentially turn off each relay
  for (int i = 0; i < 8; i++) {
    pcf8575_R1.write(i, HIGH);  // Turn off the relay at pin i (HIGH means OFF for the relay)
    delay(DELAY_TIME);          // Wait for DELAY_TIME milliseconds
  }
}
arduino ino file download:

.zip   1-output.zip (Size: 925 bytes / Downloads: 390)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   1-output.ino.merged.zip (Size: 189.23 KB / Downloads: 405)

Print this item

  KC868-A8v3 ESPHome yaml for home assistant
Posted by: admin - 04-20-2025, 06:15 AM - Forum: KC868-A8v3 - No Replies

   

Code:
esphome:
  name: a8v3
  friendly_name: a8v3
  platformio_options:
    board_build.extra_flags:
      # WIFI_CONTROL_SELF_MODE = 0
      # WIFI_CONTROL_SELF_MODE = 1
      - "-DWIFI_CONTROL_SELF_MODE=1"
esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: arduino

external_components:
  - source:
      type: git
      url: https://github.com/hzkincony/esphome-tuya-wifi-mcu
      ref: v1.1.0

# Enable logging
# logger:
#   hardware_uart: USB_SERIAL_JTAG
# Enable Home Assistant API
api:
  encryption:
    key: "WeVOuL5oNhjXcfzXtTirlOwvtWvCD5yqIxd3oV4es1k="

ethernet:
  type: W5500
  clk_pin: GPIO1
  mosi_pin: GPIO2
  miso_pin: GPIO41
  cs_pin: GPIO42
  interrupt_pin: GPIO43
  reset_pin: GPIO44

i2c:
   - id: bus_a
     sda: 8
     scl: 18
     scan: true
     frequency: 400kHz

pcf8574:
  - id: 'pcf8574_hub_out_1'  # for output channel 0-7| input channel 8-15   
    i2c_id: bus_a
    address: 0x22
    pcf8575: true

uart:
  - id: uart_1    #RS485
    baud_rate: 9600
    debug:
      direction: BOTH
      dummy_receiver: true
      after:
        timeout: 10ms
    tx_pin: 39
    rx_pin: 38

  - id: tuya_mcu_uart
    tx_pin: GPIO16
    rx_pin: GPIO17
    baud_rate: 9600

tuya_wifi_mcu:
  # tuya mcu product id
  product_id: qlvsreramxcldwek
  uart_id: tuya_mcu_uart
  wifi_reset_pin: 28
  wifi_led_pin: 16

switch:
  - platform: uart
    uart_id: uart_1
    name: "RS485 Button"
    data: [0x11, 0x22, 0x33, 0x44, 0x55]

  - platform: gpio
    name: "a8v3-output01"
    id: "a8v3_output01"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 0
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: a8v3-output1-tuya
    dp_id: 1
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "a8v3_output01"

  - platform: gpio
    name: "a8v3-output02"
    id: "a8v3_output02"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 1
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: a8v3-output2-tuya
    dp_id: 2
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "a8v3_output02"

  - platform: gpio
    name: "a8v3-output03"
    id: "a8v3_output03"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 2
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: a8v3-output3-tuya
    dp_id: 3
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "a8v3_output03"

  - platform: gpio
    name: "a8v3-output04"
    id: "a8v3_output04"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 3
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: a8v3-output4-tuya
    dp_id: 4
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "a8v3_output04"

  - platform: gpio
    name: "a8v3-output05"
    id: "a8v3_output05"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 4
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: a8v3-output5-tuya
    dp_id: 5
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "a8v3_output05"

  - platform: gpio
    name: "a8v3-output06"
    id: "a8v3_output06"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 5
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: a8v3-output6-tuya
    dp_id: 6
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "a8v3_output06"

  - platform: gpio
    name: "a8v3-output07"
    id: "a8v3_output07"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 6
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: a8v3-output7-tuya
    dp_id: 101
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "a8v3_output07"

  - platform: gpio
    name: "a8v3-output08"
    id: "a8v3_output08"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 7
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: a8v3-output8-tuya
    dp_id: 102
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "a8v3_output08"

binary_sensor:
  - platform: gpio
    name: "a8v3-input01"
    id: "a8v3_input01"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 8
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: a8v3-input1-tuya
    dp_id: 111
    bind_binary_sensor_id: a8v3_input01
    internal: true

  - platform: gpio
    name: "a8v3-input02"
    id: "a8v3_input02"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 9
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: a8v3-input2-tuya
    dp_id: 112
    bind_binary_sensor_id: a8v3_input02
    internal: true

  - platform: gpio
    name: "a8v3-input03"
    id: "a8v3_input03"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 10
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: a8v3-input3-tuya
    dp_id: 113
    bind_binary_sensor_id: a8v3_input03
    internal: true

  - platform: gpio
    name: "a8v3-input04"
    id: "a8v3_input04"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 11
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: a8v3-input4-tuya
    dp_id: 114
    bind_binary_sensor_id: a8v3_input04
    internal: true

  - platform: gpio
    name: "a8v3-input05"
    id: "a8v3_input05"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 12
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: a8v3-input5-tuya
    dp_id: 115
    bind_binary_sensor_id: a8v3_input05
    internal: true

  - platform: gpio
    name: "a8v3-input06"
    id: "a8v3_input06"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 13
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: a8v3-input6-tuya
    dp_id: 116
    bind_binary_sensor_id: a8v3_input06
    internal: true

  - platform: gpio
    name: "a8v3-input07"
    id: "a8v3_input07"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 14
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: a8v3-input7-tuya
    dp_id: 117
    bind_binary_sensor_id: a8v3_input07
    internal: true

  - platform: gpio
    name: "a8v3-input08"
    id: "a8v3_input08"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 15
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: a8v3-input8-tuya
    dp_id: 118
    bind_binary_sensor_id: a8v3_input08
    internal: true

##pull-up resistance on PCB
  - platform: gpio
    name: "a8v3-W1-io13"
    pin:
      number: 13
      inverted: true

  - platform: gpio
    name: "a8v3-W1-io40"
    pin:
      number: 40
      inverted: true

  - platform: gpio
    name: "a8v3-W1-io14"
    pin:
      number: 14
      inverted: true

  - platform: gpio
    name: "a8v3-W1-io48"
    pin:
      number: 48
      inverted: true
## without resistance on PCB
  - platform: gpio
    name: "a8v3-5"
    pin:
      number: 5
      inverted:  false

  - platform: gpio
    name: "a8v3-0"
    pin:
      number: 0
      inverted:  false

sensor:
  - platform: adc
    pin: 7
    name: "A8v3 A1 Voltage"
    update_interval: 5s
    attenuation: 11db
    filters:
      - lambda:
          if (x >= 3.11) {
            return x * 1.60256;
          } else if (x <= 0.15) {
            return 0;
          } else {
            return x * 1.51;
          }
  - platform: adc
    pin: 6
    name: "A8v3 A2 Voltage"
    update_interval: 5s
    attenuation: 11db
    filters:
      # - multiply: 1.51515
      - lambda:
          if (x >= 3.11) {
            return x * 1.60256;
          } else if (x <= 0.15) {
            return 0;
          } else {
            return x * 1.51;
          }

web_server:
  port: 80

font:
  - file: "gfonts://Roboto"
    id: roboto
    size: 20

display:
  - platform: ssd1306_i2c
    i2c_id: bus_a
    model: "SSD1306 128x64"
    address: 0x3C
    lambda: |-
      it.printf(0, 0, id(roboto), "KinCony a8v3");
esphome yaml file download:

.txt   A8v3-HA.txt (Size: 8.41 KB / Downloads: 438)

Print this item

  KC868-A8v3 ESP32-S3 IO pins define
Posted by: admin - 04-20-2025, 06:13 AM - Forum: KC868-A8v3 - No Replies

IIC Bus:

SDA:GPIO8
SCL:GPIO18

PCF8575: i2c address:0x22

PCF8575->P0 (relay1)
PCF8575->P1 (relay2)
PCF8575->P2 (relay3)
PCF8575->P3 (relay4)
PCF8575->P4 (relay5)
PCF8575->P5 (relay6)
PCF8575->P6 (relay7)
PCF8575->P7 (relay8)

PCF8575->P8 (DI1)
PCF8575->P9 (DI2)
PCF8575->P10 (DI3)
PCF8575->P11 (DI4)
PCF8575->P12 (DI5)
PCF8575->P13 (DI6)
PCF8575->P14 (DI7)
PCF8575->P15 (DI8)

24C02 EPROM i2c address: 0x50
DS3231 RTC i2c address: 0x68
SSD1306 display: i2c address:0x3c


Analog input (A1: DC 0-5v): GPIO7
Analog input (A2: DC 0-5v): GPIO6

-----------------
1-wire GPIOs (with pull-up resistance on PCB):
S1:GPIO40
S2:GPIO13
S3:GPIO48
S4:GPIO14


-----------------

Ethernet (W5500) I/O define:

clk_pin: GPIO1
mosi_pin: GPIO2
miso_pin: GPIO41
cs_pin: GPIO42

interrupt_pin: GPIO43
reset_pin: GPIO44

--------------------
RS485:
RXD:GPIO38
TXD:GPIO39

Tuya module:
RXD:GPIO17
TXD:GPIO16

Tuya network button: Tuya module's P28
Tuya network LED: Tuya module's P16
--------------------
SD Card:
SPI-MOSI:GPIO10
SPI-SCK:GPIO11
SPI-MISO:GPIO12
SPI-CS:GPIO9
SPI-CD:GPIO47
--------------------
RF433M sender:GPIO4
RF433M receiver:GPIO5

Print this item

  [arduino code examples for A2v3]-11 Digital input trigger relay output
Posted by: admin - 04-20-2025, 06:07 AM - Forum: KC868-A2v3 - No Replies

Code:
/**
* @brief Example to control relays based on digital input states using ESP32
* @details This program reads the states of two digital inputs (GPIO16, GPIO17)
*          and controls two relays (GPIO40, GPIO39) accordingly.
*
* Made by KinCony IoT: https://www.kincony.com
*/

// Define the GPIO pins for digital inputs
#define INPUT1_PIN 16  // GPIO16 for Digital Input 1
#define INPUT2_PIN 17  // GPIO17 for Digital Input 2

// Define the GPIO pins for relays
#define RELAY1_PIN 40  // GPIO40 for Relay 1
#define RELAY2_PIN 39  // GPIO39 for Relay 2

void setup() {
    // Initialize the serial communication for debugging
    Serial.begin(115200);
    Serial.println("ESP32 Input-Controlled Relay Example");

    // Set the input pins as INPUT
    pinMode(INPUT1_PIN, INPUT);
    pinMode(INPUT2_PIN, INPUT);

    // Set the relay pins as OUTPUT
    pinMode(RELAY1_PIN, OUTPUT);
    pinMode(RELAY2_PIN, OUTPUT);

    // Turn off both relays at startup (assuming active LOW relays)
    digitalWrite(RELAY1_PIN, HIGH);
    digitalWrite(RELAY2_PIN, HIGH);
}

void loop() {
    // Read the state of the digital inputs
    int state1 = digitalRead(INPUT1_PIN);
    int state2 = digitalRead(INPUT2_PIN);

    // Control the relays based on input states
    digitalWrite(RELAY1_PIN, state1 == HIGH ? LOW : HIGH); // Activate relay if input is HIGH
    digitalWrite(RELAY2_PIN, state2 == HIGH ? LOW : HIGH); // Activate relay if input is HIGH

    // Print the states to the Serial Monitor
    Serial.print("Digital Input 1 State: ");
    Serial.println(state1);
    Serial.print("Digital Input 2 State: ");
    Serial.println(state2);

    // Wait for 100 milliseconds before reading again
    delay(100);
}
arduino ino file download:

.zip   11-input-trigger-output.zip (Size: 866 bytes / Downloads: 450)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   11-input-trigger-output.ino.merged.zip (Size: 179.47 KB / Downloads: 397)

Print this item

  [arduino code examples for A2v3]-10 Print TEXT on SSD1306 OLED displayer
Posted by: admin - 04-20-2025, 06:04 AM - Forum: KC868-A2v3 - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* This Arduino program demonstrates how to display text on an SSD1306 128x64 OLED display using the U8g2 library.
* The program draws two lines of text on the display:
* - The first line is "KINCONY" in a larger font.
* - The second line is "www.kincony.com" in a smaller font.
*
* The display is connected via I2C (software implementation) with:
* - SCL (clock) on pin IO47
* - SDA (data) on pin IO48
*
* The display's I2C address is set to 0x3C.
*/

#include <U8g2lib.h>  // Include the U8g2 library for controlling the OLED display
#include <Wire.h>     // Include the Wire library for I2C communication

// Initialize the display using the software I2C method (SCL = IO47, SDA = IO48)
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0,  47, 48, U8X8_PIN_NONE);  // Screen rotation: U8G2_R0

// Function to display page 1 content
void page1() {
  // Set font size 18 for the larger "KINCONY" text
  u8g2.setFont(u8g2_font_timR18_tf);  // Use the Times Roman font, size 18
  u8g2.setFontPosTop();               // Set the text position at the top of the display
  u8g2.setCursor(5, 0);               // Position the cursor at coordinates (5, 0)
  u8g2.print("KINCONY");              // Display the text "KINCONY" on the screen

  // Set font size 12 for the smaller "www.kincony.com" text
  u8g2.setFont(u8g2_font_timR12_tf);  // Use the Times Roman font, size 12
  u8g2.setCursor(0, 40);              // Position the cursor at coordinates (0, 40)
  u8g2.print("www.kincony.com");      // Display the text "www.kincony.com"
}

// Setup function, runs once when the program starts
void setup() {
  // Set the I2C address for the display to 0x3C
  u8g2.setI2CAddress(0x3C*2);  // I2C address shift for 8-bit format
 
  // Initialize the display
  u8g2.begin();
 
  // Enable UTF-8 character printing for the display
  u8g2.enableUTF8Print();  // Allow UTF-8 encoded text to be printed
}

// Main loop function, continuously runs after setup()
void loop() {
  // Begin the display drawing process
  u8g2.firstPage();  // Prepare the first page for drawing
  do {
    // Call the page1() function to draw content on the display
    page1();
  } while (u8g2.nextPage());  // Continue to the next page until all pages are drawn
}
arduino ino file download:

.zip   10-oled-ssd1306.zip (Size: 1.12 KB / Downloads: 419)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   10-oled-ssd1306.ino.merged.zip (Size: 201.24 KB / Downloads: 414)

Print this item

Photo KCSv3 ADC threshold does nothing with Home Assistant MQTT
Posted by: riri0 - 04-20-2025, 06:03 AM - Forum: "KCS" v3 firmware - Replies (3)

Hi. Does the ADC threshold not apply to Home Assistant MQTT? For testing, my CH1 is around 1430 to 1450, value does not go above 1450. I put 100 so it should update in MQTT the value when it go above 1500 correct? But in Home Assistant MQTT the value still update every 2 second between 1430 to 1450.
The drop in the graph is when I try reboot the board to see if threshold apply after reboot. Still same.
       

Print this item