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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 8,293
» Latest member: swilson
» Forum threads: 3,623
» Forum posts: 18,689

Full Statistics

Online Users
There are currently 67 online users.
» 0 Member(s) | 54 Guest(s)
AhrefsBot, Amazonbot, Applebot, Bing, Crawl, Google, Yandex, bot

Latest Threads
clk_mode for ethernet
Forum: KC868-AI
Last Post: cvonk
1 minute ago
» Replies: 2
» Views: 19
a16v3 - reed switch and m...
Forum: KC868-A16v3
Last Post: admin
4 hours ago
» Replies: 13
» Views: 566
KC868-M16v2 configure yam...
Forum: KC868-M16 / M1 / MB / M30
Last Post: admin
5 hours ago
» Replies: 114
» Views: 24,833
N60/N30/N20/N10/M30 CT se...
Forum: N20
Last Post: admin
5 hours ago
» Replies: 2
» Views: 407
KC868-Server ESP32 Ethern...
Forum: KC868-Server Raspberry Pi4 local server
Last Post: admin
Today, 05:39 AM
» Replies: 1
» Views: 6
Help with Product Slectio...
Forum: Suggestions and feedback on KinCony's products
Last Post: admin
Today, 03:12 AM
» Replies: 3
» Views: 21
Kc868a newbie questions
Forum: KC868-A series and Uair Smart Controller
Last Post: admin
Today, 12:03 AM
» Replies: 3
» Views: 25
No Ethernet, No WiFi, No ...
Forum: KC868-A128
Last Post: admin
Yesterday, 12:01 PM
» Replies: 1
» Views: 14
MB Current & Power too lo...
Forum: KC868-M16 / M1 / MB / M30
Last Post: admin
Yesterday, 01:17 AM
» Replies: 3
» Views: 31
N30 LoRa and RS485 code f...
Forum: N30
Last Post: admin
Yesterday, 01:17 AM
» Replies: 1
» Views: 12

  [arduino code examples for B24]-07 how to DS3231 RTC clock
Posted by: admin - 07-31-2025, 07:02 AM - Forum: B24 - No Replies

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

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

String serial_cmd_rcv = ""; // Serial port receiver

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

MY_DATE_STR my_date_str = {0};

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

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

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


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

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

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

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

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

  serial_cmd_rcv.trim();

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

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

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

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

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

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

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

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

  serial_cmd_rcv = "";

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

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

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

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

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

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

.zip   7-DS3231-RTC.ino.merged.zip (Size: 193.66 KB / Downloads: 251)

Print this item

  [arduino code examples for B24M]-06 How to use SD Card
Posted by: admin - 07-31-2025, 07:01 AM - Forum: B24M - No Replies

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  uint8_t cardType = SD.cardType();

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

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

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

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

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

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

.zip   6-SD.ino.merged.zip (Size: 219.14 KB / Downloads: 265)

Print this item

  [arduino code examples for B24]-06 How to use SD Card
Posted by: admin - 07-31-2025, 07:01 AM - Forum: B24 - No Replies

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  uint8_t cardType = SD.cardType();

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

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

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

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

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

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

.zip   6-SD.ino.merged.zip (Size: 219.14 KB / Downloads: 251)

Print this item

  [arduino code examples for B24M]-05 Read free GPIO state
Posted by: admin - 07-31-2025, 07:00 AM - Forum: B24M - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* GPIO Status Monitoring
*
* This program monitors the status (high or low) of multiple GPIO pins on the ESP32-S3.
* It prints the status of the pins to the serial monitor whenever a change is detected.
*
* GPIO Pins Monitored:
* - GPIO 13
* - GPIO 14
* - GPIO 21
* - GPIO 40
* - GPIO 48
* - GPIO 47
* - GPIO 7
*
* Hardware Requirements:
* - Connect the pins to appropriate devices or pull them to HIGH/LOW for testing
*/

// Define the GPIO pins to be monitored
#define GPIO_PIN_13 13
#define GPIO_PIN_14 14
#define GPIO_PIN_21 21
#define GPIO_PIN_40 40
#define GPIO_PIN_48 48
#define GPIO_PIN_47 47
#define GPIO_PIN_7   7

// Create an array to hold the GPIO pin numbers
const int monitoredPins[] = {
  GPIO_PIN_13,
  GPIO_PIN_14,
  GPIO_PIN_21,
  GPIO_PIN_40,
  GPIO_PIN_48,
  GPIO_PIN_47,
  GPIO_PIN_7
};

const int pinCount = sizeof(monitoredPins) / sizeof(monitoredPins[0]);

// Store the previous state of the GPIO pins
bool prevState[pinCount] = {false};

void setup() {
  Serial.begin(115200);       // Initialize the serial monitor
  while (!Serial);            // Wait for serial monitor to open

  // Set each monitored pin as input
  for (int i = 0; i < pinCount; i++) {
    pinMode(monitoredPins[i], INPUT);
  }

  Serial.println("GPIO Status Monitoring Started");
}

