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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 10,550
» Latest member: neurobalancetec
» Forum threads: 4,337
» Forum posts: 21,344

Full Statistics

Online Users
There are currently 52 online users.
» 0 Member(s) | 39 Guest(s)
Applebot, Baidu, Bytespider, Crawl, Google, PetalBot, bot

Latest Threads
KCS debounce option for K...
Forum: KC868-A16
Last Post: tech1977
1 hour ago
» Replies: 0
» Views: 14
[arduino code examples fo...
Forum: F32
Last Post: admin
9 hours ago
» Replies: 0
» Views: 15
[arduino code examples fo...
Forum: F32
Last Post: admin
9 hours ago
» Replies: 0
» Views: 14
KC868-A16 wiring diagram
Forum: KC868-A16
Last Post: admin
Yesterday, 09:31 PM
» Replies: 24
» Views: 22,059
N20 energy
Forum: N20
Last Post: admin
Yesterday, 09:29 PM
» Replies: 1
» Views: 20
Automatic Modbus Sensor p...
Forum: "KCS" v3 firmware
Last Post: admin
Yesterday, 09:27 PM
» Replies: 4
» Views: 115
[arduino code examples fo...
Forum: CO16
Last Post: admin
Yesterday, 04:33 AM
» Replies: 0
» Views: 20
KC868-A8 PCB V1.7 - Maxim...
Forum: KC868-A8
Last Post: admin
11-16-2026, 09:29 AM
» Replies: 1
» Views: 53
Device change after damag...
Forum: Getting Started with ESPHome and Home Assistant
Last Post: grayweird
11-16-2026, 04:43 AM
» Replies: 2
» Views: 775
CT Clamp Compatibility
Forum: KC868-M16 / M1 / MB / M30
Last Post: admin
11-14-2026, 11:38 PM
» Replies: 16
» Views: 3,843

Lightbulb ⚡ 40 Buttons, 36 Lighting Circuits & Home Assistant — How Would You Build It?
Posted by: viko - 09-02-2026, 09:08 AM - Forum: DIY Project - Replies (24)

Hello everyone,
I recently discovered KinCony while researching home automation solutions, and I would really appreciate your advice before finalizing my installation.
I am currently completely rewiring my house from scratch, and I wanted to take the opportunity to integrate home automation from the beginning. Just two weeks ago, my knowledge of home automation was practically zero, so I have learned a lot in a very short time. I now want to make sure that the architecture I am planning makes sense before I install all the equipment.
My goal is to have a reliable, mainly wired and locally controlled installation, with Home Assistant as the central system.
? My overall installation
I plan to run Home Assistant on a mini PC, together with the other home automation software.
For the electrical installation, I will have a central electrical panel with separate circuits for the different parts of the house. I will bring the lighting circuits back to the electrical panel and use terminal blocks to keep the wiring organized.

For lighting control, I currently plan to use KinCony A16S modules for the physical inputs. I am considering using three A16S modules because I have around 40 buttons/switches to manage, as well as some additional sensors and equipment such as SHT30 sensors, flow meters and some controls related to the hot water tank.

The idea is that the wall switches will not directly control the 230 V lighting circuits. Instead, they will be connected to the low-voltage inputs of the A16S modules, while Home Assistant/KinCony will handle the logic and control of the outputs.
I believe I now have a good understanding of the wiring logic for this part. I still need to learn how to properly draw electrical diagrams so that I can show you the wiring in more detail.

For the power side, my basic principle would be something like:
10 A circuit breaker → KinCony relay → output → light

I am still working out exactly how I will wire the A16S modules and the relay/output side, so I would particularly appreciate the advice of people who have built a similar installation.
 ? Lighting
I have quite a lot of separate lighting circuits because I want to keep a high degree of flexibility in the installation.
The lighting circuits will all come back to the electrical panel, where switching will be handled by the KinCony system/relays rather than installing a home automation module behind every wall switch.
I would also like to have dimming capability, particularly in the living room and bedroom, on the 2 or 3 circuits concerned. I will of course use dimmable bulbs.
For this part, I am currently considering using SUNRICHER SR-ZG9042A-D Zigbee dimmers, installed directly in the electrical panel. I would therefore like your opinion on this solution, and whether there is a better KinCony solution or another simpler and more cost-effective architecture that you would recommend for dimming.

? Hot water tank
For the electric hot water tank, I plan to control it from the electrical panel through a suitable 25 A AC/DC contactor.

The idea is to use the standard Linky automatic control/tariff signal, with an additional layer of management through Home Assistant so that I can adapt the operating schedule to my needs, while keeping a conventional and safe electrical installation.

❄️Air conditioning / heating
I will also have several air-conditioning units as well as a pellet stove for heating.
I don't think these systems will necessarily be directly connected to the KinCony part. I will rather look for a suitable integration for each piece of equipment so that they can be integrated into Home Assistant.

? Roller shutters
The roller shutters will be installed by a professional company. I am simply planning to provide them with SONOFF MINI-ZBRBS-E switches/controllers so that they can be integrated from the beginning.

The goal is to use Zigbee for the shutter control while keeping a physical local control.
However, I would like your opinion on this approach, particularly regarding the proper management of the motor's up/down interlocking and safety, and what equipment you would recommend if I eventually decided not to use the Zigbee solution.

? Zigbee
I am also considering using an SMLIGHT SLZB-MR4U, connected via Ethernet/PoE, mainly to manage Zigbee devices over the network.
The idea is to use Zigbee for wireless devices where it makes sense, particularly roller shutters, dimmers and some sensors, while keeping the important parts of the installation wired.
I would mainly like to know how you would organize this part alongside the KinCony equipment, and whether you think there is a simpler or more cost-effective solution.

?️ Temperature / humidity sensors
I also plan to use several temperature and humidity sensors, including Modbus RTU sensors.
I am planning to use both the SHT30 Tiny and the standard versions. The Tiny models will be used discreetly in the rooms of the house where I want the sensor to be as unobtrusive as possible, while the standard versions will mainly be used in places such as the basement, workshop or technical areas, where appearance is less important.
I would therefore mainly like your opinion on these two models and whether you think they are suitable for these different applications.

? Flow meters and valves
I would also like to have the possibility of managing flow meters and motorized valves, for example to measure certain water flows and control valves from Home Assistant.
I am currently looking at the KinCony solutions available for flow meters and 12/24 V motorized valves, but I am not yet sure what the best architecture would be for this part.

? Network
Everything important will be connected via Ethernet.
I am planning a small network rack with a managed/PoE switch, a patch panel and the Home Assistant server.

The KinCony modules will also be connected to the network where appropriate, rather than having all the equipment physically installed next to the PC.
I am trying to keep the installation modular so that I can add sensors, cameras and other devices later without having to completely redesign the system.
❓ What I would like your opinion on
Everything is still being prepared, so I would really appreciate your corrections and suggestions.
In particular:

  • Does this overall architecture seem coherent to you?
  • Does using three A16S modules make sense for this installation and around 40 buttons, a few SHT30 sensors, flow meters and the control of some equipment such as the hot water tank?
  • Is there a better KinCony module or architecture that you would recommend?
  • Am I missing any important component or connection?
  • Are there simpler and more cost-effective solutions that could achieve the same result?
  • Are there any limitations of the A16S modules or the KinCony ecosystem that I should be aware of before committing to this installation?
  • For roller shutters, what solution would you recommend to properly handle the up/down interlocking and safety if I don't use the Zigbee solution?
  • Do you think the SHT30 Tiny and standard versions are suitable for these two different applications?
  • What would you consider the best KinCony solution for flow meters and motorized valves?
  • Is there anything I should plan for now, while the walls, cables and electrical panels are still accessible?
Is there anything you would do differently if you were starting this installation today?  ❤️

I am deliberately trying to plan everything before pulling the cables, so I would rather discover a better solution now than have to modify the installation later. I will of course continue researching the forum and KinCony documentation in parallel.

This is quite a long message, and I may have forgotten some details, so please feel free to ask if anything is unclear.

Thank you very much for taking the time to read this and for any advice, corrections or suggestions! ?❤️
Thanks everyone! ?

Print this item

  KinCony CO16 ESP32S3 16 Channel Analog Input Controller released
Posted by: admin - 09-02-2026, 01:51 AM - Forum: News - No Replies

KinCony CO16 ESP32 smart controller based on ESP32-S3-WROOM-1U (N16R8) wifi chip. Support 16 channel relay output and 16 channel digital input ports, 16 channel ADS1115 16bit analog input ports. One SD card using SPI bus. CO16 include DS3231 high precision RTC clock chip. Color ST7789 TFT LCD display will show wifi and ethernet IP address and Tuya connection state. CO16 have SIM7600E 4G module slot and RS485 port. CO16 support MAX 4 channel PT100 RTD (Resistance Temperature Detector). You can write any code by Arduino IDE / MicroPython / ESP-IDF development tool to ESP32 module. We will supply Arduino / ESP-IDF demo code for different samples. Everyone can modify and change the code for your own smart home automation system project. it support use by ESPHome for home assistant or tasmota firmware for smart home automation DIY. CO16 use KCS v3 firmware, it support home assistant auto discovery function by MQTT, so without write any config code (zero code) for home assistant. KCS v3 support KinCony cloud service (official shop customer free 2 years), remote monitor and control device by webpage in anywhere. KCS v3 support KinCony board integrate to Loxone Miniserver. Support Apple HomeKit for Siri.
[Image: CO16-2.jpg]
Model No. KinCony CO16
Description: KinCony ESP32-S3 16 Channel Analog Input Smart Controller – CO16
Power supply: 12-24V DC
Processor: ESP32-S3-WROOM-1U (N16R8)
Size: 225mm*83mm*56mm
interfaces: Ethernet(RJ45)-LAN 100Mbps IPv4/IPv6,WiFi,RS485,Bluetooth,USB-C,LCD,Tuya Module, 4G SIM7600
RTC: DS3231 high precision chip (battery socket on PCB)
SD Card: SPI bus
Installation method: DIN RAIL
TFT LCD: ST7789 SPI display
Outputs:
16CH relay Outputs, every relay use by MAX AC250V/7A
Inputs:
ADS1115 16bit ADC: 16CH analog input DC0-10V or 4-20mA (set by jumper)
jumper: short UP: set for DC 0-10V signal.
jumper: short DOWN: set for DC 4-20mA signal.
16CH dry contact inputs (optocoupler isolation, long distance circuit for MAX 500 meters cable)
3 buttons: 1:ESP32 Reset 2:ESP32 Download 3:Tuya config
PT100 RTD: 4CH (read by MAX31865, switch channel by NX3L4051)
[Image: CO16-1.jpg]
software solution:
1. download KinCony KCS v3 firmware, so that work with multi protocol: HTTP, MQTT, Modbus(RS485/TCP), BACnet(RS485/TCP), DMX512, Tuya app, config OUTPUT for “momentary” and “interlock” group functions. use Tuya mobile phone app directly, support voice control by Alexa and Google home speaker directly. if you want local voice control without internet, you can add KinCony AS voice assistant. “KCS” support IFTTT function work locally without internet. It also support use by KinCony cloud server. KCS v3 support home assistant auto discovery function by MQTT, so without any config file for home assistant.
2. download firmware by ESPHome, integrate to home assistant or use by web service.
3. download tasmota firmware.
4. write your own arudino or ESP-IDF code for your own requirements.
5. It is recommended to use home assistant and Tuya mobile phone app at the same time. So that remote control by internet using Tuya app, local control by LAN using home assistant app.
[Image: KinCony-CO16-smart-controller-diagram.jpg]

Print this item

  No ethernet communication
Posted by: philippe - 09-02-2026, 01:25 AM - Forum: KC868-A series and Uair Smart Controller - Replies (10)

Hi, I just received a new  board. I cant accees it through ethernet. I guess the kcs comes with dhcp enabled. if yes, I cant see it with a scanner, I cant find it with the kincony scan tool. I reflashed with esp home and the A8 yaml file, no way. I reflash with the kincony flashing tool and kscv3, no way. The port I am using on the switch is fine, thats the one I am using for my PC . By the way, the board is V1.7.1, I is it the new board? I hope so, I just got it, expecting to use it with 1wire sensors expecting the kcs v3 to solve my 1wire instable sensors issue.
Thanks
     

Print this item

  [arduino code examples for CO16]-10 ST7789 TFT color display
Posted by: admin - 08-31-2026, 12:16 AM - Forum: CO16 - No Replies

Code:
#include <Adafruit_GFX.h>
#include <driver/gpio.h>
#include <driver/spi_master.h>
#include <esp_heap_caps.h>

namespace {

// CO16 ST7789 (GMT020-02-7P) pin mapping from kcs_co16.h.
constexpr gpio_num_t kTftSclk = GPIO_NUM_11;
constexpr gpio_num_t kTftMosi = GPIO_NUM_10;
constexpr gpio_num_t kTftMiso = GPIO_NUM_12;
constexpr gpio_num_t kTftCs = GPIO_NUM_4;
constexpr gpio_num_t kTftDc = GPIO_NUM_0;
constexpr gpio_num_t kTftReset = GPIO_NUM_5;
constexpr gpio_num_t kTftBacklight = GPIO_NUM_40;

constexpr int16_t kDisplayWidth = 320;
constexpr int16_t kDisplayHeight = 240;
constexpr int16_t kTransferChunkHeight = 10;
constexpr uint32_t kDisplaySpiFrequency = 20 * 1000 * 1000;
constexpr uint8_t kCo16Madctl = 0x68;  // MX | MV | BGR.

constexpr uint16_t kBlack = 0x0000;
constexpr uint16_t kBlue = 0x001F;
constexpr uint16_t kRed = 0xF800;
constexpr uint16_t kGreen = 0x07E0;
constexpr uint16_t kCyan = 0x07FF;
constexpr uint16_t kMagenta = 0xF81F;
constexpr uint16_t kYellow = 0xFFE0;
constexpr uint16_t kWhite = 0xFFFF;

class Co16St7789 : public Adafruit_GFX {
public:
  Co16St7789() : Adafruit_GFX(kDisplayWidth, kDisplayHeight) {}

  bool begin() {
    gpio_reset_pin(kTftCs);
    gpio_set_direction(kTftCs, GPIO_MODE_OUTPUT);
    gpio_set_level(kTftCs, 1);

    gpio_reset_pin(kTftDc);
    gpio_set_direction(kTftDc, GPIO_MODE_OUTPUT);
    gpio_set_level(kTftDc, 1);

    gpio_reset_pin(kTftBacklight);
    gpio_set_direction(kTftBacklight, GPIO_MODE_OUTPUT);
    gpio_set_level(kTftBacklight, 0);

    spi_bus_config_t busConfig = {};
    busConfig.sclk_io_num = kTftSclk;
    busConfig.mosi_io_num = kTftMosi;
    busConfig.miso_io_num = kTftMiso;
    busConfig.quadwp_io_num = -1;
    busConfig.quadhd_io_num = -1;
    busConfig.max_transfer_sz =
        kDisplayWidth * kTransferChunkHeight * sizeof(uint16_t);

    esp_err_t err =
        spi_bus_initialize(SPI3_HOST, &busConfig, SPI_DMA_CH_AUTO);
    if (err != ESP_OK) {
      Serial.printf("SPI3 initialization failed: %s\n", esp_err_to_name(err));
      return false;
    }

    spi_device_interface_config_t deviceConfig = {};
    deviceConfig.clock_speed_hz = kDisplaySpiFrequency;
    deviceConfig.mode = 0;
    deviceConfig.spics_io_num = -1;
    deviceConfig.queue_size = 1;

    err = spi_bus_add_device(SPI3_HOST, &deviceConfig, &spiDevice_);
    if (err != ESP_OK) {
      Serial.printf("ST7789 SPI device setup failed: %s\n",
                    esp_err_to_name(err));
      return false;
    }

    drawBuffer_ = static_cast<uint8_t*>(heap_caps_malloc(
        kDisplayWidth * kTransferChunkHeight * sizeof(uint16_t),
        MALLOC_CAP_DMA));
    if (drawBuffer_ == nullptr) {
      Serial.println("ST7789 DMA buffer allocation failed");
      return false;
    }

    // GPIO5 is shared with the optional LoRa module. Match the working KCS
    // firmware and issue one reset pulse before initializing the controller.
    gpio_reset_pin(kTftReset);
    gpio_set_direction(kTftReset, GPIO_MODE_OUTPUT);
    gpio_set_level(kTftReset, 1);
    delay(1);
    gpio_set_level(kTftReset, 0);
    delay(1);
    gpio_set_level(kTftReset, 1);
    delay(10);

    if (!initializeController()) {
      return false;
    }

    fillScreen(kBlack);
    delay(120);
    if (!writeCommand(0x29)) {  // Display on.
      return false;
    }
    delay(120);

    gpio_set_level(kTftBacklight, 1);
    initialized_ = true;
    return true;
  }

  void drawPixel(int16_t x, int16_t y, uint16_t color) override {
    fillRect(x, y, 1, 1, color);
  }

  void writePixel(int16_t x, int16_t y, uint16_t color) override {
    fillRect(x, y, 1, 1, color);
  }

  void fillRect(int16_t x, int16_t y, int16_t width, int16_t height,
                uint16_t color) override {
    if (x < 0) {
      width += x;
      x = 0;
    }
    if (y < 0) {
      height += y;
      y = 0;
    }
    if (x + width > kDisplayWidth) {
      width = kDisplayWidth - x;
    }
    if (y + height > kDisplayHeight) {
      height = kDisplayHeight - y;
    }
    if (drawBuffer_ == nullptr || width <= 0 || height <= 0) {
      return;
    }

    const uint8_t high = color >> 8;
    const uint8_t low = color;
    for (int16_t row = y; row < y + height;
         row += kTransferChunkHeight) {
      const int16_t chunkHeight =
          min<int16_t>(kTransferChunkHeight, y + height - row);
      const size_t pixelCount = width * chunkHeight;
      for (size_t index = 0; index < pixelCount; ++index) {
        drawBuffer_[index * 2] = high;
        drawBuffer_[index * 2 + 1] = low;
      }

      if (!setWindow(x, row, x + width, row + chunkHeight) ||
          !writePixels(drawBuffer_, pixelCount * sizeof(uint16_t))) {
        Serial.println("ST7789 pixel transfer failed");
        return;
      }
    }
  }

  void writeFillRect(int16_t x, int16_t y, int16_t width, int16_t height,
                     uint16_t color) override {
    fillRect(x, y, width, height, color);
  }

  bool initialized() const { return initialized_; }

private:
  bool transmit(const void* data, size_t length, int dcLevel) {
    if (data == nullptr || length == 0) {
      return true;
    }

    gpio_set_level(kTftDc, dcLevel);
    spi_transaction_t transaction = {};
    transaction.length = length * 8;
    transaction.tx_buffer = data;
    const esp_err_t err = spi_device_polling_transmit(spiDevice_, &transaction);
    if (err != ESP_OK) {
      Serial.printf("ST7789 SPI transfer failed: %s\n", esp_err_to_name(err));
      return false;
    }
    return true;
  }

  bool writeCommand(uint8_t command) {
    gpio_set_level(kTftCs, 0);
    const bool success = transmit(&command, sizeof(command), 0);
    gpio_set_level(kTftCs, 1);
    return success;
  }

  bool writeCommandData(uint8_t command, const uint8_t* data, size_t length) {
    gpio_set_level(kTftCs, 0);
    const bool success = transmit(&command, sizeof(command), 0) &&
                         transmit(data, length, 1);
    gpio_set_level(kTftCs, 1);
    return success;
  }

  bool setWindow(int16_t x1, int16_t y1, int16_t x2, int16_t y2) {
    const uint8_t columns[] = {
        static_cast<uint8_t>(x1 >> 8), static_cast<uint8_t>(x1),
        static_cast<uint8_t>((x2 - 1) >> 8), static_cast<uint8_t>(x2 - 1),
    };
    const uint8_t rows[] = {
        static_cast<uint8_t>(y1 >> 8), static_cast<uint8_t>(y1),
        static_cast<uint8_t>((y2 - 1) >> 8), static_cast<uint8_t>(y2 - 1),
    };
    return writeCommandData(0x2A, columns, sizeof(columns)) &&
           writeCommandData(0x2B, rows, sizeof(rows));
  }

  bool writePixels(const uint8_t* data, size_t length) {
    constexpr uint8_t kRamWrite = 0x2C;
    gpio_set_level(kTftCs, 0);
    const bool success = transmit(&kRamWrite, sizeof(kRamWrite), 0) &&
                         transmit(data, length, 1);
    gpio_set_level(kTftCs, 1);
    return success;
  }

  bool initializeController() {
    const uint8_t madctl[] = {kCo16Madctl};
    const uint8_t displayFunction[] = {0x0A, 0x82};
    const uint8_t pixelFormat[] = {0x55};
    const uint8_t porchControl[] = {0x0C, 0x0C, 0x00, 0x33, 0x33};
    const uint8_t gateControl[] = {0x35};
    const uint8_t vcom[] = {0x28};
    const uint8_t lcmControl[] = {0x0C};
    const uint8_t vdvVrhEnable[] = {0x01, 0xFF};
    const uint8_t vrh[] = {0x10};
    const uint8_t vdv[] = {0x20};
    const uint8_t frameRate[] = {0x0F};
    const uint8_t powerControl[] = {0xA4, 0xA1};
    const uint8_t positiveGamma[] = {
        0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x32,
        0x44, 0x42, 0x06, 0x0E, 0x12, 0x14, 0x17,
    };
    const uint8_t negativeGamma[] = {
        0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x31,
        0x54, 0x47, 0x0E, 0x1C, 0x17, 0x1B, 0x1E,
    };

    if (!writeCommand(0x11)) {  // Sleep out.
      return false;
    }
    delay(120);

    return writeCommand(0x13) &&
           writeCommandData(0x36, madctl, sizeof(madctl)) &&
           writeCommandData(0xB6, displayFunction, sizeof(displayFunction)) &&
           writeCommandData(0x3A, pixelFormat, sizeof(pixelFormat)) &&
           (delay(10), true) &&
           writeCommandData(0xB2, porchControl, sizeof(porchControl)) &&
           writeCommandData(0xB7, gateControl, sizeof(gateControl)) &&
           writeCommandData(0xBB, vcom, sizeof(vcom)) &&
           writeCommandData(0xC0, lcmControl, sizeof(lcmControl)) &&
           writeCommandData(0xC2, vdvVrhEnable, sizeof(vdvVrhEnable)) &&
           writeCommandData(0xC3, vrh, sizeof(vrh)) &&
           writeCommandData(0xC4, vdv, sizeof(vdv)) &&
           writeCommandData(0xC6, frameRate, sizeof(frameRate)) &&
           writeCommandData(0xD0, powerControl, sizeof(powerControl)) &&
           writeCommandData(0xE0, positiveGamma, sizeof(positiveGamma)) &&
           writeCommandData(0xE1, negativeGamma, sizeof(negativeGamma)) &&
           writeCommand(0x21);  // Display inversion on.
  }

  spi_device_handle_t spiDevice_ = nullptr;
  uint8_t* drawBuffer_ = nullptr;
  bool initialized_ = false;
};

Co16St7789 display;
uint32_t frameCount = 0;

void drawColorBars() {
  constexpr uint16_t colors[] = {
      kRed,
      kGreen,
      kBlue,
      kCyan,
      kMagenta,
      kYellow,
  };
  constexpr size_t colorCount = sizeof(colors) / sizeof(colors[0]);
  const int barWidth = kDisplayWidth / colorCount;

  for (size_t index = 0; index < colorCount; ++index) {
    const int x = index * barWidth;
    const int width =
        (index == colorCount - 1) ? kDisplayWidth - x : barWidth;
    display.fillRect(x, 132, width, 44, colors[index]);
  }
}

void drawStaticScreen() {
  display.fillScreen(kBlack);
  display.drawRect(0, 0, kDisplayWidth, kDisplayHeight, kWhite);

  display.setTextWrap(false);
  display.setTextColor(kCyan);
  display.setTextSize(3);
  display.setCursor(34, 20);
  display.print("KinCony CO16");

  display.setTextColor(kWhite);
  display.setTextSize(2);
  display.setCursor(24, 64);
  display.print("ST7789 display test");
  display.setCursor(24, 92);
  display.print("SPI3 native driver");

  drawColorBars();

  display.setTextColor(kGreen);
  display.setCursor(24, 194);
  display.print("Frame:");
}

void updateFrameCounter() {
  display.fillRect(108, 190, 190, 28, kBlack);
  display.setTextColor(kGreen);
  display.setTextSize(2);
  display.setCursor(108, 194);
  display.print(frameCount++);
}

}  // namespace

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

  Serial.println();
  Serial.println("KinCony CO16 standalone ST7789 example");
  Serial.printf("SPI3 SCLK=%d MOSI=%d MISO=%d CS=%d mode=0 clock=%u Hz\n",
                kTftSclk, kTftMosi, kTftMiso, kTftCs,
                kDisplaySpiFrequency);
  Serial.printf("LCD DC=%d RESET=%d BACKLIGHT=%d\n", kTftDc, kTftReset,
                kTftBacklight);

  if (!display.begin()) {
    Serial.println("Display initialization failed");
    while (true) {
      delay(1000);
    }
  }

  drawStaticScreen();
  updateFrameCounter();

  Serial.printf("Display initialized: %dx%d, MADCTL=0x%02X, invert=on\n",
                display.width(), display.height(), kCo16Madctl);
}

void loop() {
 
  updateFrameCounter();
  delay(1000);
}
   
arduino ino file download: 

.zip   10-TFT-LCD-ST7789.zip (Size: 3.05 KB / Downloads: 166)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   10-TFT-LCD-ST7789.ino.merged.zip (Size: 211.33 KB / Downloads: 155)
before run code , need install these arduino library:
   
   

Print this item

  [arduino code examples for CO16]-09 digital INPUT trigger OUTPUT directly
Posted by: admin - 08-31-2026, 12:11 AM - Forum: CO16 - No Replies

Code:
/*
  Made by KinCony IoT: https://www.kincony.com

  Program functionality:
  This program uses ESP32-S3 to read inputs from PCA9555 I/O expander chip (I2C address 0x24)
  for channels 1-16, and control corresponding relays using PCF8575 I/O expander chip (I2C address 0x22)
  for controlling 16 relays (1-16). When input (DI) is triggered (LOW), corresponding relay (OUTPUT) is activated (LOW).
*/

#include <PCA95x5.h>
#include <Wire.h>
#include <PCF8575.h>

// Initialize the PCA9555 objects for reading inputs (channels 1-16)
PCA9555 input_ioex1;  // For channels 1-16 (I2C address 0x24)

// Set I2C address of the PCF8575 module for output relays
#define I2C_ADDRESS 0x22
PCF8575 pcf8575_R1(I2C_ADDRESS);

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

    // Initialize I2C bus: SDA=GPIO8, SCL=GPIO18, 100kHz
    Wire.begin(8, 18, 100000);

    // Initialize PCF8575 for outputs
    pcf8575_R1.begin();

    // Turn off all relays initially (set all pins HIGH - relay OFF)
    for (int i = 0; i < 16; i++) {
        pcf8575_R1.write(i, HIGH);
    }

    // Configure input PCA9555 (for inputs 1-16)
    input_ioex1.attach(Wire, 0x24);
    input_ioex1.polarity(PCA95x5::Polarity::ORIGINAL_ALL);
    input_ioex1.direction(PCA95x5::Direction::IN_ALL);

    delay(50);
}

void loop() {
    // Read input states from XL9535 (inputs 1-16)
    uint16_t inputs_1_16 = input_ioex1.read();
   
    // Control outputs based on inputs
    // When input is LOW, set corresponding output to LOW (activate relay)
    for (int channel = 0; channel < 16; channel++) {
        if (!(inputs_1_16 & (1 << channel))) {
            pcf8575_R1.write(channel, LOW);   // Input triggered, activate relay
        } else {
            pcf8575_R1.write(channel, HIGH);  // Input not triggered, deactivate relay
        }
    }
   
    delay(100);
}
arduino ino file download:

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

.zip   9-input-trigger-output.ino.merged.zip (Size: 197.75 KB / Downloads: 164)

Print this item

  [arduino code examples for CO16]-08 Ethernet W5500 chip work with TCP Server mode
Posted by: admin - 08-31-2026, 12:09 AM - Forum: CO16 - 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: GPIO1
* - MOSI: GPIO2
* - MISO: GPIO41
* - CS: GPIO42
* - RST: GPIO44
* - INT: GPIO43
*
* 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  42
#define W5500_RST_PIN 44
#define W5500_INT_PIN 43
#define W5500_CLK_PIN 1
#define W5500_MOSI_PIN 2
#define W5500_MISO_PIN 41

// 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: 155)
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: 162)

