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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 8,380
» Latest member: alhazzem5
» Forum threads: 3,653
» Forum posts: 18,879

Full Statistics

Online Users
There are currently 9 online users.
» 0 Member(s) | 4 Guest(s)
Amazonbot, bot

Latest Threads
Connect um330 and kc828 a...
Forum: DIY Project
Last Post: gtd0916
3 minutes ago
» Replies: 26
» Views: 3,396
KC868-M16v2 configure yam...
Forum: KC868-M16 / M1 / MB / M30
Last Post: admin
35 minutes ago
» Replies: 141
» Views: 25,921
KC868-HAv2 work with F24 ...
Forum: KC868-HA /HA v2
Last Post: admin
59 minutes ago
» Replies: 3
» Views: 640
Problema a cargar .bin al...
Forum: KC868-A2
Last Post: admin
1 hour ago
» Replies: 3
» Views: 25
N30 Energy entry not work...
Forum: N30
Last Post: admin
1 hour ago
» Replies: 20
» Views: 315
flash Kincony software to...
Forum: DIY Project
Last Post: admin
1 hour ago
» Replies: 3
» Views: 21
"SmartLife" wifi transmit
Forum: TA
Last Post: admin
Yesterday, 12:17 AM
» Replies: 7
» Views: 39
Kc868a newbie questions
Forum: KC868-A series and Uair Smart Controller
Last Post: admin
Yesterday, 12:16 AM
» Replies: 5
» Views: 123
KINCONY IN KSA
Forum: DIY Project
Last Post: admin
Yesterday, 12:15 AM
» Replies: 1
» Views: 15
T16M not responding on US...
Forum: T16M
Last Post: admin
01-05-2026, 12:14 PM
» Replies: 3
» Views: 23

  [arduino code examples for AIO Hybrid]-09 how to communication with Tuya Zigbee modul
Posted by: admin - 09-15-2025, 01:35 AM - Forum: AIO Hybrid - No Replies

Code:
#define TUYA_RXD 15
#define TUYA_TXD 48

void setup() {
  Serial0.begin(115200);  // Serial0
  while (!Serial0);

  Serial2.begin(115200, SERIAL_8N1, TUYA_RXD, TUYA_TXD);
  delay(100);

  byte tuya_cmd[] = {0x55, 0xAA, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04};
  Serial0.println("send data to Tuya module:");
  for (int i = 0; i < sizeof(tuya_cmd); i++) {
    Serial0.printf("%02X ", tuya_cmd[i]);
    Serial2.write(tuya_cmd[i]);
  }
  Serial0.println();
}

void loop() {
  if (Serial2.available()) {
    Serial0.print("received from tuya: ");
    while (Serial2.available()) {
      byte b = Serial2.read();
      Serial0.printf("%02X ", b);
    }
    Serial0.println();
  }

  delay(100);
}
arduino ino file download:

.zip   9-Zigbee-ZSU.zip (Size: 496 bytes / Downloads: 207)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   9-Zigbee-ZSU.ino.merged.zip (Size: 190.24 KB / Downloads: 192)

Print this item

  [arduino code examples for AIO Hybrid]-08 Ethernet W5500 chip work with TCP Server mo
Posted by: admin - 09-15-2025, 01:32 AM - Forum: AIO Hybrid - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* This Arduino program sets up an ESP32-S3 with a W5500 Ethernet module
* as a TCP server. It listens on port 4196 and echoes back any string
* received from a client.
*
* Hardware connections:
* - CLK: GPIO42
* - MOSI: GPIO43
* - MISO: GPIO44
* - CS: GPIO41
* - RST: GPIO1
* - INT: GPIO2
*
* Static IP address: 192.168.3.55
* Subnet Mask: 255.255.255.0
* Gateway: 192.168.3.1
* DNS: 192.168.3.1
*/

#include <SPI.h>
#include <Ethernet.h>

