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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,391
» Latest member: proelec
» Forum threads: 2,850
» Forum posts: 15,084

Full Statistics

Online Users
There are currently 232 online users.
» 1 Member(s) | 219 Guest(s)
Amazonbot, Applebot, Crawl, Go-http-client, Google, PetalBot, Yandex, bot, wkdrlfska

Latest Threads
Additional GPIO
Forum: KC868-A4S
Last Post: Amaral989
3 hours ago
» Replies: 0
» Views: 2
Setup K868-a32 and k868-a...
Forum: DIY Project
Last Post: admin
7 hours ago
» Replies: 7
» Views: 43
KC868-A16 with IDE 2.3.4
Forum: KC868-A16
Last Post: admin
7 hours ago
» Replies: 4
» Views: 45
Display
Forum: KC868-A series and Uair Smart Controller
Last Post: admin
7 hours ago
» Replies: 1
» Views: 5
RTC stop working with bu...
Forum: KC868-A6
Last Post: admin
Yesterday, 08:31 AM
» Replies: 15
» Views: 5,051
Hibrid project
Forum: KC868-Server Raspberry Pi4 local server
Last Post: Psyos
Yesterday, 12:32 AM
» Replies: 2
» Views: 13
Double press/ Long press ...
Forum: KC868-AI
Last Post: admin
03-09-2025, 11:34 PM
» Replies: 7
» Views: 428
Trigger Outputs
Forum: KC868-HxB series Smart Controller
Last Post: admin
03-09-2025, 11:29 PM
» Replies: 5
» Views: 46
Using 12v on Digital Inpu...
Forum: KC868-A16
Last Post: admin
03-09-2025, 01:31 PM
» Replies: 17
» Views: 397
Input problem 868 A6
Forum: KC868-A series and Uair Smart Controller
Last Post: admin
03-09-2025, 01:29 PM
» Replies: 3
» Views: 18

  AG PRO / KCS Firmware / IR Learning / Node Red
Posted by: chmabu - 09-16-2024, 07:27 AM - Forum: KC868-AG / AG Pro / AG8 - No Replies

Hi,

running the AG PRO with the latest firmware.

1. IR Learning - KCS
If I put the firmware to learning via KCS Web frontend, the Samsung TV IR signals are not recorded. Even no beep is played.
If I use Tuya the IR is recorded.

2. IR Learining - Node Red
In addition I found a video on youtube where the Inject node was used to put IR in learning.
Now I checked the HTTP and the MQTT protocoll. There is no explanation on these protocols how to do this.

3. MQTT Problems
I enabled the MQTT to a remote MQTT server.
Using the MQTT-Explorer I can see the Topic with STATE created. So, apparently AG and MQTT server connection is ok.

BUT: STATE is always empty! Also when I send  {"get _datas" : {"value": true}} -  nothing is responded.

Print this item

  KinCony Video Contest: Share Your Project, Earn Rewards!
Posted by: admin - 09-16-2024, 02:00 AM - Forum: News - Replies (1)

KinCony Video Submission Campaign: Showcase Your Project and Get Rewarded!
Dear Valued KinCony Customers,
We’re excited to launch a new campaign where you can share how you’re using KinCony products in your projects and help inspire other users! Simply create a short, real-life video showcasing KinCony products in action, and in return, you’ll receive rewards and have your video featured on our official KinCony YouTube channel.
Video Submission Requirements:

  1. Record in vertical format using your smartphone.
  2. The video should be between 15 seconds and 1 minute long.
  3. Show the real wiring connections of the product.
  4. Highlight the actual control features in action.
  5. Capture the real environment where the product is used, such as home settings, outdoor farms, or other real-world IoT project environments.
How to Participate:
  1. Submit your video in MP4 format along with your KinCony official store account email address and username to kincony.iot@gmail.com, or upload it to Google Drive and email us the download link.
  2. We will review your submission within 2 business days and, if approved, upload it to our YouTube channel to share your project with the community.