Print this item

  [arduino code examples for CO16]-07 how to DS3231 RTC clock
Posted by: admin - 08-31-2026, 12:08 AM - Forum: CO16 - 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
*    Set date and time command example: D2024-09-19T11:50:22
*    print current date and time command: current time
*
*
* 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.56 KB / Downloads: 153)
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: 191.08 KB / Downloads: 172)

Print this item

  [arduino code examples for CO16]-06 How to use SD Card
Posted by: admin - 08-31-2026, 12:06 AM - Forum: CO16 - 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: 156)
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.25 KB / Downloads: 162)

Print this item

  [arduino code examples for CO16]-05 Read PT100 temperature sensor
Posted by: admin - 08-31-2026, 12:04 AM - Forum: CO16 - No Replies

Code:
#include <Adafruit_MAX31865.h>

namespace {

// CO16 MAX31865 software-SPI pins.
constexpr int kPt100Sclk = 11;
constexpr int kPt100Mosi = 10;
constexpr int kPt100Miso = 12;
constexpr int kPt100Cs = 14;

// NX3L4051PW channel select pins. S3 is fixed LOW on CO16.
constexpr int kMuxS1 = 7;
constexpr int kMuxS2 = 21;
constexpr uint8_t kPt100ChannelCount = 4;
constexpr uint32_t kMuxSettlingTimeMs = 20;

constexpr float kRtdNominalOhms = 100.0F;
constexpr float kReferenceResistorOhms = 400.0F;

Adafruit_MAX31865 pt100(kPt100Cs, kPt100Mosi, kPt100Miso, kPt100Sclk);

void selectPt100Channel(uint8_t channel) {
  const uint8_t muxAddress = channel - 1;

  // S3 is fixed LOW, so S2/S1 select PT100 channels 1-4.
  digitalWrite(kMuxS1, muxAddress & 0x01);
  digitalWrite(kMuxS2, (muxAddress >> 1) & 0x01);
  delay(kMuxSettlingTimeMs);
}

void printFault(uint8_t fault) {
  Serial.printf(" fault=0x%02X", fault);
  if (fault & MAX31865_FAULT_HIGHTHRESH) {
    Serial.print(" RTD_HIGH_THRESHOLD");
  }
  if (fault & MAX31865_FAULT_LOWTHRESH) {
    Serial.print(" RTD_LOW_THRESHOLD");
  }
  if (fault & MAX31865_FAULT_REFINLOW) {
    Serial.print(" REFIN_HIGH");
  }
  if (fault & MAX31865_FAULT_REFINHIGH) {
    Serial.print(" REFIN_LOW_OR_FORCE_OPEN");
  }
  if (fault & MAX31865_FAULT_RTDINLOW) {
    Serial.print(" RTDIN_LOW_OR_FORCE_OPEN");
  }
  if (fault & MAX31865_FAULT_OVUV) {
    Serial.print(" OVER_UNDERVOLTAGE");
  }
}

}  // namespace

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

  pinMode(kMuxS1, OUTPUT);
  pinMode(kMuxS2, OUTPUT);
  selectPt100Channel(1);

  Serial.println();
  Serial.println("KinCony CO16 four-channel PT100 example");
  Serial.printf("MUX S3=LOW S2=%d S1=%d; SPI SCLK=%d MOSI=%d MISO=%d CS=%d\n",
                kMuxS2, kMuxS1, kPt100Sclk, kPt100Mosi, kPt100Miso,
                kPt100Cs);

  pt100.begin(MAX31865_3WIRE);
  pt100.enable50Hz(true);
}