// Define the W5500 Ethernet module pins
#define W5500_CS_PIN  41
#define W5500_RST_PIN 1
#define W5500_INT_PIN 2
#define W5500_CLK_PIN 42
#define W5500_MOSI_PIN 43
#define W5500_MISO_PIN 44

// MAC address for your Ethernet shield (must be unique on your network)
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// Static IP address configuration
IPAddress ip(192, 168, 3, 55);       // Static IP address
IPAddress subnet(255, 255, 255, 0);   // Subnet mask
IPAddress gateway(192, 168, 3, 1);    // Default gateway
IPAddress dns(192, 168, 3, 1);        // DNS server address

// Create an EthernetServer object to handle TCP connections
EthernetServer server(4196);

void setup() {
  // Initialize serial communication
  Serial.begin(115200);
  while (!Serial) {
    ; // Wait for serial port to connect
  }

  // Initialize the W5500 module
  pinMode(W5500_RST_PIN, OUTPUT);
  pinMode(W5500_INT_PIN, INPUT);
  digitalWrite(W5500_RST_PIN, LOW);  // Reset the W5500 module
  delay(100);                       // Wait for reset to complete
  digitalWrite(W5500_RST_PIN, HIGH); // Release reset

  // Initialize SPI with the correct pin definitions
  SPI.begin(W5500_CLK_PIN, W5500_MISO_PIN, W5500_MOSI_PIN);

  // Set up the Ethernet library with W5500-specific pins
  Ethernet.init(W5500_CS_PIN);

  // Start the Ethernet connection with static IP configuration
  Ethernet.begin(mac, ip, dns, gateway, subnet);

  // Print the IP address to the serial monitor
  Serial.print("IP Address: ");
  Serial.println(Ethernet.localIP());

  // Start listening for incoming TCP connections
  server.begin();
}

void loop() {
  // Check for incoming client connections
  EthernetClient client = server.available();
  if (client) {
    Serial.println("New client connected");

    // Read data from the client and echo it back
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        server.write(c);
      }
    }

    // Close the connection when done
    client.stop();
    Serial.println("Client disconnected");
  }
}
arduino ino file download:

.zip   8-Ethernet-W5500.zip (Size: 1.23 KB / Downloads: 217)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   8-Ethernet-W5500.ino.merged.zip (Size: 188.93 KB / Downloads: 205)

Print this item

  [arduino code examples for AIO Hybrid]-07 how to DS3231 RTC clock
Posted by: admin - 09-15-2025, 01:31 AM - Forum: AIO Hybrid - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* DS3231 RTC with Arduino
*
* This program demonstrates how to use the DS3231 RTC (Real-Time Clock) module with the Arduino.
* It includes functionality to:
* - Initialize the DS3231 RTC module
* - Read the current date and time from the RTC
* - Set the RTC time based on a serial command:Command format: DYYYY-MM-DDTHH:MM:SS
*
* Hardware Connections:
* - SDA: GPIO 8
* - SCL: GPIO 18
*/

#include <DS3231.h>
#include <Wire.h>

String serial_cmd_rcv = ""; // Serial port receiver

typedef struct
{
  byte year;    // Last two digits of the year, library adds 2000.
  byte month;
  byte day;
  byte hour;
  byte minute;
  byte second;
} MY_DATE_STR;

MY_DATE_STR my_date_str = {0};

// Define constants for relay control
#define OPEN_RLY_DATA    26
#define OPEN_RLY_MONTH   4
#define CLOSE_RLY_DATA   2
#define CLOSE_RLY_MONTH  5

// Define pin connections
#define SDA_PIN   8
#define SCL_PIN   18

DS3231 rtc; // Create an instance of the DS3231 RTC
bool h12Flag;
bool pmFlag;
static bool bCentury = false;
static bool old_level_high = false;
static bool old_level_low = false;