Get Rewarded: As a token of appreciation, we will provide you with a discount coupon for your next purchase on the KinCony website. Coupon values range from 5 USD to 10 USD, depending on the quality of the video.
We believe that your video can help more users understand and utilize KinCony products in their own projects. We look forward to seeing your submissions and sharing your success with the KinCony community!

Print this item

  a16 as basis for a security system
Posted by: lcrisp - 09-16-2024, 12:50 AM - Forum: KC868-A16 - Replies (16)

I was planning to use my A16 to form a security system, and while door sensors are easy enough, I'm just a touched confused over how to connect alarms, buzzers, and a motion detector...

A four-wire motion detector needs two of it's wires to be connected to a 12v power supply (I think?) and it's two alarm wires can be connected directly to one of the dry digital inputs.

I believe that I'll then need to connect the siren and alarm to the mosfet outputs via two relays, which will then also have to be connected to their own power supplies?

Am I correct in this assumption? I purchased three 12v power supplies with the board, but I'm now worried that I'll need to purchase another one just to hook everything up! Am I correct in assuming that none of them can be powered via the board's 12v power supply? Can any of them be connected to a 12v power supply in sequence. *Especially valid because an alarm shouldn't ever be sounding (drawing power from a supply) at the same time as a buzzer.

And thus far I've connected it to Home Assistant via Esphome, but because my wireless networks have been hacked before I'd rather limit the A16's exposure to potential hacking attempts. Is there any other way to connect the A16 to Home Assistant so that it doesn't need to be constantly connected via ethernet?

Print this item

  Free sample request
Posted by: Tran Song HUng - 09-15-2024, 03:59 PM - Forum: Apply for free sample product - No Replies

Dear KINCONY Team

I already know some microprocessor like as PIC, Atmega and now. I want to learn ESP32.
After learning hardware. I know KINCONY have support Apply for free sample.
I hope i can be lucky enough to get it.

I am waiting your feedback.

Thank you so much.  Heart

Print this item

  H32L - faulty network card
Posted by: athxp - 09-15-2024, 08:19 AM - Forum: KC868-HxB series Smart Controller - Replies (5)

hi, this morning I found H32L disconnected. the network card is turned off and has no green LEDs on. ESP32 tuya module also fails to connect. I tried changing the cable but nothing.
from the input keys the plc works correctly. I attach a screenshot, where you can see that it is not online. what could have happened?
Thank you



Attached Files Thumbnail(s)
   
Print this item

  [ESP-IDF code examples for A32 Pro]-02 Read digital input ports state
Posted by: admin - 09-14-2024, 12:47 AM - Forum: KC868-A32/A32 Pro - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* This program reads inputs from two XL9535 I/O expander chips (I2C addresses 0x24 and 0x25)
* and one PCF8574 I/O expander (I2C address 0x23) via I2C using an ESP32-S3.
* The state of all inputs is printed in binary format to the serial monitor every second.
*
* - The XL9535 chips read inputs from channels 1-32.
* - The PCF8574 chip reads inputs from channels 33-40.
*
* I2C is initialized on GPIO 11 (SDA) and GPIO 10 (SCL) with a frequency of 40kHz.
*/

#include <stdio.h>
#include "driver/i2c.h"
#include "esp_log.h"

// I2C communication settings
#define I2C_MASTER_SCL_IO           10    // GPIO number for I2C clock line (SCL)
#define I2C_MASTER_SDA_IO           11    // GPIO number for I2C data line (SDA)
#define I2C_MASTER_FREQ_HZ          40000  // I2C frequency set to 40kHz
#define I2C_MASTER_PORT             I2C_NUM_0  // I2C port number used in this program

// I2C addresses for XL9535 chips and PCF8574
#define XL9535_ADDR_1               0x24  // Address for XL9535 (channels 1-16)
#define XL9535_ADDR_2               0x25  // Address for XL9535 (channels 17-32)
#define PCF8574_ADDR                0x23  // Address for PCF8574 (channels 33-40)

// XL9535 registers for input ports
#define XL9535_INPUT_PORT_0         0x00  // Input register for port 0 (channels 1-8)
#define XL9535_INPUT_PORT_1         0x01  // Input register for port 1 (channels 9-16)