void loop() {
  for (uint8_t channel = 1; channel <= kPt100ChannelCount; ++channel) {
    selectPt100Channel(channel);

    const uint16_t raw = pt100.readRTD();
    const float resistance =
        static_cast<float>(raw) * kReferenceResistorOhms / 32768.0F;
    const float temperature = pt100.calculateTemperature(
        raw, kRtdNominalOhms, kReferenceResistorOhms);
    const uint8_t fault = pt100.readFault(MAX31865_FAULT_NONE);

    Serial.printf("CH%u raw=%u resistance=%.3f ohm temperature=%.2f C",
                  channel, raw, resistance, temperature);
    if (fault != 0) {
      printFault(fault);
      pt100.clearFault();
    } else {
      Serial.print(" fault=0x00");
    }
    Serial.println();
  }

  Serial.println();
  delay(1000);
}
arduino ino file download: 

.zip   5-PT100.zip (Size: 1.11 KB / Downloads: 150)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   5-PT100.ino.merged.zip (Size: 198.5 KB / Downloads: 152)
before run code , need install max31865 arduino library
   
   

Print this item

  [arduino code examples for CO16]-04 RS485 communication test
Posted by: admin - 08-31-2026, 12:02 AM - Forum: CO16 - 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!");

  // 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: 760 bytes / Downloads: 151)
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: 190.1 KB / Downloads: 140)

Print this item