/**
* @brief Print the current time from the RTC to the Serial Monitor.
*/
static void PrintfCurTime()
{
  Serial.print("Current time is: ");
  int year = rtc.getYear() + 2000;
  Serial.print(year);
  Serial.print("-");

  Serial.print(rtc.getMonth(bCentury), DEC);
  Serial.print("-");

  Serial.print(rtc.getDate(), DEC);
  Serial.print(" ");

  Serial.print(rtc.getHour(h12Flag, pmFlag), DEC);
  Serial.print(":");
  Serial.print(rtc.getMinute(), DEC);
  Serial.print(":");
  Serial.println(rtc.getSecond(), DEC);
}

/**
* @brief Process serial commands to set the RTC time.
* Command format: DYYYY-MM-DDTHH:MM:SS
*/
static void GetSerialCmd()
{
  if (Serial.available() > 0)
  {
    delay(100);
    int num_read = Serial.available();
    while (num_read--)
      serial_cmd_rcv += char(Serial.read());
  }
  else return;

  serial_cmd_rcv.trim();

  if (serial_cmd_rcv == "current time")
  {
    PrintfCurTime();
    serial_cmd_rcv = "";
    return;
  }

  Serial.print("Received length: ");
  Serial.println(serial_cmd_rcv.length());

  int indexof_d = serial_cmd_rcv.indexOf('D');
  int indexof_t = serial_cmd_rcv.indexOf('T');

  Serial.print("D index: ");
  Serial.print(indexof_d);
  Serial.print(" T index: ");
  Serial.println(indexof_t);

  if (serial_cmd_rcv.length() != 20 ||
      serial_cmd_rcv.substring(0, 1) != "D" ||
      serial_cmd_rcv.substring(11, 12) != "T") 
  {
    Serial.println(serial_cmd_rcv);
    serial_cmd_rcv = "";
    return;
  }

  Serial.println("Setting time...");

  my_date_str.year = (byte)serial_cmd_rcv.substring(3, 5).toInt();
  my_date_str.month = (byte)serial_cmd_rcv.substring(6, 8).toInt();
  my_date_str.day = (byte)serial_cmd_rcv.substring(9, 11).toInt();
  my_date_str.hour = (byte)serial_cmd_rcv.substring(12, 14).toInt();
  my_date_str.minute = (byte)serial_cmd_rcv.substring(15, 17).toInt();
  my_date_str.second = (byte)serial_cmd_rcv.substring(18).toInt();

  rtc.setYear(my_date_str.year);
  rtc.setMonth(my_date_str.month);
  rtc.setDate(my_date_str.day);
  rtc.setHour(my_date_str.hour);
  rtc.setMinute(my_date_str.minute);
  rtc.setSecond(my_date_str.second);

  serial_cmd_rcv = "";

  Serial.println("Time set.");
}

void setup() {
  // Initialize the I2C interface
  Wire.begin(SDA_PIN, SCL_PIN, 40000);
 
  // Initialize Serial communication
  Serial.begin(115200);
   
  // Set the RTC to 24-hour mode
  rtc.setClockMode(false); // 24-hour format

  // Print current time to Serial Monitor
  PrintfCurTime();

  // Clear any remaining serial data
  while (Serial.read() >= 0) {}
}

void loop() {
  // Process incoming serial commands
  GetSerialCmd();
  delay(1000); // Delay for 1 second
}
arduino ino file download:

.zip   7-DS3231-RTC.zip (Size: 1.51 KB / Downloads: 220)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   7-DS3231-RTC.ino.merged.zip (Size: 198.29 KB / Downloads: 210)

Print this item

  [arduino code examples for AIO Hybrid]-06 How to use SD Card
Posted by: admin - 09-15-2025, 01:30 AM - Forum: AIO Hybrid - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* SD Card File Operations
*
* This program demonstrates basic file operations on an SD card using the ESP32.
* It includes functionality to:
* - Initialize and test the SD card
* - Read from, write to, append to, and delete files on the SD card
* - Measure file read and write performance
*
* Hardware Connections:
* - SCK: GPIO 11
* - MISO: GPIO 12
* - MOSI: GPIO 10
* - CS: GPIO 9
*/

