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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 8,413
» Latest member: apexwebstudios
» Forum threads: 3,663
» Forum posts: 18,972

Full Statistics

Online Users
There are currently 20 online users.
» 0 Member(s) | 7 Guest(s)
AhrefsBot, Amazonbot, Bytespider, Google, bot

Latest Threads
flash Kincony software to...
Forum: DIY Project
Last Post: admin
33 minutes ago
» Replies: 14
» Views: 78
KC868-A6 - how to connect...
Forum: KC868-A6
Last Post: admin
2 hours ago
» Replies: 10
» Views: 140
F8 physical on device swi...
Forum: F8
Last Post: admin
2 hours ago
» Replies: 3
» Views: 16
Feedback: Product line di...
Forum: Suggestions and feedback on KinCony's products
Last Post: mkai
4 hours ago
» Replies: 0
» Views: 5
flash kc868-a4
Forum: KC868-A series and Uair Smart Controller
Last Post: Sten
11 hours ago
» Replies: 14
» Views: 557
KC868 A8v3 RF not working...
Forum: KC868-A8v3
Last Post: admin
Yesterday, 10:46 AM
» Replies: 1
» Views: 9
N30 Energy entry not work...
Forum: N30
Last Post: admin
Yesterday, 01:30 AM
» Replies: 30
» Views: 581
KC868-A16 v1 with KCS v2....
Forum: "KCS" v2 firmware system
Last Post: admin
01-11-2026, 11:52 PM
» Replies: 7
» Views: 53
Separate +12V to Kincony,...
Forum: T128M
Last Post: admin
01-11-2026, 11:51 PM
» Replies: 1
» Views: 19
linux command line / bash...
Forum: TA
Last Post: almman
01-11-2026, 11:13 PM
» Replies: 2
» Views: 28

  [arduino code examples for B8]-03 Read ADS1115 analog input ports value
Posted by: admin - 06-23-2025, 04:40 AM - Forum: B8 - No Replies

Code:
/*
* This program reads voltage values from the ADS1115 analog-to-digital converter
* on all four channels (A0, A1, A2, A3) and prints the results through the serial port.
* The ADS1115 communicates via the I2C protocol. This version of the code includes
* the capability to specify custom SDA and SCL pins for I2C communication.
*
* Copyright: Made by KinCony IoT: https://www.kincony.com
*
*/

#include <Wire.h>                // Library for I2C communication
#include <DFRobot_ADS1115.h>     // Library for ADS1115 ADC module

// Define the I2C SDA and SCL pins for communication with ADS1115
#define SDA_PIN 8 
#define SCL_PIN 18 

// Initialize ADS1115 instance using the Wire library
DFRobot_ADS1115 ads(&Wire);

void setup(void)
{
    // Begin serial communication at a baud rate of 115200
    Serial.begin(115200);

    // Initialize the I2C bus using the defined SDA and SCL pins
    Wire.begin(SDA_PIN, SCL_PIN);

    // Set the I2C address for the ADS1115 (default: 0x49)
    ads.setAddr_ADS1115(ADS1115_IIC_ADDRESS0);   // Address is 0x49

    // Set the gain for the ADS1115 (2/3x gain allows for a maximum input voltage of 6.144V)
    ads.setGain(eGAIN_TWOTHIRDS);

    // Set the ADS1115 to operate in single-shot mode (each reading is a single conversion)
    ads.setMode(eMODE_SINGLE);

    // Set the sample rate to 128 samples per second (SPS)
    ads.setRate(eRATE_128);

    // Set the operational status mode to single-conversion start
    ads.setOSMode(eOSMODE_SINGLE);

    // Initialize the ADS1115 module
    ads.init();
}