// Function prototypes
esp_err_t i2c_master_init();
esp_err_t xl9535_read_inputs(uint8_t device_addr, uint8_t *data);
esp_err_t pcf8574_read_inputs(uint8_t *data);
void read_and_print_inputs();

void app_main() {
    // Initialize I2C master
    ESP_ERROR_CHECK(i2c_master_init());

    // Main loop to read and print input states every second
    while (1) {
        read_and_print_inputs();
        vTaskDelay(1000 / portTICK_PERIOD_MS);  // Wait for 1 second
    }
}

// Initialize I2C master interface
esp_err_t i2c_master_init() {
    i2c_config_t conf = {
        .mode = I2C_MODE_MASTER,  // Set I2C mode to master
        .sda_io_num = I2C_MASTER_SDA_IO,  // SDA GPIO pin
        .scl_io_num = I2C_MASTER_SCL_IO,  // SCL GPIO pin
        .sda_pullup_en = GPIO_PULLUP_ENABLE,  // Enable internal pull-up for SDA line
        .scl_pullup_en = GPIO_PULLUP_ENABLE,  // Enable internal pull-up for SCL line
        .master.clk_speed = I2C_MASTER_FREQ_HZ,  // Set I2C clock frequency to 40kHz
    };
    i2c_param_config(I2C_MASTER_PORT, &conf);
    return i2c_driver_install(I2C_MASTER_PORT, conf.mode, 0, 0, 0);
}

// Read inputs from XL9535 I/O expander
esp_err_t xl9535_read_inputs(uint8_t device_addr, uint8_t *data) {
    i2c_cmd_handle_t cmd = i2c_cmd_link_create();
    i2c_master_start(cmd);
    i2c_master_write_byte(cmd, (device_addr << 1) | I2C_MASTER_WRITE, true);
    i2c_master_write_byte(cmd, XL9535_INPUT_PORT_0, true);
    i2c_master_start(cmd);
    i2c_master_write_byte(cmd, (device_addr << 1) | I2C_MASTER_READ, true);
    i2c_master_read_byte(cmd, &data[0], I2C_MASTER_ACK);  // Read port 0 (channels 1-8 or 17-24)
    i2c_master_read_byte(cmd, &data[1], I2C_MASTER_NACK); // Read port 1 (channels 9-16 or 25-32)
    i2c_master_stop(cmd);
    esp_err_t ret = i2c_master_cmd_begin(I2C_MASTER_PORT, cmd, 1000 / portTICK_PERIOD_MS);
    i2c_cmd_link_delete(cmd);
    return ret;
}

// Read inputs from PCF8574 I/O expander
esp_err_t pcf8574_read_inputs(uint8_t *data) {
    i2c_cmd_handle_t cmd = i2c_cmd_link_create();
    i2c_master_start(cmd);
    i2c_master_write_byte(cmd, (PCF8574_ADDR << 1) | I2C_MASTER_READ, true);
    i2c_master_read_byte(cmd, data, I2C_MASTER_NACK);
    i2c_master_stop(cmd);
    esp_err_t ret = i2c_master_cmd_begin(I2C_MASTER_PORT, cmd, 1000 / portTICK_PERIOD_MS);
    i2c_cmd_link_delete(cmd);
    return ret;
}

// Function to read and print the state of inputs from XL9535 and PCF8574 chips
void read_and_print_inputs() {
    uint8_t xl9535_data_1[2];  // Data buffer for XL9535 (channels 1-16)
    uint8_t xl9535_data_2[2];  // Data buffer for XL9535 (channels 17-32)
    uint8_t pcf8574_data;      // Data buffer for PCF8574 (channels 33-40)

    // Read inputs from the first XL9535 (channels 1-16)
    if (xl9535_read_inputs(XL9535_ADDR_1, xl9535_data_1) == ESP_OK) {
        printf("1-16 input states: %02X%02X\n", xl9535_data_1[1], xl9535_data_1[0]);  // Print in binary
    } else {
        printf("Error reading from XL9535 (channels 1-16)\n");
    }

    // Read inputs from the second XL9535 (channels 17-32)
    if (xl9535_read_inputs(XL9535_ADDR_2, xl9535_data_2) == ESP_OK) {
        printf("17-32 input states: %02X%02X\n", xl9535_data_2[1], xl9535_data_2[0]);  // Print in binary
    } else {
        printf("Error reading from XL9535 (channels 17-32)\n");
    }

    // Read inputs from the PCF8574 (channels 33-40)
    if (pcf8574_read_inputs(&pcf8574_data) == ESP_OK) {
        printf("33-40 input states: %02X\n", pcf8574_data);  // Print in binary
    } else {
        printf("Error reading from PCF8574 (channels 33-40)\n");
    }
}
   