#include "FS.h"
#include "SD.h"
#include "SPI.h"

// Pin definitions for SD card
#define SCK  11
#define MISO 12
#define MOSI 10
#define CS   9

/**
* @brief Reads the contents of a file from the SD card and prints it to the serial monitor.
*
* @param fs File system to use (in this case, SD).
* @param path Path of the file to read.
*/
void readFile(fs::FS &fs, const char * path) {
  Serial.printf("Reading file: %s\n", path);

  File file = fs.open(path);
  if (!file) {
    Serial.println("Failed to open file for reading");
    return;
  }

  Serial.print("Read from file: ");
  while (file.available()) {
    Serial.print((char)file.read());
  }
  file.close();
}

/**
* @brief Writes a message to a file on the SD card.
*
* @param fs File system to use (in this case, SD).
* @param path Path of the file to write.
* @param message Message to write to the file.
*/
void writeFile(fs::FS &fs, const char * path, const char * message) {
  Serial.printf("Writing file: %s\n", path);

  File file = fs.open(path, FILE_WRITE);
  if (!file) {
    Serial.println("Failed to open file for writing");
    return;
  }
  if (file.print(message)) {
    Serial.println("File written");
  } else {
    Serial.println("Write failed");
  }
  file.close();
}

/**
* @brief Appends a message to a file on the SD card.
*
* @param fs File system to use (in this case, SD).
* @param path Path of the file to append.
* @param message Message to append to the file.
*/
void appendFile(fs::FS &fs, const char * path, const char * message) {
  Serial.printf("Appending to file: %s\n", path);

  File file = fs.open(path, FILE_APPEND);
  if (!file) {
    Serial.println("Failed to open file for appending");
    return;
  }
  if (file.print(message)) {
    Serial.println("Message appended");
  } else {
    Serial.println("Append failed");
  }
  file.close();
}

/**
* @brief Deletes a file from the SD card.
*
* @param fs File system to use (in this case, SD).
* @param path Path of the file to delete.
*/
void deleteFile(fs::FS &fs, const char * path) {
  Serial.printf("Deleting file: %s\n", path);
  if (fs.remove(path)) {
    Serial.println("File deleted");
  } else {
    Serial.println("Delete failed");
  }
}

/**
* @brief Tests file read and write performance.
*
* @param fs File system to use (in this case, SD).
* @param path Path of the file to test.
*/
void testFileIO(fs::FS &fs, const char * path) {
  File file = fs.open(path);
  static uint8_t buf[512];
  size_t len = 0;
  uint32_t start = millis();
  uint32_t end = start;

  if (file) {
    len = file.size();
    size_t flen = len;
    start = millis();
    while (len) {
      size_t toRead = len;
      if (toRead > 512) {
        toRead = 512;
      }
      file.read(buf, toRead);
      len -= toRead;
    }
    end = millis() - start;
    Serial.printf("%u bytes read for %u ms\n", flen, end);
    file.close();
  } else {
    Serial.println("Failed to open file for reading");
  }

  file = fs.open(path, FILE_WRITE);
  if (!file) {
    Serial.println("Failed to open file for writing");
    return;
  }

  size_t i;
  start = millis();
  for (i = 0; i < 2048; i++) {
    file.write(buf, 512);
  }
  end = millis() - start;
  Serial.printf("%u bytes written for %u ms\n", 2048 * 512, end);
  file.close();
}