void loop() {
  for (int i = 0; i < pinCount; i++) {
    bool currentState = digitalRead(monitoredPins[i]);
    if (currentState != prevState[i]) {
      Serial.print("GPIO ");
      Serial.print(monitoredPins[i]);
      Serial.print(" changed to ");
      Serial.println(currentState ? "HIGH" : "LOW");
      prevState[i] = currentState;
    }
  }

  delay(100); // Delay to reduce serial flooding
}
arduino ino file download: 

.zip   5-free-gpio-state.zip (Size: 924 bytes / Downloads: 261)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   5-free-gpio-state.ino.merged.zip (Size: 181.63 KB / Downloads: 246)

Print this item

  [arduino code examples for B24]-05 Read free GPIO state
Posted by: admin - 07-31-2025, 07:00 AM - Forum: B24 - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* GPIO Status Monitoring
*
* This program monitors the status (high or low) of multiple GPIO pins on the ESP32-S3.
* It prints the status of the pins to the serial monitor whenever a change is detected.
*
* GPIO Pins Monitored:
* - GPIO 13
* - GPIO 14
* - GPIO 21
* - GPIO 40
* - GPIO 48
* - GPIO 47
* - GPIO 7
*
* Hardware Requirements:
* - Connect the pins to appropriate devices or pull them to HIGH/LOW for testing
*/

// Define the GPIO pins to be monitored
#define GPIO_PIN_13 13
#define GPIO_PIN_14 14
#define GPIO_PIN_21 21
#define GPIO_PIN_40 40
#define GPIO_PIN_48 48
#define GPIO_PIN_47 47
#define GPIO_PIN_7   7

// Create an array to hold the GPIO pin numbers
const int monitoredPins[] = {
  GPIO_PIN_13,
  GPIO_PIN_14,
  GPIO_PIN_21,
  GPIO_PIN_40,
  GPIO_PIN_48,
  GPIO_PIN_47,
  GPIO_PIN_7
};

const int pinCount = sizeof(monitoredPins) / sizeof(monitoredPins[0]);

// Store the previous state of the GPIO pins
bool prevState[pinCount] = {false};

void setup() {
  Serial.begin(115200);       // Initialize the serial monitor
  while (!Serial);            // Wait for serial monitor to open

  // Set each monitored pin as input
  for (int i = 0; i < pinCount; i++) {
    pinMode(monitoredPins[i], INPUT);
  }

  Serial.println("GPIO Status Monitoring Started");
}

void loop() {
  for (int i = 0; i < pinCount; i++) {
    bool currentState = digitalRead(monitoredPins[i]);
    if (currentState != prevState[i]) {
      Serial.print("GPIO ");
      Serial.print(monitoredPins[i]);
      Serial.print(" changed to ");
      Serial.println(currentState ? "HIGH" : "LOW");
      prevState[i] = currentState;
    }
  }

  delay(100); // Delay to reduce serial flooding
}
arduino ino file download: 

.zip   5-free-gpio-state.zip (Size: 924 bytes / Downloads: 256)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   5-free-gpio-state.ino.merged.zip (Size: 181.63 KB / Downloads: 235)

Print this item

  [arduino code examples for B24M]-04 RS485 communication test
Posted by: admin - 07-31-2025, 06:58 AM - Forum: B24M - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* RS485 Communication Test
*
* This program is a simple test for RS485 communication using ESP32-S3.
* It will send a message over RS485 and then read incoming messages.
* The TXD pin is defined as GPIO 16 and RXD pin is defined as GPIO 17.
*/

#include <HardwareSerial.h>

// Define RS485 pins
#define RS485_RXD 38
#define RS485_TXD 39

// Create a hardware serial object
HardwareSerial rs485Serial(1);

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

  // Initialize RS485 Serial communication
  rs485Serial.begin(9600, SERIAL_8N1, RS485_RXD, RS485_TXD);
 
  Serial.println("RS485 Test Start");
}

void loop() {
  // Send a test message
  rs485Serial.println("Hello from KinCony B24!");

  // Wait for a short period
  delay(1000);

  // Check if data is available to read
  if (rs485Serial.available()) {
    String receivedMessage = "";
    while (rs485Serial.available()) {
      char c = rs485Serial.read();
      receivedMessage += c;
    }
    // Print the received message
    Serial.print("Received: ");
    Serial.println(receivedMessage);
  }

  // Wait before sending the next message
  delay(2000);
}
arduino ino file download: 

.zip   4-RS485-Test.zip (Size: 764 bytes / Downloads: 261)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download: 

.zip   4-RS485-Test.ino.merged.zip (Size: 186.53 KB / Downloads: 254)

Print this item

  [arduino code examples for B24]-04 RS485 communication test
Posted by: admin - 07-31-2025, 06:58 AM - Forum: B24 - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* RS485 Communication Test
*
* This program is a simple test for RS485 communication using ESP32-S3.
* It will send a message over RS485 and then read incoming messages.
* The TXD pin is defined as GPIO 16 and RXD pin is defined as GPIO 17.
*/

#include <HardwareSerial.h>

// Define RS485 pins
#define RS485_RXD 38
#define RS485_TXD 39