Print this item

  [ESP-IDF code examples for A32 Pro]-01 Turn ON/OFF relay
Posted by: admin - 09-14-2024, 12:38 AM - Forum: KC868-A32/A32 Pro - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* This program controls two PCA9555 I/O expander chips via I2C to control a total of 32 relays.
* The first PCA9555 (at I2C address 0x21) controls relays 1-16, while the second PCA9555 (at I2C address 0x22)
* controls relays 17-32. The relays are turned ON (LOW) and OFF (HIGH) in sequence.
*
* Each PCA9555 chip has two ports: port 0 controls relays 1-8 (or 17-24), and port 1 controls relays 9-16 (or 25-32).
*
* The program will initialize both chips and turn all relays OFF initially, then turn each relay ON one by one.
* After a delay, all relays are turned OFF again.
*/

#include <stdio.h>
#include <string.h>
#include "driver/i2c.h"
#include "esp_log.h"

// I2C communication settings
#define I2C_MASTER_SCL_IO           10    // GPIO number for I2C clock line (SCL)
#define I2C_MASTER_SDA_IO           11    // GPIO number for I2C data line (SDA)
#define I2C_MASTER_FREQ_HZ          100000 // Frequency for I2C clock (100kHz)
#define I2C_MASTER_PORT             I2C_NUM_0 // I2C port number used in this program

// I2C write/read settings
#define WRITE_BIT                   I2C_MASTER_WRITE // I2C write mode
#define READ_BIT                    I2C_MASTER_READ  // I2C read mode
#define ACK_CHECK_EN                0x1     // Enable I2C ACK checking
#define ACK_CHECK_DIS               0x0     // Disable I2C ACK checking
#define ACK_VAL                     0x0     // I2C ACK value
#define NACK_VAL                    0x1     // I2C NACK value

// PCA9555 I2C addresses (chip 1: controls relays 1-16, chip 2: controls relays 17-32)
#define PCA9555_ADDR_1              0x21    // I2C address for the first PCA9555 (1-16 relays)
#define PCA9555_ADDR_2              0x22    // I2C address for the second PCA9555 (17-32 relays)

// PCA9555 Register addresses
#define PCA9555_REG_OUTPUT_0        0x02    // Output register for port 0 (controls relays 1-8 or 17-24)
#define PCA9555_REG_OUTPUT_1        0x03    // Output register for port 1 (controls relays 9-16 or 25-32)

// Function declarations (prototypes)
esp_err_t i2c_master_init(); // Initializes the I2C master
esp_err_t pca9555_write_byte(uint8_t device_addr, uint8_t reg_addr, uint8_t data); // Writes a byte to a PCA9555 register
void control_relays(); // Main function to control the relays

// Main application entry point
void app_main() {
    // Initialize I2C master interface
    ESP_ERROR_CHECK(i2c_master_init());

    // Set both PCA9555 chips' all pins as output and turn all relays OFF initially (0xFF = all HIGH = OFF)
    ESP_ERROR_CHECK(pca9555_write_byte(PCA9555_ADDR_1, PCA9555_REG_OUTPUT_0, 0xFF)); // Turn off relays 1-8
    ESP_ERROR_CHECK(pca9555_write_byte(PCA9555_ADDR_1, PCA9555_REG_OUTPUT_1, 0xFF)); // Turn off relays 9-16
    ESP_ERROR_CHECK(pca9555_write_byte(PCA9555_ADDR_2, PCA9555_REG_OUTPUT_0, 0xFF)); // Turn off relays 17-24
    ESP_ERROR_CHECK(pca9555_write_byte(PCA9555_ADDR_2, PCA9555_REG_OUTPUT_1, 0xFF)); // Turn off relays 25-32

    // Start controlling relays (turn on one by one, then off)
    control_relays();
}

