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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 8,800
» Latest member: orientcctv
» Forum threads: 3,865
» Forum posts: 19,727

Full Statistics

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

Latest Threads
kWh resolution
Forum: N30
Last Post: admin
10 hours ago
» Replies: 32
» Views: 1,018
"KCS" v3.24.2 firmware BI...
Forum: "KCS" v3 firmware
Last Post: admin
Today, 05:58 AM
» Replies: 0
» Views: 32
N60 Energy RS485 Modbus P...
Forum: N60
Last Post: admin
Today, 05:42 AM
» Replies: 1
» Views: 353
N30 Energy RS485 Modbus P...
Forum: N30
Last Post: admin
Today, 05:41 AM
» Replies: 1
» Views: 418
N20 Energy RS485 Modbus P...
Forum: N20
Last Post: admin
Today, 05:40 AM
» Replies: 1
» Views: 361
N10 Energy RS485 Modbus P...
Forum: N10
Last Post: admin
Today, 05:35 AM
» Replies: 1
» Views: 433
N60 N30 N20 N10 ARM CPU f...
Forum: N60
Last Post: admin
Today, 05:01 AM
» Replies: 3
» Views: 113
N60 N30 N20 N10 ARM CPU f...
Forum: N30
Last Post: admin
Today, 04:59 AM
» Replies: 0
» Views: 15
N60 N30 N20 N10 ARM CPU f...
Forum: N20
Last Post: admin
Today, 04:59 AM
» Replies: 0
» Views: 9
N60 N30 N20 N10 ARM CPU f...
Forum: N10
Last Post: admin
Today, 04:59 AM
» Replies: 0
» Views: 14

  [arduino code examples for N20]-02 How to use SD Card
Posted by: admin - 08-03-2025, 03:17 AM - Forum: N20 - 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  39
#define MISO 38
#define MOSI 40
#define CS   48

/**
* @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   2-SD.zip (Size: 1.54 KB / Downloads: 331)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   2-SD.ino.merged.zip (Size: 219.15 KB / Downloads: 314)

Print this item

  [arduino code examples for N30]-02 How to use SD Card
Posted by: admin - 08-03-2025, 03:17 AM - Forum: N30 - 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  39
#define MISO 38
#define MOSI 40
#define CS   48

/**
* @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   2-SD.zip (Size: 1.54 KB / Downloads: 317)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   2-SD.ino.merged.zip (Size: 219.15 KB / Downloads: 326)

Print this item

  [arduino code examples for N60]-01 Read digital input ports state
Posted by: admin - 08-03-2025, 03:15 AM - Forum: N60 - No Replies

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

  This program reads the digital state of GPIO15 and GPIO16 on an ESP32
  and prints their state (HIGH or LOW) to the serial monitor every 500ms.
*/

#define PIN_GPIO15 15  // Define GPIO15
#define PIN_GPIO16 16  // Define GPIO16

void setup() {
  Serial.begin(115200);               // Initialize serial communication at 115200 baud
  pinMode(PIN_GPIO15, INPUT);         // Set GPIO15 as input
  pinMode(PIN_GPIO16, INPUT);         // Set GPIO16 as input
  Serial.println("ESP32 GPIO15 and GPIO16 State Monitor");
}

void loop() {
  int state15 = digitalRead(PIN_GPIO15);  // Read state of GPIO15
  int state16 = digitalRead(PIN_GPIO16);  // Read state of GPIO16

  // Print the state to the serial monitor
  Serial.print("GPIO15: ");
  Serial.print(state15 == HIGH ? "HIGH" : "LOW");
  Serial.print("  |  GPIO16: ");
  Serial.println(state16 == HIGH ? "HIGH" : "LOW");

  delay(500);  // Wait for 500 milliseconds before reading again
}
arduino ino file download:

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

.zip   1-free-gpio-state.ino.merged.zip (Size: 181.39 KB / Downloads: 334)

Print this item

  [arduino code examples for N10]-01 Read digital input ports state
Posted by: admin - 08-03-2025, 03:15 AM - Forum: N10 - No Replies

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

  This program reads the digital state of GPIO15 and GPIO16 on an ESP32
  and prints their state (HIGH or LOW) to the serial monitor every 500ms.
*/

#define PIN_GPIO15 15  // Define GPIO15
#define PIN_GPIO16 16  // Define GPIO16

void setup() {
  Serial.begin(115200);               // Initialize serial communication at 115200 baud
  pinMode(PIN_GPIO15, INPUT);         // Set GPIO15 as input
  pinMode(PIN_GPIO16, INPUT);         // Set GPIO16 as input
  Serial.println("ESP32 GPIO15 and GPIO16 State Monitor");
}