void loop(void)
{
    // Check if the ADS1115 is properly connected and functioning
    if (ads.checkADS1115())
    {
        // Variables to store the voltage readings for each channel
        int16_t adc0, adc1, adc2, adc3;

        // Read the voltage from channel A0 and print the value
        adc0 = ads.readVoltage(0);
        Serial.print("A0:");
        Serial.print(adc0);
        Serial.print("mV,  ");    // Print the value in millivolts

        // Read the voltage from channel A1 and print the value
        adc1 = ads.readVoltage(1);
        Serial.print("A1:");
        Serial.print(adc1);
        Serial.print("mV,  ");    // Print the value in millivolts

        // Read the voltage from channel A2 and print the value
        adc2 = ads.readVoltage(2);
        Serial.print("A2:");
        Serial.print(adc2);
        Serial.print("mV,  ");    // Print the value in millivolts

        // Read the voltage from channel A3 and print the value
        adc3 = ads.readVoltage(3);
        Serial.print("A3:");
        Serial.print(adc3);
        Serial.println("mV");     // Print the value in millivolts and end the line
    }
    else
    {
        // If ADS1115 is not connected, print a message indicating disconnection
        Serial.println("ADS1115 Disconnected!");
    }

    // Wait for 1 second before the next loop iteration
    delay(1000);
}
arduino ino file download: 

.zip   3-ads1115_adc.zip (Size: 1.2 KB / Downloads: 263)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   3-ads1115_adc.ino.merged.zip (Size: 192.69 KB / Downloads: 300)

Print this item

  [arduino code examples for B8]-02 Read digital input ports state
Posted by: admin - 06-23-2025, 04:36 AM - Forum: B8 - No Replies

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

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

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

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

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

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

    pcf8575_IN1.begin(); // Initialize the PCF8575

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

void loop() {
    uint16_t state = 0;

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

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

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

.zip   2-digital-input.zip (Size: 837 bytes / Downloads: 277)
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: 192.29 KB / Downloads: 313)

Print this item

  [arduino code examples for B8]-01 Turn ON/OFF OUTPUT
Posted by: admin - 06-23-2025, 04:31 AM - Forum: B8 - No Replies

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

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

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

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

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

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

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

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

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

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

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

.zip   1-output.ino.merged.zip (Size: 192.06 KB / Downloads: 278)

Print this item

  B8 ESPHome yaml for home assistant with tuya
Posted by: admin - 06-23-2025, 04:28 AM - Forum: B8 - No Replies

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  - platform: gpio
    name: "b8-input02"
    id: "b8_input02"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 1
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: b8-input2-tuya
    dp_id: 112
    bind_binary_sensor_id: b8_input02
    internal: true

  - platform: gpio
    name: "b8-input03"
    id: "b8_input03"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 2
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: b8-input3-tuya
    dp_id: 113
    bind_binary_sensor_id: b8_input03
    internal: true

  - platform: gpio
    name: "b8-input04"
    id: "b8_input04"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 3
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: b8-input4-tuya
    dp_id: 114
    bind_binary_sensor_id: b8_input04
    internal: true

  - platform: gpio
    name: "b8-input05"
    id: "b8_input05"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 4
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: b8-input5-tuya
    dp_id: 115
    bind_binary_sensor_id: b8_input05
    internal: true

  - platform: gpio
    name: "b8-input06"
    id: "b8_input06"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 5
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: b8-input6-tuya
    dp_id: 116
    bind_binary_sensor_id: b8_input06
    internal: true

  - platform: gpio
    name: "b8-input07"
    id: "b8_input07"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 6
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: b8-input7-tuya
    dp_id: 117
    bind_binary_sensor_id: b8_input07
    internal: true

  - platform: gpio
    name: "b8-input08"
    id: "b8_input08"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 7
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: b8-input8-tuya
    dp_id: 118
    bind_binary_sensor_id: b8_input08
    internal: true

##pull-up resistance on PCB
  - platform: gpio
    name: "b8-W1-io47"
    pin:
      number: 47
      inverted: true

  - platform: gpio
    name: "b8-W1-io48"
    pin:
      number: 48
      inverted: true

  - platform: gpio
    name: "b8-W1-io7"
    pin:
      number: 7
      inverted: true

  - platform: gpio
    name: "b8-W1-io40"
    pin:
      number: 40
      inverted: true
## without resistance on PCB
  - platform: gpio
    name: "b8-13"
    pin:
      number: 13
      inverted:  false
  - platform: gpio
    name: "b8-14"
    pin:
      number: 14
      inverted:  false
  - platform: gpio
    name: "b8-21"
    pin:
      number: 21
      inverted:  false
  - platform: gpio
    name: "b8-0"
    pin:
      number: 0
      inverted:  false