// Function to initialize the I2C master
esp_err_t i2c_master_init() {
    // I2C configuration structure
    i2c_config_t conf = {
        .mode = I2C_MODE_MASTER,       // Set the I2C mode to master
        .sda_io_num = I2C_MASTER_SDA_IO, // Set the SDA GPIO pin
        .scl_io_num = I2C_MASTER_SCL_IO, // Set the SCL GPIO pin
        .sda_pullup_en = GPIO_PULLUP_ENABLE, // Enable internal pull-up for SDA line
        .scl_pullup_en = GPIO_PULLUP_ENABLE, // Enable internal pull-up for SCL line
        .master.clk_speed = I2C_MASTER_FREQ_HZ, // Set I2C clock frequency to 100kHz
    };
    // Apply I2C configuration to I2C master port
    i2c_param_config(I2C_MASTER_PORT, &conf);
    // Install the I2C driver for the master port
    return i2c_driver_install(I2C_MASTER_PORT, conf.mode, 0, 0, 0);
}

// Function to write a byte of data to a specified register of the PCA9555
// device_addr: I2C address of the PCA9555 chip (0x21 or 0x22)
// reg_addr: Register address to write to (e.g., output register 0 or 1)
// data: The byte of data to write (e.g., relay states: HIGH = OFF, LOW = ON)
esp_err_t pca9555_write_byte(uint8_t device_addr, uint8_t reg_addr, uint8_t data) {
    // Create a new I2C command link
    i2c_cmd_handle_t cmd = i2c_cmd_link_create();
    // Start the I2C communication
    i2c_master_start(cmd);
    // Send the PCA9555's I2C address with the write bit
    i2c_master_write_byte(cmd, (device_addr << 1) | WRITE_BIT, ACK_CHECK_EN);
    // Send the register address where the data should be written
    i2c_master_write_byte(cmd, reg_addr, ACK_CHECK_EN);
    // Send the actual data to be written to the register
    i2c_master_write_byte(cmd, data, ACK_CHECK_EN);
    // Stop the I2C communication
    i2c_master_stop(cmd);
    // Execute the I2C command and return the result
    esp_err_t ret = i2c_master_cmd_begin(I2C_MASTER_PORT, cmd, 1000 / portTICK_PERIOD_MS);
    // Delete the I2C command link after use
    i2c_cmd_link_delete(cmd);
    return ret;
}