void setup() {
  // Initialize serial communication
  Serial.begin(115200);
 
  // Initialize SPI and SD card
  SPIClass spi = SPIClass(HSPI);
  spi.begin(SCK, MISO, MOSI, CS);

  if (!SD.begin(CS, spi, 80000000)) {
    Serial.println("Card Mount Failed");
    return;
  }

  uint8_t cardType = SD.cardType();

  if (cardType == CARD_NONE) {
    Serial.println("No SD card attached");
    return;
  }

  Serial.print("SD Card Type: ");
  if (cardType == CARD_MMC) {
    Serial.println("MMC");
  } else if (cardType == CARD_SD) {
    Serial.println("SDSC");
  } else if (cardType == CARD_SDHC) {
    Serial.println("SDHC");
  } else {
    Serial.println("UNKNOWN");
  }

  uint64_t cardSize = SD.cardSize() / (1024 * 1024);
  Serial.printf("SD Card Size: %lluMB\n", cardSize);
  delay(2000);

  // Perform file operations
  deleteFile(SD, "/hello.txt");
  writeFile(SD, "/hello.txt", "Hello ");
  appendFile(SD, "/hello.txt", "World!\n");
  readFile(SD, "/hello.txt");
  testFileIO(SD, "/test.txt");
  Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024));
  Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024));
}

void loop() {
  // No operation in loop
}
arduino ino file download:

.zip   6-SD.zip (Size: 1.53 KB / Downloads: 205)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   6-SD.ino.merged.zip (Size: 221.05 KB / Downloads: 211)

Print this item

  [arduino code examples for AIO Hybrid]-05 IR send
Posted by: admin - 09-15-2025, 01:29 AM - Forum: AIO Hybrid - No Replies

Code:
/*
* Copyright (c) 2025 KinCony IoT
* https://www.kincony.com
*
* Description:
* This program generates a 38 kHz PWM signal on a specified GPIO pin
* using the ESP32-S3 LEDC hardware peripheral.
* The output can be used to drive an IR LED for infrared signal transmission.
*/

#include <Arduino.h>
#include "driver/ledc.h"

#define IR_SEND_PIN 14  // GPIO pin connected to the IR LED

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

  // Configure the LEDC timer
  ledc_timer_config_t ledc_timer = {
      .speed_mode = LEDC_LOW_SPEED_MODE,       // Use low-speed mode
      .duty_resolution = LEDC_TIMER_8_BIT,     // 8-bit resolution (0-255)
      .timer_num = LEDC_TIMER_0,               // Select timer 0
      .freq_hz = 38000,                        // Set frequency to 38 kHz
      .clk_cfg = LEDC_AUTO_CLK                 // Automatically select the clock source
  };
  ledc_timer_config(&ledc_timer);

  // Configure the LEDC channel
  ledc_channel_config_t ledc_channel = {
      .gpio_num = IR_SEND_PIN,                 // Output GPIO pin
      .speed_mode = LEDC_LOW_SPEED_MODE,       // Use low-speed mode
      .channel = LEDC_CHANNEL_0,               // Channel 0
      .intr_type = LEDC_INTR_DISABLE,          // Disable interrupts
      .timer_sel = LEDC_TIMER_0,                // Use timer 0
      .duty = 128,                             // 50% duty cycle (128/255)
      .hpoint = 0                              // Start at high point 0
  };
  ledc_channel_config(&ledc_channel);

  Serial.println("38kHz PWM started.");
}

void loop() {
  // Continuously output the carrier wave
}
arduino ino file download:

.zip   5-IR-send-ESP32.zip (Size: 904 bytes / Downloads: 188)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   5-IR-send-ESP32.ino.merged.zip (Size: 187.02 KB / Downloads: 167)

Print this item

  [arduino code examples for AIO Hybrid]-04 RS485 communication test
Posted by: admin - 09-15-2025, 01:28 AM - Forum: AIO Hybrid - 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 16 and RXD pin is defined as GPIO 17.
*/

#include <HardwareSerial.h>

// Define RS485 pins
#define RS485_RXD 47
#define RS485_TXD 3

// 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 Controller!");

  // 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: 766 bytes / Downloads: 167)
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: 189.46 KB / Downloads: 175)

Print this item

  [arduino code examples for AIO Hybrid]-03 Read analog input ports value