// Create a hardware serial object
HardwareSerial rs485Serial(1);

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

  // Initialize RS485 Serial communication
  rs485Serial.begin(9600, SERIAL_8N1, RS485_RXD, RS485_TXD);
 
  Serial.println("RS485 Test Start");
}

void loop() {
  // Send a test message
  rs485Serial.println("Hello from KinCony B24!");

  // Wait for a short period
  delay(1000);

  // Check if data is available to read
  if (rs485Serial.available()) {
    String receivedMessage = "";
    while (rs485Serial.available()) {
      char c = rs485Serial.read();
      receivedMessage += c;
    }
    // Print the received message
    Serial.print("Received: ");
    Serial.println(receivedMessage);
  }

  // Wait before sending the next message
  delay(2000);
}
arduino ino file download: 

.zip   4-RS485-Test.zip (Size: 764 bytes / Downloads: 238)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download: 

.zip   4-RS485-Test.ino.merged.zip (Size: 186.53 KB / Downloads: 237)

Print this item

  [arduino code examples for B24M]-03 Read ADS1115 analog input ports value
Posted by: admin - 07-31-2025, 06:57 AM - Forum: B24M - 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: 236)
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: 236)

Print this item

  [arduino code examples for B24]-03 Read ADS1115 analog input ports value
Posted by: admin - 07-31-2025, 06:57 AM - Forum: B24 - 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: 268)
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: 259)

Print this item

  [arduino code examples for B24M]-02 Read digital input ports state
Posted by: admin - 07-31-2025, 06:55 AM - Forum: B24M - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* Description:
* This Arduino program reads the state of two 16-channel PCF8575 I/O expanders
* and prints the state of all input pins (1-24) to the Serial Monitor.
*
* Pin Definitions:
* - SDA: GPIO 8
* - SCL: GPIO 18
* - PCF8575 I2C Address: 0x22 for inputs 1-16, 0x25 for inputs 17-24
*/

#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 addresses
PCF8575 pcf8575_IN1(0x22); // The I2C address of the first PCF8575 (inputs 1-16)
PCF8575 pcf8575_IN2(0x25); // The I2C address of the second PCF8575 (inputs 17-24)

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

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

    // Initialize both PCF8575 modules
    pcf8575_IN1.begin();
    pcf8575_IN2.begin();

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

void loop() {

if (pcf8575_IN1.read(8)==0) {Serial.print("DI1 state="); Serial.println("on");}
if (pcf8575_IN1.read(9)==0) {Serial.print("DI2 state="); Serial.println("on");}
if (pcf8575_IN1.read(10)==0) {Serial.print("DI3 state="); Serial.println("on");}
if (pcf8575_IN1.read(11)==0) {Serial.print("DI4 state="); Serial.println("on");}
if (pcf8575_IN1.read(12)==0) {Serial.print("DI5 state="); Serial.println("on");}
if (pcf8575_IN1.read(13)==0) {Serial.print("DI6 state="); Serial.println("on");}
if (pcf8575_IN1.read(14)==0) {Serial.print("DI7 state="); Serial.println("on");}
if (pcf8575_IN1.read(15)==0) {Serial.print("DI8 state="); Serial.println("on");}

if (pcf8575_IN1.read(0)==0) {Serial.print("DI9 state="); Serial.println("on");}
if (pcf8575_IN1.read(1)==0) {Serial.print("DI10 state="); Serial.println("on");}
if (pcf8575_IN1.read(2)==0) {Serial.print("DI11 state="); Serial.println("on");}
if (pcf8575_IN1.read(3)==0) {Serial.print("DI12 state="); Serial.println("on");}
if (pcf8575_IN1.read(4)==0) {Serial.print("DI13 state="); Serial.println("on");}
if (pcf8575_IN1.read(5)==0) {Serial.print("DI14 state="); Serial.println("on");}
if (pcf8575_IN1.read(6)==0) {Serial.print("DI15 state="); Serial.println("on");}
if (pcf8575_IN1.read(7)==0) {Serial.print("DI16 state="); Serial.println("on");}

if (pcf8575_IN2.read(0)==0) {Serial.print("DI17 state="); Serial.println("on");}
if (pcf8575_IN2.read(1)==0) {Serial.print("DI18 state="); Serial.println("on");}
if (pcf8575_IN2.read(2)==0) {Serial.print("DI19 state="); Serial.println("on");}
if (pcf8575_IN2.read(3)==0) {Serial.print("DI20 state="); Serial.println("on");}
if (pcf8575_IN2.read(4)==0) {Serial.print("DI21 state="); Serial.println("on");}
if (pcf8575_IN2.read(5)==0) {Serial.print("DI22 state="); Serial.println("on");}
if (pcf8575_IN2.read(6)==0) {Serial.print("DI23 state="); Serial.println("on");}
if (pcf8575_IN2.read(7)==0) {Serial.print("DI24 state="); Serial.println("on");}


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

.zip   2-digital-input.zip (Size: 880 bytes / Downloads: 238)
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.64 KB / Downloads: 238)

Print this item