// Function to control the relays on both PCA9555 chips
void control_relays() {
    uint8_t relay_state_0 = 0xFE; // Relay 1 ON (LOW), others OFF (HIGH) for port 0
    uint8_t relay_state_1 = 0xFF; // All OFF (HIGH) for port 1 initially

    // Control the first PCA9555 chip (relays 1-16)
    // Port 0 controls relays 1-8
    for (int i = 0; i < 8; ++i) {
        ESP_LOGI("Relay Control", "Setting relay %d ON (chip 1, port 0)", i + 1);
        // Write relay states to port 0 of the first PCA9555 (1-8 relays)
        pca9555_write_byte(PCA9555_ADDR_1, PCA9555_REG_OUTPUT_0, relay_state_0);
        relay_state_0 = (relay_state_0 << 1) | 0x01; // Shift to the next relay
        vTaskDelay(100 / portTICK_PERIOD_MS); // Delay between relay actions
    }

    relay_state_0 = 0xFE; // Reset state for port 0, relay 9 ON

    // Port 1 controls relays 9-16
    for (int i = 0; i < 8; ++i) {
        ESP_LOGI("Relay Control", "Setting relay %d ON (chip 1, port 1)", i + 9);
        // Write relay states to port 1 of the first PCA9555 (9-16 relays)
        pca9555_write_byte(PCA9555_ADDR_1, PCA9555_REG_OUTPUT_1, relay_state_0);
        relay_state_0 = (relay_state_0 << 1) | 0x01; // Shift to the next relay
        vTaskDelay(100 / portTICK_PERIOD_MS); // Delay between relay actions
    }

    relay_state_0 = 0xFE; // Relay 17 ON (LOW), others OFF (HIGH) for port 0

    // Control the second PCA9555 chip (relays 17-32)
    // Port 0 controls relays 17-24
    for (int i = 0; i < 8; ++i) {
        ESP_LOGI("Relay Control", "Setting relay %d ON (chip 2, port 0)", i + 17);
        // Write relay states to port 0 of the second PCA9555 (17-24 relays)
        pca9555_write_byte(PCA9555_ADDR_2, PCA9555_REG_OUTPUT_0, relay_state_0);
        relay_state_0 = (relay_state_0 << 1) | 0x01; // Shift to the next relay
        vTaskDelay(100 / portTICK_PERIOD_MS); // Delay between relay actions
    }

    relay_state_0 = 0xFE; // Reset state for port 1, relay 25 ON

    // Port 1 controls relays 25-32
    for (int i = 0; i < 8; ++i) {
        ESP_LOGI("Relay Control", "Setting relay %d ON (chip 2, port 1)", i + 25);
        // Write relay states to port 1 of the second PCA9555 (25-32 relays)
        pca9555_write_byte(PCA9555_ADDR_2, PCA9555_REG_OUTPUT_1, relay_state_0);
        relay_state_0 = (relay_state_0 << 1) | 0x01; // Shift to the next relay
        vTaskDelay(100 / portTICK_PERIOD_MS); // Delay between relay actions
    }

    // After a short delay, turn all relays OFF
    vTaskDelay(1000 / portTICK_PERIOD_MS);
    // Set all relays on both chips to OFF (HIGH)
    pca9555_write_byte(PCA9555_ADDR_1, PCA9555_REG_OUTPUT_0, 0xFF); // Turn off relays 1-8
    pca9555_write_byte(PCA9555_ADDR_1, PCA9555_REG_OUTPUT_1, 0xFF); // Turn off relays 9-16
    pca9555_write_byte(PCA9555_ADDR_2, PCA9555_REG_OUTPUT_0, 0xFF); // Turn off relays 17-24
    pca9555_write_byte(PCA9555_ADDR_2, PCA9555_REG_OUTPUT_1, 0xFF); // Turn off relays 25-32
}
   

Print this item

  [arduino code examples for A32 Pro]-11 How to use digital input port trigger relay
Posted by: admin - 09-14-2024, 12:12 AM - Forum: KC868-A32/A32 Pro - Replies (2)

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

  Program functionality:
  This program uses ESP32-S3 to read inputs from two PCA9555 I/O expander chips (I2C addresses 0x24 and 0x25)
  for channels 1-32, and control corresponding relays using two PCA9555 I/O expander chips (I2C addresses 0x21 and 0x22)
  for controlling 32 relays (1-32). When input1 is triggered, relay1 is activated; when input2 is triggered,
  relay2 is activated, and so on.

  The I2C bus is initialized on GPIO pins 11 (SDA) and 10 (SCL) with a frequency of 100kHz.
*/

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

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