Posted by: admin - 09-15-2025, 01:27 AM - Forum: AIO Hybrid - 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, A3, A4)
* 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 5
* - A2: GPIO 7
* - A3: GPIO 6
* - A4: GPIO 4
*/

#define ANALOG_A1   5   // Define GPIO pin for analog input A1
#define ANALOG_A2   7   // Define GPIO pin for analog input A2
#define ANALOG_A3   6   // Define GPIO pin for analog input A3
#define ANALOG_A4   4   // Define GPIO pin for analog input A4

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
    pinMode(ANALOG_A3, INPUT); // Set GPIO 6 as an input for analog signal A3
    pinMode(ANALOG_A4, INPUT); // Set GPIO 4 as an input for analog signal A4
}

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
    Serial.print("A3=");
    Serial.println(analogRead(ANALOG_A3)); // Read and print the value from A3
    Serial.print("A4=");
    Serial.println(analogRead(ANALOG_A4)); // Read and print the value from A4
   
    delay(2000); // Wait for 2 seconds before the next reading
}
arduino ino file download:

.zip   3-analog-input.zip (Size: 769 bytes / Downloads: 168)
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: 189.25 KB / Downloads: 194)

Print this item

  [arduino code examples for AIO Hybrid]-02 Read digital input ports state
Posted by: admin - 09-15-2025, 01:26 AM - Forum: AIO Hybrid - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* Description:
* This Arduino program continuously reads 12 digital inputs (P0~P11)
* from a PCF8575 I/O expander and prints their states to the Serial Monitor
* in binary format (0 = ON, 1 = OFF).
*
* Pin Definitions:
* - SDA: GPIO 8
* - SCL: GPIO 18
* - PCF8575 I2C Address: 0x24
*/

#include <Arduino.h>
#include <Wire.h>
#include "PCF8575.h"

// I2C pin definitions
#define I2C_SDA 8
#define I2C_SCL 18

// PCF8575 object with I2C address 0x24
PCF8575 pcf8575_IN1(0x24);

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

    // Initialize I2C communication
    Wire.begin(I2C_SDA, I2C_SCL);

    // Initialize the PCF8575
    pcf8575_IN1.begin();

    Serial.println("Input state: 0=ON, 1=OFF");
}

void loop() {
    uint16_t state = 0;

    // Read the state of P0~P11
    for (int pin = 0; pin <= 11; pin++) {
        if (pcf8575_IN1.read(pin)) {
            state |= (1 << pin);
        }
    }

    // Print the state in binary format
    Serial.print("Input state: ");
    for (int pin = 11; pin >= 0; pin--) {
        Serial.print((state >> pin) & 1);
    }
    Serial.println();

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

.zip   2-digital-input.zip (Size: 764 bytes / Downloads: 183)
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: 196.89 KB / Downloads: 174)

Print this item

  [arduino code examples for AIO Hybrid]-01 Turn ON/OFF relay
Posted by: admin - 09-15-2025, 01:24 AM - Forum: AIO Hybrid - No Replies

Code:
/*
* PCF8574 Relay Control Example
*
* Controls 5 relays connected to PCF8574 via I2C bus.
*
* Made By KinCony
* https://www.kincony.com
*/

#include <Arduino.h>
#include <Wire.h>
#include "PCF8574.h"

// I2C pin definitions
#define I2C_SDA 8
#define I2C_SCL 18

// Create PCF8574 object with I2C address 0x26
PCF8574 pcf8574(0x26);

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

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

  // Set PCF8574 P3~P7 as OUTPUT (Relays)
  pcf8574.pinMode(P3, OUTPUT);
  pcf8574.pinMode(P4, OUTPUT);
  pcf8574.pinMode(P5, OUTPUT);
  pcf8574.pinMode(P6, OUTPUT);
  pcf8574.pinMode(P7, OUTPUT);

  Serial.print("Init pcf8574...");
  if (pcf8574.begin()) {
    Serial.println("OK");
  } else {
    Serial.println("KO");
    while (1); // Stop if initialization fails
  }

  // Turn OFF all relays at startup
  for (int pin = P3; pin <= P7; pin++) {
    pcf8574.digitalWrite(pin, LOW);
  }
}