ads1115:
  - address: 0x48
sensor:
  - platform: ads1115
    multiplexer: 'A0_GND'
    gain: 6.144
    resolution: 16_BITS
    name: "ADS1115 Channel A0-GND"
    update_interval: 5s
  - platform: ads1115
    multiplexer: 'A1_GND'
    gain: 6.144
    name: "ADS1115 Channel A1-GND"
    update_interval: 5s
  - platform: ads1115
    multiplexer: 'A2_GND'
    gain: 6.144
    name: "ADS1115 Channel A2-GND"
    update_interval: 5s
  - platform: ads1115
    multiplexer: 'A3_GND'
    gain: 6.144
    name: "ADS1115 Channel A3-GND"
    update_interval: 5s

web_server:
  port: 80

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

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

.txt   B8-HA.txt (Size: 8.35 KB / Downloads: 173)

Print this item

  B8 ESP32-S3 IO pins define
Posted by: admin - 06-23-2025, 04:19 AM - Forum: B8 - No Replies

IIC Bus:

SDA:GPIO8
SCL:GPIO18

PCF8575: i2c address:0x22

PCF8575->P0 (digital input-1)
PCF8575->P1 (digital input-2)
PCF8575->P2 (digital input-3)
PCF8575->P3 (digital input-4)
PCF8575->P4 (digital input-5)
PCF8575->P5 (digital input-6)
PCF8575->P6 (digital input-7)
PCF8575->P7 (digital input-8)

PCF8575->P8 (relay1)
PCF8575->P9 (relay2)
PCF8575->P10 (relay3)
PCF8575->P11 (relay4)
PCF8575->P12 (relay5)
PCF8575->P13 (relay6)
PCF8575->P14 (relay7)
PCF8575->P15 (relay8)

24C02 EPROM i2c address: 0x50
DS3231 RTC i2c address: 0x68
SSD1306 display: i2c address:0x3c
ADS1115 (4CH ADC): i2c address:0x48

Analog input (A1: DC 0-5v)
Analog input (A2: DC 0-5v)
Analog input (A3: DC 4-20mA)
Analog input (A4: DC 4-20mA)


-----------------
1-wire GPIOs (with pull-up resistance on PCB):
1-wire-1:GPIO47
1-wire-2:GPIO48
1-wire-3:GPIO7
1-wire-4:GPIO40
-----------------
free GPIOs (without pull-up resistance on PCB):
GPIO13
GPIO14
GPIO21
-----------------

Ethernet (W5500) I/O define:

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

interrupt_pin: GPIO43
reset_pin: GPIO44

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

Tuya module:
RXD:GPIO17
TXD:GPIO16

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

Print this item

  IFTTT DI OnDelay
Posted by: job-systems - 06-22-2025, 01:41 AM - Forum: "KCS" v2 firmware system - Replies (2)

Hi, hope you are all fine. 

Is it possible to have a Digital In (DI) to be true or ON for a fix number of seconds on the IF section before going to the THEN section and enabling a Digital Out (DO). 

Example: I have laser barrier that flying insects pass by and activate it, I would like to not have false positives, and for example, ensure the DI is ON for 3 seconds fixed before activating the DO. 

Thank you.



Attached Files Thumbnail(s)
   
Print this item

  KC868-A2 watchdog
Posted by: apps4check - 06-21-2025, 05:11 PM - Forum: KC868-A2 - Replies (1)

Hello. Does KC868-A2 (with "KCS" firmware) have a hardware or software watchdog?

Print this item

  KinCony B8M ESP32-S3 Smart Controller released
Posted by: admin - 06-21-2025, 04:07 AM - Forum: News - No Replies