// Initialize the PCA9555 objects for controlling relays (channels 1-32)
PCA9555 output_ioex1; // For relays 1-16 (I2C address 0x21)
PCA9555 output_ioex2; // For relays 17-32 (I2C address 0x22)

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

    // Initialize the I2C bus with GPIO 11 as SDA and GPIO 10 as SCL, 100kHz frequency
    Wire.begin(11, 10, 100000);

    // Configure the input PCA9555 chips (for inputs 1-32)
    input_ioex1.attach(Wire, 0x24);  // I2C address 0x24 for inputs 1-16
    input_ioex1.polarity(PCA95x5::Polarity::ORIGINAL_ALL);  // No polarity inversion
    input_ioex1.direction(PCA95x5::Direction::IN_ALL);  // Set all pins as inputs

    input_ioex2.attach(Wire, 0x25);  // I2C address 0x25 for inputs 17-32
    input_ioex2.polarity(PCA95x5::Polarity::ORIGINAL_ALL);  // No polarity inversion
    input_ioex2.direction(PCA95x5::Direction::IN_ALL);  // Set all pins as inputs

    // Configure the output PCA9555 chips (for relays 1-32)
    output_ioex1.attach(Wire, 0x21);  // I2C address 0x21 for relays 1-16
    output_ioex1.polarity(PCA95x5::Polarity::ORIGINAL_ALL);  // No polarity inversion
    output_ioex1.direction(PCA95x5::Direction::OUT_ALL);  // Set all pins as outputs
    output_ioex1.write(PCA95x5::Level::H_ALL);  // Initialize all relays to OFF (HIGH)

    output_ioex2.attach(Wire, 0x22);  // I2C address 0x22 for relays 17-32
    output_ioex2.polarity(PCA95x5::Polarity::ORIGINAL_ALL);  // No polarity inversion
    output_ioex2.direction(PCA95x5::Direction::OUT_ALL);  // Set all pins as outputs
    output_ioex2.write(PCA95x5::Level::H_ALL);  // Initialize all relays to OFF (HIGH)

    delay(50);  // Wait for initialization to complete
}

void loop() {
    // Read the input states from the first PCA9555 chip (inputs 1-16)
    uint16_t inputs_1_16 = input_ioex1.read();
   
    // Iterate through each input (1-16) and control corresponding relay output
    for (int i = 0; i < 16; ++i) {
        bool input_state = bitRead(inputs_1_16, i);  // Read the state of each input (0 = triggered, 1 = not triggered)
        if (input_state == 0) {  // If the input is triggered (pressed, i.e., LOW)
            output_ioex1.write((PCA95x5::Port::Port)i, PCA95x5::Level::L);  // Activate corresponding relay (LOW)
        } else {
            output_ioex1.write((PCA95x5::Port::Port)i, PCA95x5::Level::H);  // Deactivate relay (HIGH)
        }
    }

    // Read the input states from the second PCA9555 chip (inputs 17-32)
    uint16_t inputs_17_32 = input_ioex2.read();
   
    // Iterate through each input (17-32) and control corresponding relay output
    for (int i = 0; i < 16; ++i) {
        bool input_state = bitRead(inputs_17_32, i);  // Read the state of each input (0 = triggered, 1 = not triggered)
        if (input_state == 0) {  // If the input is triggered (pressed, i.e., LOW)
            output_ioex2.write((PCA95x5::Port::Port)i, PCA95x5::Level::L);  // Activate corresponding relay (LOW)
        } else {
            output_ioex2.write((PCA95x5::Port::Port)i, PCA95x5::Level::H);  // Deactivate relay (HIGH)
        }
    }

    delay(100);  // Small delay for stability
}
arduino ino file download: 
.zip   11-input-trigger-output.zip (Size: 1.26 KB / Downloads: 86)
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: 187.31 KB / Downloads: 84)

Print this item

  [arduino code examples for A32 Pro]-10 How to test AT command with SIM7600 4G modulde
Posted by: admin - 09-14-2024, 12:09 AM - Forum: KC868-A32/A32 Pro - No Replies

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

  ESP32-S3 with SIM7600 and RS485 Communication
  This program sends an AT command to the SIM7600 4G module every 3 seconds to query its model number.
  The response from the SIM7600 is then sent out through the RS485 interface.

  Connections:
  SIM7600:
    TXD: GPIO18
    RXD: GPIO17
  RS485:
    TXD: GPIO9
    RXD: GPIO8
*/

#include <HardwareSerial.h>

// Create a hardware serial object for SIM7600 communication using UART2
HardwareSerial sim7600(2); // UART2: TXD on GPIO18, RXD on GPIO17

// Create a hardware serial object for RS485 communication using UART1
HardwareSerial rs485(1);   // UART1: TXD on GPIO9, RXD on GPIO8