void loop() {
  int state15 = digitalRead(PIN_GPIO15);  // Read state of GPIO15
  int state16 = digitalRead(PIN_GPIO16);  // Read state of GPIO16

  // Print the state to the serial monitor
  Serial.print("GPIO15: ");
  Serial.print(state15 == HIGH ? "HIGH" : "LOW");
  Serial.print("  |  GPIO16: ");
  Serial.println(state16 == HIGH ? "HIGH" : "LOW");

  delay(500);  // Wait for 500 milliseconds before reading again
}
arduino ino file download:

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

.zip   1-free-gpio-state.ino.merged.zip (Size: 181.39 KB / Downloads: 318)

Print this item

  [arduino code examples for N20]-01 Read digital input ports state
Posted by: admin - 08-03-2025, 03:15 AM - Forum: N20 - No Replies

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

  This program reads the digital state of GPIO15 and GPIO16 on an ESP32
  and prints their state (HIGH or LOW) to the serial monitor every 500ms.
*/

#define PIN_GPIO15 15  // Define GPIO15
#define PIN_GPIO16 16  // Define GPIO16

void setup() {
  Serial.begin(115200);               // Initialize serial communication at 115200 baud
  pinMode(PIN_GPIO15, INPUT);         // Set GPIO15 as input
  pinMode(PIN_GPIO16, INPUT);         // Set GPIO16 as input
  Serial.println("ESP32 GPIO15 and GPIO16 State Monitor");
}

void loop() {
  int state15 = digitalRead(PIN_GPIO15);  // Read state of GPIO15
  int state16 = digitalRead(PIN_GPIO16);  // Read state of GPIO16

  // Print the state to the serial monitor
  Serial.print("GPIO15: ");
  Serial.print(state15 == HIGH ? "HIGH" : "LOW");
  Serial.print("  |  GPIO16: ");
  Serial.println(state16 == HIGH ? "HIGH" : "LOW");

  delay(500);  // Wait for 500 milliseconds before reading again
}
arduino ino file download:

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

.zip   1-free-gpio-state.ino.merged.zip (Size: 181.39 KB / Downloads: 332)

Print this item

  [arduino code examples for N30]-01 Read digital input ports state
Posted by: admin - 08-03-2025, 03:15 AM - Forum: N30 - No Replies

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

  This program reads the digital state of GPIO15 and GPIO16 on an ESP32
  and prints their state (HIGH or LOW) to the serial monitor every 500ms.
*/

#define PIN_GPIO15 15  // Define GPIO15
#define PIN_GPIO16 16  // Define GPIO16

void setup() {
  Serial.begin(115200);               // Initialize serial communication at 115200 baud
  pinMode(PIN_GPIO15, INPUT);         // Set GPIO15 as input
  pinMode(PIN_GPIO16, INPUT);         // Set GPIO16 as input
  Serial.println("ESP32 GPIO15 and GPIO16 State Monitor");
}

void loop() {
  int state15 = digitalRead(PIN_GPIO15);  // Read state of GPIO15
  int state16 = digitalRead(PIN_GPIO16);  // Read state of GPIO16

  // Print the state to the serial monitor
  Serial.print("GPIO15: ");
  Serial.print(state15 == HIGH ? "HIGH" : "LOW");
  Serial.print("  |  GPIO16: ");
  Serial.println(state16 == HIGH ? "HIGH" : "LOW");

  delay(500);  // Wait for 500 milliseconds before reading again
}
arduino ino file download:

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

.zip   1-free-gpio-state.ino.merged.zip (Size: 181.39 KB / Downloads: 297)

Print this item

  N60/N30/N20/N10 PC software for RS485 modbus connection
Posted by: admin - 08-03-2025, 03:07 AM - Forum: N60 - Replies (3)

connect PC to N60 by USB-RS485 adapter.
   
pc software download:

.zip   N60_APP.zip (Size: 1.66 MB / Downloads: 385)

Print this item

  N60/N30/N20/N10 PC software for RS485 modbus connection
Posted by: admin - 08-03-2025, 03:07 AM - Forum: N10 - Replies (1)

connect PC to N60 by USB-RS485 adapter.
   
pc software download:

.zip   N60_APP.zip (Size: 1.66 MB / Downloads: 367)

Print this item

  N60/N30/N20/N10 PC software for RS485 modbus connection
Posted by: admin - 08-03-2025, 03:07 AM - Forum: N20 - Replies (1)

connect PC to N60 by USB-RS485 adapter.
   
pc software download:

.zip   N60_APP.zip (Size: 1.66 MB / Downloads: 348)

Print this item

  N60/N30/N20/N10 PC software for RS485 modbus connection
Posted by: admin - 08-03-2025, 03:07 AM - Forum: N30 - Replies (1)

connect PC to N60 by USB-RS485 adapter.
   
pc software download:

.zip   N60_APP.zip (Size: 1.66 MB / Downloads: 354)

Print this item