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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 10,167
» Latest member: okfuncoach
» Forum threads: 4,260
» Forum posts: 21,110

Full Statistics

Online Users
There are currently 762 online users.
» 0 Member(s) | 741 Guest(s)
Amazonbot, Applebot, Baidu, Bing, Bytespider, Crawl, Google, PetalBot, Semrush, bot

Latest Threads
Bricked KC868-A16
Forum: KC868-A series and Uair Smart Controller
Last Post: newdos
3 hours ago
» Replies: 4
» Views: 29
remember relay state
Forum: KC868-E16T
Last Post: greeryan
Today, 12:37 AM
» Replies: 6
» Views: 360
It looks like it's broken...
Forum: KinCony Server-Mini / Server-16 Raspberry Pi4 relay module
Last Post: admin
Yesterday, 08:36 AM
» Replies: 5
» Views: 96
Bidirectional reading
Forum: N10
Last Post: admin
10-05-2026, 11:35 PM
» Replies: 1
» Views: 26
Update to latest esphome
Forum: KC868-A16
Last Post: admin
10-05-2026, 12:05 PM
» Replies: 6
» Views: 152
KC868-A16 ethernet work w...
Forum: KC868-A16
Last Post: admin
10-04-2026, 11:43 PM
» Replies: 31
» Views: 26,355
B32M maximum voltage
Forum: DIY Project
Last Post: admin
10-04-2026, 11:52 AM
» Replies: 4
» Views: 569
m16v2 energy meter - cali...
Forum: KC868-M16 / M1 / MB / M30
Last Post: admin
10-02-2026, 11:50 AM
» Replies: 15
» Views: 2,501
oCBot: KC868-A6/A16 as a ...
Forum: DIY Project
Last Post: oCBot
10-01-2026, 01:32 PM
» Replies: 0
» Views: 305
N20 Energy RS485 Modbus P...
Forum: N20
Last Post: admin
10-01-2026, 12:43 PM
» Replies: 3
» Views: 1,020

  ESPHome modbus not functional
Posted by: Bergoglio - 09-06-2026, 05:56 PM - Forum: KC868-A8S - Replies (1)

Hello, we recently bought and set up the KC868-A8S with a Midea heat pump. ESPHome was used to set up the switches, binary sensors and modbus. The first two work as intended, while the modbus seemingly not being able to read or send requests properly.

Here is the chunk of the code that relates to and might influence the modbus and one of the sensors:

Code:
esphome:
  name: centralina-freddo
  friendly_name: Centralina freddo

esp32:
  variant: ESP32
  flash_size: 4MB
  board: esp32dev

logger:

api:
  encryption:
    key: [cencored for privacy]

ota:
  - platform: esphome
    password: [cencored for privacy]

i2c:
  - id: bus_a
    sda: GPIO4
    scl: GPIO5
    scan: true

ethernet:
  type: LAN8720
  clk:
    pin: GPIO17
    mode: CLK_OUT
  mdc_pin: GPIO23
  mdio_pin: GPIO18
  phy_addr: 0

uart:
  - id: uart_1
    tx_pin: GPIO33
    rx_pin: GPIO32
    baud_rate: 9600
    stop_bits: 1
    parity: NONE
    data_bits: 8
    rx_full_threshold: 8B
    debug:
      direction: BOTH

modbus:
  - id: modbus_1
    uart_id: uart_1
    role: client

modbus_controller:
  - id: modbus_controller_1
    address: 0x01
    modbus_id: modbus_1
    setup_priority: -10
    update_interval: 15s
   

sensor:
  - platform: modbus_controller
    name: "Temp. Esterna (PdC)"
    id: pdc_esterna_TP
    modbus_controller_id: modbus_controller_1
    address: 107
    register_type: holding
    unit_of_measurement: °C
    device_class: temperature
    state_class: measurement
    value_type: S_WORD
    accuracy_decimals: 1

Attempted fixes (that did not work):
  • phisically inverting the A and B connections
  • changing the modbus controller adress
  • changing the sensor adress to hexadecimal
  • changing the register type
  • changing the value type
  • adding accuracy decimals
  • changing th esp variant from inf to dev
  • changing the api to be more generic
  • inverting the tx and rx pins
  • changing the parity to even and odd
  • changing the amount of data bits
  • changing the amount of rx_full_threshold
  • removing the client role
  • removing the uart id
  • changing the update interval
  • decreasing the turnaround time to 50ms

At the moment, with this code, the log output repeats these lines:
Quote:[19:49:26.943][W][modbus:1214]: Clearing buffer of 21 bytes - timeout after partial response 1188899ms after last send
[19:49:26.954][D][uart_debug:113]: <<< 7E:66:66:00:66:F8:FE:18:E6:FE:E6:F8:FE:FE:E6:06:FE:E6:F8:FE:FE
Quote:[19:50:11.845][D][modbus:1118]: Frame already active for 1 with 2 requests pending, refused
[19:50:11.847][D][modbus_controller:204]: Poll refused by hub for range 0x68