void setup() {
  // Initialize the default serial port for debugging (Serial Monitor)
  Serial.begin(115200);        // Baud rate of 115200 for debugging

  // Initialize the SIM7600 serial port with baud rate of 115200
  // Set TX to GPIO18 and RX to GPIO17
  sim7600.begin(115200, SERIAL_8N1, 17, 18);

  // Initialize the RS485 serial port with baud rate of 9600
  // Set TX to GPIO9 and RX to GPIO8
  rs485.begin(9600, SERIAL_8N1, 8, 9);

  // Wait for 3 seconds before starting (optional, can be used for initialization delay)
  delay(3000);
}

void loop() {
  // Send the AT command to query SIM7600 module model number
  // "AT+CGMM" is the command used to get the model of the SIM7600
  sim7600.println("AT+CGMM");

  // Wait for 1 second to allow time for the SIM7600 to respond
  delay(1000);

  // Check if there is any data available from the SIM7600 module
  if (sim7600.available()) {
    // Create a string to store the response from the SIM7600
    String simResponse = "";

    // While data is available from the SIM7600, read it byte by byte
    while (sim7600.available()) {
      // Read one byte from the SIM7600 serial
      char c = sim7600.read();
      // Append the byte to the response string
      simResponse += c;
    }
   
    // Send the SIM7600 response to the RS485 serial port
    rs485.print(simResponse);

    // Also print the response to the Serial Monitor for debugging
    Serial.println(simResponse);
  }

  // Wait for 3 seconds before sending the next query
  delay(3000);
}
arduino ino file download: 
.zip   10-4g-sim7600.zip (Size: 1.04 KB / Downloads: 78)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download: 
.zip   10-4g-sim7600.ino.merged.zip (Size: 182.27 KB / Downloads: 82)

Print this item

  [arduino code examples for A32 Pro]-09 How to output DC0-10v from GP8403 DAC port
Posted by: admin - 09-14-2024, 12:06 AM - Forum: KC868-A32/A32 Pro - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* This Arduino program controls the GP8403 DAC I2C chip using an ESP32-S3 board.
* The program sets the DAC outputs for two channels:
* - Channel 0 (CH0) outputs 5V.
* - Channel 1 (CH1) outputs 10V.
*
* The I2C communication is handled using the Wire library, and the SDA and SCL pins
* are custom defined as GPIO11 (SDA) and GPIO10 (SCL).
*
* GP8403 I2C address: 0x58
*/

#include "DFRobot_GP8403.h"

// Initialize the GP8403 DAC object with the I2C address 0x58
DFRobot_GP8403 dac(&Wire, 0x58);

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

  // Initialize I2C communication with custom SDA and SCL pins
  Wire.begin(11, 10);  // SDA = GPIO11, SCL = GPIO10

  // Try to initialize the DAC, retry if initialization fails
  while(dac.begin() != 0) {
    Serial.println("Initialization failed, retrying...");
    delay(1000);  // Wait for 1 second before retrying
  }

  // If initialization succeeds
  Serial.println("Initialization successful!");

  // Set the DAC output range to 10V (this setting applies to both channels)
  dac.setDACOutRange(dac.eOutputRange10V);

  // Set the output for DAC channel 0 to 5V
  // Range for 10V mode is 0-10000, so 5000 represents 5V
  dac.setDACOutVoltage(5000, 0);  // Set CH0 to 5V
  Serial.println("Channel 0 set to 5V");

  // Set the output for DAC channel 1 to 10V
  dac.setDACOutVoltage(10000, 1);  // Set CH1 to 10V
  Serial.println("Channel 1 set to 10V");

  // Store the data in the chip's non-volatile memory so it persists after power-off
  dac.store();
  Serial.println("DAC values stored in memory");
}

void loop() {
  // No need to continuously write the values, the DAC holds the last set value
}
arduino ino file download: 
.zip   9-dac-GP8403.zip (Size: 975 bytes / Downloads: 68)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download: 
.zip   9-dac-GP8403.ino.merged.zip (Size: 187.92 KB / Downloads: 74)

Print this item