void loop() {
  // Turn ON all relays one by one
  for (int pin = P3; pin <= P7; pin++) {
    pcf8574.digitalWrite(pin, HIGH);
    delay(500);
  }

  delay(1000); // Keep all relays ON for a while

  // Turn OFF all relays
  for (int pin = P3; pin <= P7; pin++) {
    pcf8574.digitalWrite(pin, LOW);
  }

  delay(1000); // Keep all relays OFF for a while
}
arduino ino file download:

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

.zip   1-relay.ino.merged.zip (Size: 198.37 KB / Downloads: 166)

Print this item

  AIO Hybrid ESPHome yaml for home assistant without tuya
Posted by: admin - 09-15-2025, 01:19 AM - Forum: AIO Hybrid - No Replies

Code:
esphome:
  name: aio-hybrid
  friendly_name: AIO-hybrid
  platformio_options:
    board_build.flash_mode: dio

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: esp-idf
    sdkconfig_options:
      SOC_RMT_SUPPORT_RX_PINGPONG: "n"
# Enable logging
logger:
  hardware_uart: USB_SERIAL_JTAG
# Enable Home Assistant API
api:

uart:
  - id: uart_zsu
    baud_rate: 115200
    debug:
      direction: BOTH
      dummy_receiver: true
      after:
        timeout: 10ms
      sequence:
        - lambda: UARTDebug::log_string(direction, bytes);
    tx_pin: 15
    rx_pin: 48

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

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

pcf8574:
  - id: 'pcf8574_hub_output_1'  # for output channel 5
    i2c_id: bus_a
    address: 0x26

  - id: 'pcf8574_hub_input_1'  # for input channel 1-12
    i2c_id: bus_a
    address: 0x24
    pcf8575: true


switch:

  - platform: uart
    uart_id: uart_zsu
    name: "UART zigbee"
    data: [0x55, 0xaa, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04] # ZSU zigbee module 

  - platform: gpio
    name: "AIO_hybrid-output01"
    id: "AIO_hybrid_output01"
    pin:
      pcf8574: pcf8574_hub_output_1
      number: 3
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: "AIO_hybrid-output02"
    id: "AIO_hybrid_output02"
    pin:
      pcf8574: pcf8574_hub_output_1
      number: 4
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: "AIO_hybrid-output03"
    id: "AIO_hybrid_output03"
    pin:
      pcf8574: pcf8574_hub_output_1
      number: 5
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: "AIO_hybrid-output04"
    id: "AIO_hybrid_output04"
    pin:
      pcf8574: pcf8574_hub_output_1
      number: 6
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: "AIO_hybrid-output05"
    id: "AIO_hybrid_output05"
    pin:
      pcf8574: pcf8574_hub_output_1
      number: 7
      mode: OUTPUT
      inverted: true

  - platform: template
    name: IR-Send1
    turn_on_action:
      - remote_transmitter.transmit_pronto:
          transmitter_id: ir1
          data: "0000 006C 0022 0002 015B 00AD 0016 0041 0016 0016 0016 0041 0016 0016 0016 0016 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0041 0016 0041 0016 0041 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 0575 015B 0057 0016 0E6C"