We are unsure of what to do, and I am out of ideas on how to fix this.
All the GPIOs are correct. They have been checked.

Any help would be appreciated,
Thank you

Print this item

  Kc868ia
Posted by: Pingonet - 09-05-2026, 01:45 PM - Forum: KC868-AI - Replies (1)

Hello Can someone help me to get my New Board working in Esp-Home 

I keep getting errors on the board .


component:164]: Setup i2c took 762ms
[15:31:32][D][esp-idf:000]: E (889) i2c.master: I2C hardware timeout detected
[15:31:32][W][component:290]: pcf8574 set Warning flag: unspecified
[15:31:32][E][pcf8574:010]: PCF8574 not available under 0x24
[15:31:32][E][component:204]: pcf8574 was marked as failed
[15:31:32][E][component:297]: pcf8574 set Error flag: unspecified
[15:31:32][D][esp-idf:000]: E (912) i2c.master: I2C hardware timeout detected
[15:31:32][W][component:290]: pcf8574 set Warning flag: unspecified
[15:31:32][E][pcf8574:010]: PCF8574 not available under 0x25
[15:31:32][E][component:204]: pcf8574 was marked as failed
[15:31:32][E][component:297]: pcf8574 set Error flag: unspecified
[15:31:32][D][esp-idf:000]: E (945) i2c.master: I2C hardware timeout detected
[15:31:32][W][component:290]: pcf8574 set Warning flag: unspecified
[15:31:32][E][pcf8574:010]: PCF8574 not available under 0x21
[15:31:32][E][component:204]: pcf8574 was marked as failed
[15:31:32][E][component:297]: pcf8574 set Error flag: unspecified
[15:31:32][D][esp-idf:000]: E (978) i2c.master: I2C hardware timeout detected
[15:31:32][W][component:290]: pcf8574 set Warning flag: unspecified
[15:31:32][E][pcf8574:010]: PCF8574 not available under 0x22
[15:31:32][E][component:204]: pcf8574 was marked as failed
[15:31:32][E][component:297]: pcf8574 set Error flag: unspecified
[15:31:32][D][esp-idf:000]: E (1000) i2c.master: I2C hardware timeout detected
[15:31:32][W][component:290]: pcf8574 set Warning flag: unspecified
[15:31:32][E][pcf8574:010]: PCF8574 not available under 0x26
[15:31:32][E][component:204]: pcf8574 was marked as failed
[15:31:32][E][component:297]: pcf8574 set Error flag: unspecified
[15:31:32][D][esp-idf:000]: E (1034) i2c.master: I2C hardware timeout detected
[15:31:32][W][component:290]: pcf8574 set Warning flag: unspecified
[15:31:32][E][pcf8574:010]: PCF8574 not available under 0x23
[15:31:32][E][component:204]: pcf8574 was marked as failed
[15:31:32][E][component:297]: pcf8574 set Error flag: unspecified
[15:31:37][C][component:164]: Setup ethernet took 4328ms
[15:31:37][W][component:290]: api set Warning flag: waiting for client connection
[15:31:37][I][app:117]: setup() finished successfully!
compo

Print this item

  KC868-H32B
Posted by: kulibin - 09-05-2026, 10:18 AM - Forum: KC868-HxB series Smart Controller - Replies (5)

Hi . What is the maximum wire diameter I can connect for out terminal ?  32 relay х 10 A  [Image: vc6KWqVK]
   

Print this item

  Request for Type B Project
Posted by: lemanat - 09-03-2026, 08:47 AM - Forum: Apply for free sample product - No Replies

Application for Free Sample – KC868-A4 ESP32 Board
Project: KinCony-Powered DIY Smart Home & Smart Distribution System – Kenya
Dear KinCony Team,
My name is Nathan, and I am based in Kenya. I am currently working on my own residential house project, and one of my main objectives is to design and implement a comprehensive DIY smart home automation system for the house.
Over the past few months, I have researched different home automation solutions, including proprietary commercial systems as well as DIY platforms. During this research, I came across KinCony and became particularly interested in your products and approach to DIY home automation.
I have come to really like KinCony because it provides the flexibility and control that I am looking for. Rather than being completely dependent on a closed or proprietary ecosystem, I would like to build a system that I can understand, modify, expand and integrate with other technologies.
My Proposed Smart Home Project
My intention is to build the automation system progressively, starting with testing and learning the KinCony platform and eventually developing a comprehensive smart distribution and automation system for the house.
In particular, I am very interested in using KinCony's: 32CH Smart Distribution Box Solution with Home Assistant & Energy Monitoring as the main distribution and automation system for the house.
I believe this solution could provide an excellent foundation for centralizing the control of lighting, appliances, electrical circuits and energy monitoring while allowing Home Assistant to provide the overall smart-home interface and automation platform.
My vision is to have the electrical distribution system designed around smart control from the beginning rather than adding smart devices as an afterthought.
Areas I Intend to Automate
Depending on the results of my testing and the final design, I would like to automate and monitor areas such as:
  • Indoor and outdoor lighting
  • Security lighting
  • Garden and exterior lighting
  • Water pump control
  • Selected appliance circuits
  • Electric water heating
  • Gate and access-control systems
  • Motion and door sensors
  • Security-related automation
  • Energy monitoring
  • Automated schedules
  • Timers and scenes
  • Remote monitoring and control
  • Energy usage optimization
  • Integration with other smart-home sensors and devices