KinCony B8M ESP32 smart controller based on ESP32-S3-WROOM-1U (N16R8) wifi chip. Support 8 channel MOSFET output, 4 channel 1-wire GPIOs, 3 free GPIOs, 4 channel ADS1115 16bit analog input ports. One SD card using SPI bus. B8M include DS3231 high precision RTC clock chip. LCD display will show wifi and ethernet IP address and Tuya connection state. B8M have I2C bus extender and RS485 port. 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. B8M use KCS v3 firmware, it support home assistant auto discovery function by MQTT, so without write any config code (zero code) for home assistant. B8M support Apple HomeKit, easy to use directly. Support save state LOG to SD Card. It use by local RTC clock, use timer work without internet. B8M support to use KinCony cloud server service, so that you can remote control and monitor your device by internet using mobile phone or computer web browser. note: (buy from KinCony Official Shop have KinCony cloud server 2 years free)
[Image: B8M_1.jpg]
Model No. KinCony B8M
Description: KinCony 8 Channel ESP32-S3 Smart Controller – B8M
Power supply: 12-24V DC
Processor: ESP32-S3-WROOM-1U (N16R8)
Size:
interfaces: Ethernet(RJ45)-LAN 100Mbps IPv4/IPv6,WiFi,RS485,Bluetooth,USB-C,LCD,I2C,Tuya Module
RTC: DS3231 high precision chip (battery socket on PCB)
SD Card: SPI bus
Installation method: DIN RAIL
LCD: SSD1306 I2C display
Outputs:
8CH MOSFET Outputs, every channel use MAX 10A driver IC
Inputs:
ADS1115 16bit ADC: 2CH analog input DC0-5V (A1,A2) 2CH analog input 4-20mA (A3,A4)
8CH dry contact inputs (optocoupler isolation, long distance circuit for MAX 500 meters cable)
3 buttons: 1:ESP32 Reset 2:ESP32 Download 3:Tuya config
1-Wire GPIO: 4CH (with pull-up resistance on PCB)
free GPIO: 3CH (without pull-up resistance on PCB, connect with ESP32 pin directly)
[Image: B8M_6.jpg]

Print this item

  [arduino code examples for B8M]-11 digital INPUT trigger OUTPUT directly
Posted by: admin - 06-21-2025, 04:03 AM - Forum: B8M - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* This program reads 16 input states from a PCF8575 I/O expander and
* controls a corresponding 16-channel relay module. When an input pin
* is LOW, the corresponding relay is turned ON (LOW means ON for the relay).
* When the input pin is HIGH, the corresponding relay is turned OFF.
*
* Pin Definitions:
* - SDA: GPIO 38
* - SCL: GPIO 39
* - Input I2C Address: 0x24
* - Relay I2C Address: 0x25
*/

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

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

// I2C addresses

#define RELAY_I2C_ADDRESS 0x22   // I2C address for the relay PCF8575 module


PCF8575 pcf8575_RL(RELAY_I2C_ADDRESS);    // Create an object for the relay PCF8575

void setup() {
  // Initialize I2C communication
  Wire.begin(SDA, SCL);
 
  // Initialize serial communication
  Serial.begin(115200);
 
  // Initialize input and relay modules

  pcf8575_RL.begin();
 
  // Turn off all relays at the start
  for (int i = 0; i < 8; i++) {
    pcf8575_RL.write(i, LOW);  // Assuming relays are LOW when OFF, setting all relays to OFF initially
  }
 
  Serial.println("System started: Input state controlling 8 relays");
}

void loop() {
  uint16_t inputState = 0;

  // Read the state of 16 inputs
  for (int i = 8; i < 16; i++) {
    if (pcf8575_RL.read(i)) {
      inputState |= (1 << i);  // If input is HIGH, set the corresponding bit
    } else {
      inputState &= ~(1 << i); // Otherwise, clear the corresponding bit
    }
  }
 
  // Control the relays based on the input state
  for (int i = 0; i < 8; i++) {
    if (inputState & (1 << i+8)) {
      pcf8575_RL.write(i, HIGH);  // If input is HIGH, turn the relay OFF
    } else {
      pcf8575_RL.write(i, LOW);   // If input is LOW, turn the relay ON
    }
  }

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

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

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

Print this item

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

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

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

// Initialize the display using the software I2C method (SCL = IO18, SDA = IO8)
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0,  18, 8, U8X8_PIN_NONE);  // Screen rotation: U8G2_R0

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

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

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

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

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

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

Print this item