binary_sensor:
  - platform: gpio
    name: "AIO_hybrid-input01"
    id: "AIO_hybrid_input01"
    pin:
      pcf8574: pcf8574_hub_input_1
      number: 0
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "AIO_hybrid-input02"
    id: "AIO_hybrid_input02"
    pin:
      pcf8574: pcf8574_hub_input_1
      number: 1
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "AIO_hybrid-input03"
    id: "AIO_hybrid_input03"
    pin:
      pcf8574: pcf8574_hub_input_1
      number: 2
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "AIO_hybrid-input04"
    id: "AIO_hybrid_input04"
    pin:
      pcf8574: pcf8574_hub_input_1
      number: 3
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "AIO_hybrid-input05"
    id: "AIO_hybrid_input05"
    pin:
      pcf8574: pcf8574_hub_input_1
      number: 4
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "AIO_hybrid-input06"
    id: "AIO_hybrid_input06"
    pin:
      pcf8574: pcf8574_hub_input_1
      number: 5
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "AIO_hybrid-input07"
    id: "AIO_hybrid_input07"
    pin:
      pcf8574: pcf8574_hub_input_1
      number: 6
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "AIO_hybrid-input08"
    id: "AIO_hybrid_input08"
    pin:
      pcf8574: pcf8574_hub_input_1
      number: 7
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "AIO_hybrid-input09"
    id: "AIO_hybrid_input09"
    pin:
      pcf8574: pcf8574_hub_input_1
      number: 8
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "AIO_hybrid-input10"
    id: "AIO_hybrid_input10"
    pin:
      pcf8574: pcf8574_hub_input_1
      number: 9
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "AIO_hybrid-input11"
    id: "AIO_hybrid_input11"
    pin:
      pcf8574: pcf8574_hub_input_1
      number: 10
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "AIO_hybrid-input12"
    id: "AIO_hybrid_input12"
    pin:
      pcf8574: pcf8574_hub_input_1
      number: 11
      mode: INPUT
      inverted: true

## without resistance on PCB
  - platform: gpio
    name: "AIO_hybrid-433M"
    pin:
      number: 40
      inverted:  false

  - platform: gpio
    name: "AIO_hybrid-io0"
    pin:
      number: 0
      inverted:  false

mcp4728:
  - id: dac_output

output:
- platform: mcp4728
  id: dimmer1
  mcp4728_id: dac_output
  channel: A
  vref: vdd
  power_down: normal # default

- platform: mcp4728
  id: dimmer2
  mcp4728_id: dac_output
  channel: B
  vref: vdd
  power_down: normal # default

- platform: mcp4728
  id: dimmer3
  mcp4728_id: dac_output
  channel: C
  vref: vdd
  power_down: normal # default

- platform: mcp4728
  id: dimmer4
  mcp4728_id: dac_output
  channel: D
  vref: vdd
  power_down: normal # default

light:
  - platform: monochromatic
    name: "dimmer-1"
    output: dimmer1
    gamma_correct: 1.0

  - platform: monochromatic
    name: "dimmer-2"
    output: dimmer2
    gamma_correct: 1.0

  - platform: monochromatic
    name: "dimmer-3"
    output: dimmer3
    gamma_correct: 1.0

  - platform: monochromatic
    name: "dimmer-4"
    output: dimmer4
    gamma_correct: 1.0

  - platform: esp32_rmt_led_strip
    rgb_order: GRB
    pin: GPIO21
    num_leds: 20
    chipset: ws2812
    name: "My Light IO21"

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), "AIO-hybrid");

sensor:
  - platform: adc
    pin: 5
    name: "AIO_hybrid A1 Voltage"
    update_interval: 55s
    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: 7
    name: "AIO_hybrid A2 Voltage"
    update_interval: 55s
    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;
          }
  - platform: adc
    pin: 6
    name: "AIO_hybrid A3 Current"
    update_interval: 55s
    unit_of_measurement: mA
    attenuation: 11db
    filters:
      - multiply: 6.66666666
  - platform: adc
    pin: 4
    name: "AIO_hybrid A4 Current"
    update_interval: 55s
    unit_of_measurement: mA
    attenuation: 11db
    filters:
      - multiply: 6.66666666

remote_receiver:
  pin: 17
  dump: all

remote_transmitter:
  - id: ir1
    pin: 14
    carrier_duty_percent: 50%



web_server:
  port: 80
download yaml file:

.txt   AIO-hybrid_pin_define-HA-without-Tuya.txt (Size: 7.62 KB / Downloads: 130)

Print this item