I would also like to explore how different parts of the house can work together through Home Assistant to create useful automation scenarios rather than simply providing remote ON/OFF switching.
For example, I would like to explore scenarios where lighting, motion sensors, security systems, energy monitoring and scheduled events interact automatically.
Why I Would Like to Start With the KC868-A4
I would like to request the KC868-A4 ESP32 board as a starting point for the project.
Before committing to a larger installation, I want to properly understand and test the KinCony ecosystem in a real-world environment.
I would use the KC868-A4 to experiment with relay control, sensors, automation logic, Home Assistant integration and other aspects of the KinCony platform.
The experience gained from this initial testing would then help me make informed decisions when designing the larger smart distribution system for my house.
I am particularly interested in understanding:
  • How reliably the KC868-A4 operates in a residential environment.
  • Its integration with Home Assistant.
  • How it can interact with sensors and other smart devices.
  • How the system behaves during network interruptions.
  • Local versus remote control capabilities.
  • Automation and scheduling possibilities.
  • Energy monitoring and management possibilities.
  • Expansion possibilities as the house automation grows.
  • The practical installation requirements for a Kenyan residential environment.
I believe there is significant potential for smart-home automation in Kenya.
Many people constructing new homes are increasingly interested in modern electrical systems, security, energy efficiency, automated gates, smart lighting and remote control.
However, many homeowners are still unfamiliar with DIY smart-home systems, while some commercial solutions can be expensive or lock the homeowner into a particular ecosystem.
This is one of the reasons I am particularly interested in KinCony.
The combination of ESP32-based hardware, flexible DIY control, Home Assistant and smart electrical distribution is very interesting to me because it potentially allows homeowners to have a much greater understanding and control of their own automation system.
My house will therefore serve as a practical test and learning environment.
In addition to automating my own house, I am also interested in exploring the possibility of introducing and marketing home automation solutions in Kenya.
As I learn more about KinCony products and gain practical experience with the installation, configuration and integration process, I would like to evaluate whether KinCony's solutions could be offered to other homeowners who are looking for affordable and flexible smart-home systems.
I believe the best way for me to do this responsibly is to first install and test the technology in my own house.
This would allow me to understand the system from an installer, developer and homeowner perspective before recommending it to other people.
What I Would Provide to the KinCony Community
If KinCony is able to provide me with a KC868-A4 sample, I would be happy to document the project and share my experience with the KinCony community.
I intend to document:
  1. My initial setup and configuration of the KC868-A4.
  2. Testing of the relay outputs and inputs.
  3. Integration with Home Assistant.
  4. Wiring and automation concepts.
  5. Practical applications within my house.
  6. Testing results and lessons learned.
  7. Integration ideas for the larger smart distribution system.
  8. Photos and videos of the project where appropriate.
  9. Tutorials or practical guides based on my experience.
  10. Feedback regarding the product's strengths, limitations and suitability for residential applications in Kenya.
My intention is to create useful information that can help other people understand what is possible with KinCony products.
My long-term goal is to develop a fully integrated DIY smart home where the electrical distribution, automation, security and energy monitoring systems work together.
The KinCony 32CH Smart Distribution Box Solution with Home Assistant & Energy Monitoring is currently one of the solutions I am most interested in evaluating as the main distribution and control platform for this project.
The KC868-A4 would give me an opportunity to start learning and testing the KinCony ecosystem before implementing the larger system.
If the testing is successful, I would be interested in expanding the project with additional KinCony hardware and eventually using the experience gained to help introduce smart-home automation solutions to other homeowners in Kenya.
I would therefore be very grateful if the KinCony team would consider my project for a free KC868-A4 ESP32 sample.
I am not looking at the sample simply as a free product. I see it as an opportunity to learn, test, build, document and demonstrate what can be achieved with KinCony technology in a real Kenyan home.
I believe this project could become a useful real-world demonstration of KinCony's DIY smart-home ecosystem and potentially provide valuable exposure to a growing market for home automation in Kenya.
Thank you for considering my application. I look forward to the opportunity to work with KinCony and share my experience with the community.
Nathan Noah

Print this item

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 (22)

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: 93)
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: 104)
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: 101)
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: 109)

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: 97)
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: 105)

Print this item