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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 8,835
» Latest member: myaichatszaaab
» Forum threads: 3,865
» Forum posts: 19,745

Full Statistics

Online Users
There are currently 37 online users.
» 0 Member(s) | 18 Guest(s)
AhrefsBot, Amazonbot, Baidu, Bytespider, Crawl, Google, Sogou web, Yandex, bot

Latest Threads
Bulk IFTTT mapping
Forum: "KCS" v3 firmware
Last Post: npekpacHo
Yesterday, 08:55 AM
» Replies: 2
» Views: 256
Connecting Nextion NX3224...
Forum: KC868-A series and Uair Smart Controller
Last Post: admin
Yesterday, 01:38 AM
» Replies: 1
» Views: 12
Very Low Volume even at M...
Forum: KinCony AS
Last Post: MartinBanner
03-26-2026, 11:23 PM
» Replies: 0
» Views: 11
AS-ESP32-S3 won't initial...
Forum: Getting Started with ESPHome and Home Assistant
Last Post: MartinBanner
03-26-2026, 11:03 PM
» Replies: 10
» Views: 273
N60 N30 N20 N10 ARM CPU f...
Forum: N30
Last Post: admin
03-26-2026, 10:05 PM
» Replies: 6
» Views: 81
Just Arrived: Annoying Bu...
Forum: KinCony AS
Last Post: admin
03-25-2026, 10:12 PM
» Replies: 4
» Views: 1,071
kWh resolution
Forum: N30
Last Post: admin
03-25-2026, 10:11 PM
» Replies: 34
» Views: 1,274
Channels always have curr...
Forum: KC868-AP / ADR
Last Post: admin
03-25-2026, 09:09 AM
» Replies: 21
» Views: 6,091
"KCS" v3.24.2 firmware BI...
Forum: "KCS" v3 firmware
Last Post: admin
03-24-2026, 05:58 AM
» Replies: 0
» Views: 173
N60 Energy RS485 Modbus P...
Forum: N60
Last Post: admin
03-24-2026, 05:42 AM
» Replies: 1
» Views: 367

  [arduino code examples for N30]-05 collect N30 all data demo
Posted by: admin - 08-03-2025, 03:27 AM - Forum: N30 - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* Demo Program for Reading Data from KinCony N60 Energy Meter (60-channel version)
* via RS485 Modbus using ESP32 and NonBlockingModbusMaster library.
*
* This example:
* - Initializes RS485 Modbus communication
* - Reads current, power, energy, voltage, frequency, temperature, power factor from 6 chips
* - Prints all data to Serial Monitor
* - Uses TaskScheduler to run periodic tasks
*/

#include "TaskScheduler.h"
#include "HardwareSerial.h"
//#include "modbus-rtu.h"
#include "NonBlockingModbusMaster.h"  // Include non-blocking Modbus master library

/////defined anything here====================
#define MAX_U16DATA_LEN  68  // Number of 16-bit registers to read per chip

// Define RS485 serial and control pins
#define TX_PIN 8
#define DE_PIN 3
#define RX_PIN 18

// Define Modbus function codes
typedef enum{
  FC_READ_COIL = 1,
  FC_READ_HOLDREG = 3,
  FC_READ_INPUTREG = 4,
  FC_FORCE_COIL = 5,
  FC_FORCE_COILS = 15,
  FC_WRITE_REG = 6,
  FC_WRITE_REGS = 16,
}FC_DEF;

// Define structure to hold all the electrical parameters per chip
typedef struct
{
    uint32_t RMS_1;        //0    //XX.XXX    A        0.001A/LSB
    uint32_t RMS_2;
    uint32_t RMS_3;
    uint32_t RMS_4;
    uint32_t RMS_5;
    uint32_t RMS_6;
    uint32_t RMS_7;
    uint32_t RMS_8;
    uint32_t RMS_9;
    uint32_t RMS_10;
    uint32_t WATT_1;        //20 XXXX.X    W        0.1W/LSB
    uint32_t WATT_2;
    uint32_t WATT_3;
    uint32_t WATT_4;
    uint32_t WATT_5;
    uint32_t WATT_6;
    uint32_t WATT_7;
    uint32_t WATT_8;
    uint32_t WATT_9;
    uint32_t WATT_10;//
    uint32_t Energy_1;        //40 XXXXXX    kWh   1kWh/LSB,MAX:65535kWh
    uint32_t Energy_2;
    uint32_t Energy_3;
    uint32_t Energy_4;
    uint32_t Energy_5;
    uint32_t Energy_6;
    uint32_t Energy_7;
    uint32_t Energy_8;
    uint32_t Energy_9;
    uint32_t Energy_10; //
    uint32_t Energy_Sum; //60
    uint16_t RMS_V;            //62 XXX.X    V            0.01V/LSB
    uint16_t Period;        //63 XX.XX    Hz        0.01Hz/LSB
    float TPS1;            //64 XX.XX ℃            0.1℃/LSB
    float PF;  //66
}Elect_StructDef_JKE;

typedef union{
  Elect_StructDef_JKE jke_n60_str[6]; ////6 chips each have MAX_STRU_LEN data
  ushort read_regs_arr[6][MAX_U16DATA_LEN];
}COLLECT_UNION;

////define instance here================================================================
COLLECT_UNION jke_n60_data_union = {0};
HardwareSerial collectSerial(2);
Scheduler ts;   // Task scheduler
NonBlockingModbusMaster nbModbusMaster;

////define macros here===================
static void collectAllChipData();
static void PrintfInfo();

////define my work task==================================
Task collectDataTask(200,TASK_FOREVER,[]()
{
  collectAllChipData();
});

Task heartBeatTask(1000,TASK_FOREVER,[]()
{
  ////do anything in heartBeatTask to make sense for anyone or other.
  Serial.println("heartbeat task is running.");
});


void setup() {
  // put your setup code here, to run once:

  // Open serial communications and wait for port to open:
    Serial.begin(115200);
    collectSerial.begin(115200,SERIAL_8N1,9,10);///RX & TX
    float bitduration = 1.f / 115200;
    float charlen = 10.0f; // 8 bits + 1 stop, parity ?
    float preDelayBR = bitduration * charlen * 3.5f * 1e6  + 1; // in us
    float postDelayBR = bitduration * charlen * 3.5f * 1e6 + 1; // in us
    nbModbusMaster.initialize(collectSerial, preDelayBR, postDelayBR,1000);

  ////add task to scheduler
  ts.addTask(collectDataTask);
  ts.addTask(heartBeatTask);

  ////start task
  collectDataTask.enable(); ///start task
  heartBeatTask.enable();
}

bool isMbConnect = false;
int cnt_chip = 0;

void loop() {
  static int retryCount = 0;
  // put your main code here, to run repeatedly:
  ts.execute();

  if (nbModbusMaster.justFinished())
  {
   
    // check for errors
    int err = nbModbusMaster.getError(); // 0 for OK
    if (err) {
      isMbConnect = false;   
      Serial.print("Error: "); nbModbusMaster.printHex(err, Serial); Serial.println();
      if ((err == nbModbusMaster.ku8MBResponseTimedOut) ) {
        retryCount++;
        Serial.println("Mbtask Retry");
        nbModbusMaster.retry(); // send same cmd again
      }
    } else {
      retryCount = 0; // success
    }
    if (err == 0) {
      isMbConnect = true;
      if(cnt_chip==5)
      {
        PrintfInfo();
      }

      for (int i = 0; i < nbModbusMaster.getResponseBufferLength(); i++) {
        jke_n60_data_union.read_regs_arr[cnt_chip][i] = nbModbusMaster.getResponseBuffer(i);
        //nbModbusMaster.printHex(nbModbusMaster.getResponseBuffer(i), Serial); Serial.print(" ");
      }

      cnt_chip++;
      if(cnt_chip >= 6) cnt_chip = 0;

    }
  }

}

static void PrintfInfo()
{
  char send_buf[100] = {0};
  uint32_t *ptr;
  uint16_t *ptr2;
  float *ptr3;

  memset(send_buf,0,100);
    ///// PRINTF ALL DATA READ FROM CHIP REGISTER.

    for(int j=0;j<6;j++)
    {
    sprintf(send_buf,">>chip/socket : %d Info:",j+1);
    Serial.println(send_buf);     

    ptr= &jke_n60_data_union.jke_n60_str[j].RMS_1;
    ptr2 = &jke_n60_data_union.jke_n60_str[j].RMS_V;
    ptr3 = &jke_n60_data_union.jke_n60_str[j].TPS1;

    for(int i=0;i<35;i++)
    {
      if(i < 10)       
      {
        sprintf(send_buf,"RMS_%d:    %.2f A,",i+1,*(ptr+i) * 0.001);
        Serial.println(send_buf);
      }
      else if(i < 20)       
      {
        sprintf(send_buf,"WATT_%d:    %.2f W,",i+1-10,*(ptr+i) * 0.1);
        Serial.println(send_buf);
      }
      else if(i < 30)       
      {
        sprintf(send_buf,"Energy_%d:    %d kWh,",i+1-20,*(ptr+i) );
        Serial.println(send_buf);
      }
      else if(i == 30)       
      {
        sprintf(send_buf,"Energy_sum:    %d kWh,",*(ptr+i) );
        Serial.println(send_buf);
        memset(send_buf,0,100);
      }
      else if(i == 31)       
      {
        sprintf(send_buf,"RMS_V:    %.2f V,",*ptr2 *0.01); ///62
        Serial.println(send_buf);
        memset(send_buf,0,100);
      }
      else if(i == 32)       
      {
        sprintf(send_buf,"Period:    %.2f Hz,",*(ptr2+1) *0.01);
        Serial.println(send_buf);
        memset(send_buf,0,100);
      }
      else if(i == 33)       
      {
        sprintf(send_buf,"Chip_Temp:    %.1f ^C,",*ptr3  );
        Serial.println(send_buf);
        memset(send_buf,0,100);
      }
      else if(i == 34)       
      {
        sprintf(send_buf,"PF:    %.4f .",*(ptr3+1) );
        Serial.println(send_buf);
        memset(send_buf,0,100);
      }
    }

    if(j==5)
      Serial.println(">>Data Finished!>>"); 

  }
}

static void collectAllChipData()
{
  int read_addr_start = (cnt_chip+1) * 100;
 
  String str = "";
  uint16_t size = MAX_U16DATA_LEN;

  nbModbusMaster.readHoldingRegisters(1, read_addr_start, size);
 
}
arduino ino file download:

.zip   collect_n60_data_demo.zip (Size: 2.45 KB / Downloads: 323)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   collect_n60_data_demo.ino.merged.zip (Size: 189.94 KB / Downloads: 321)

before run the code, you need to install NonBlockingModbusMaster arduino library.
   

modify library .h file replace the number as photo.
   

after running code, will print all data by USB port:
Code:
y_5:    0 kWh,
Energy_6:    0 kWh,
Energy_7:    0 kWh,
Energy_8:    0 kWh,
Energy_9:    0 kWh,
Energy_10:    0 kWh,

RMS_V:    233.58 V,
Period:    49.70 Hz,
Chip_Temp:    25.5 ^C,
PF:    0.0000 .
>>Data Finished!>>
heartbeat task is running.
>>chip/socket : 1 Info:
RMS_1:    0.00 A,
RMS_2:    0.00 A,
RMS_3:    0.00 A,
RMS_4:    0.00 A,
RMS_5:    0.00 A,
RMS_6:    0.00 A,
RMS_7:    0.00 A,
RMS_8:    0.00 A,
RMS_9:    0.00 A,
RMS_10:    0.00 A,
WATT_1:    0.00 W,
WATT_2:    0.00 W,
WATT_3:    0.00 W,
WATT_4:    0.00 W,
WATT_5:    0.00 W,
WATT_6:    0.00 W,
WATT_7:    0.00 W,
WATT_8:    0.00 W,
WATT_9:    0.00 W,
WATT_10:    0.00 W,
Energy_1:    0 kWh,
Energy_2:    0 kWh,
Energy_3:    0 kWh,
Energy_4:    0 kWh,
Energy_5:    0 kWh,
Energy_6:    0 kWh,
Energy_7:    0 kWh,
Energy_8:    0 kWh,
Energy_9:    0 kWh,
Energy_10:    0 kWh,
Energy_sum:    0 kWh,
RMS_V:    0.00 V,
Period:    9.53 Hz,
Chip_Temp:    24.4 ^C,
PF:    0.0000 .
>>chip/socket : 2 Info:
RMS_1:    0.00 A,
RMS_2:    0.00 A,
RMS_3:    0.00 A,
RMS_4:    0.00 A,
RMS_5:    0.00 A,
RMS_6:    0.00 A,
RMS_7:    0.00 A,
RMS_8:    0.00 A,
RMS_9:    0.00 A,
RMS_10:    0.00 A,
WATT_1:    0.00 W,
WATT_2:    0.00 W,
WATT_3:    0.00 W,
WATT_4:    0.00 W,
WATT_5:    0.00 W,
WATT_6:    0.00 W,
WATT_7:    0.00 W,
WATT_8:    0.00 W,
WATT_9:    0.00 W,
WATT_10:    0.00 W,
Energy_1:    0 kWh,
Energy_2:    0 kWh,
Energy_3:    0 kWh,
Energy_4:    0 kWh,
Energy_5:    0 kWh,
Energy_6:    0 kWh,
Energy_7:    0 kWh,
Energy_8:    0 kWh,
Energy_9:    0 kWh,
Energy_10:    0 kWh,
Energy_sum:    0 kWh,
RMS_V:    0.00 V,
Period:    9.53 Hz,
Chip_Temp:    23.8 ^C,
PF:    0.0000 .
>>chip/socket : 3 Info:
RMS_1:    0.00 A,
RMS_2:    0.00 A,
RMS_3:    0.00 A,
RMS_4:    0.00 A,
RMS_5:    0.00 A,
RMS_6:    0.00 A,
RMS_7:    0.00 A,
RMS_8:    0.00 A,
RMS_9:    0.00 A,
RMS_10:    0.00 A,
WATT_1:    0.00 W,
WATT_2:    0.00 W,
WATT_3:    0.00 W,
WATT_4:    0.00 W,
WATT_5:    0.00 W,
WATT_6:    0.00 W,
WATT_7:    0.00 W,
WATT_8:    0.00 W,
WATT_9:    0.00 W,
WATT_10:    0.00 W,
Energy_1:    0 kWh,
Energy_2:    0 kWh,
Energy_3:    0 kWh,
Energy_4:    0 kWh,
Energy_5:    0 kWh,
Energy_6:    0 kWh,
Energy_7:    0 kWh,
Energy_8:    0 kWh,
Energy_9:    0 kWh,
Energy_10:    0 kWh,
Energy_sum:    0 kWh,
RMS_V:    0.00 V,
Period:    9.53 Hz,
Chip_Temp:    25.0 ^C,
PF:    0.0000 .
>>chip/socket : 4 Info:
RMS_1:    0.00 A,
RMS_2:    0.00 A,
RMS_3:    0.00 A,
RMS_4:    0.00 A,
RMS_5:    0.00 A,
RMS_6:    0.00 A,
RMS_7:    0.00 A,
RMS_8:    0.00 A,
RMS_9:    0.00 A,
RMS_10:    0.00 A,
WATT_1:    0.00 W,
WATT_2:    0.00 W,
WATT_3:    0.00 W,
WATT_4:    0.00 W,
WATT_5:    0.00 W,
WATT_6:    0.00 W,
WATT_7:    0.00 W,
WATT_8:    0.00 W,
WATT_9:    0.00 W,
WATT_10:    0.00 W,
Energy_1:    0 kWh,
Energy_2:    0 kWh,
Energy_3:    0 kWh,
Energy_4:    0 kWh,
Energy_5:    0 kWh,
Energy_6:    0 kWh,
Energy_7:    0 kWh,
Energy_8:    0 kWh,
Energy_9:    0 kWh,
Energy_10:    0 kWh,
Energy_sum:    0 kWh,
RMS_V:    0.00 V,
Period:    9.53 Hz,
Chip_Temp:    23.8 ^C,
PF:    0.0000 .
>>chip/socket : 5 Info:
RMS_1:    0.00 A,
RMS_2:    0.00 A,
RMS_3:    0.00 A,
RMS_4:    0.00 A,
RMS_5:    0.00 A,
RMS_6:    0.00 A,
RMS_7:    0.00 A,
RMS_8:    0.00 A,
RMS_9:    0.00 A,
RMS_10:    0.00 A,
WATT_1:    0.00 W,
WATT_2:    0.00 W,
WATT_3:    0.00 W,
WATT_4:    0.00 W,
WATT_5:    0.00 W,
WATT_6:    0.00 W,
WATT_7:    0.00 W,
WATT_8:    0.00 W,
WATT_9:    0.00 W,
WATT_10:    0.00 W,
Energy_1:    0 kWh,
Energy_2:    0 kWh,
Energy_3:    0 kWh,
Energy_4:    0 kWh,
Energy_5:    0 kWh,
Energy_6:    0 kWh,
Energy_7:    0 kWh,
Energy_8:    0 kWh,
Energy_9:    0 kWh,
Energy_10:    0 kWh,
Energy_sum:    0 kWh,
RMS_V:    0.00 V,
Period:    9.53 Hz,
Chip_Temp:    25.5 ^C,
PF:    0.0000 .
>>chip/socket : 6 Info:
RMS_1:    0.00 A,
RMS_2:    0.00 A,
RMS_3:    0.00 A,
RMS_4:    0.00 A,
RMS_5:    0.00 A,
RMS_6:    0.00 A,
RMS_7:    0.00 A,
RMS_8:    0.00 A,
RMS_9:    0.00 A,
RMS_10:    0.00 A,
WATT_1:    0.00 W,
WATT_2:    3.20 W,
WATT_3:    0.00 W,
WATT_4:    0.00 W,
WATT_5:    0.00 W,
WATT_6:    0.00 W,
WATT_7:    0.00 W,
WATT_8:    0.00 W,
WATT_9:    0.00 W,
WATT_10:    0.00 W,
Energy_1:    0 kWh,
Energy_2:    0 kWh,
Energy_3:    0 kWh,
Energy_4:    0 kWh,
Energy_5:    0 kWh,
Energy_6:    0 kWh,
Energy_7:    0 kWh,
Energy_8:    0 kWh,
Energy_9:    0 kWh,
Energy_10:    0 kWh,
Energy_sum:    0 kWh,
RMS_V:    233.50 V,
Period:    49.71 Hz,
Chip_Temp:    25.7 ^C,
PF:    0.0000 .
>>Data Finished!>>
heartbeat task is running.
>>chip/socket : 1 Info:
RMS_1:    0.00 A,
RMS_2:    0.00 A,
RMS_3:    0.00 A,
RMS_4:    0.00 A,
RMS_5:    0.00 A,
RMS_6:    0.00 A,
RMS_7:    0.00 A,
RMS_8:    0.00 A,
RMS_9:    0.00 A,
RMS_10:    0.00 A,
WATT_1:    0.00 W,
WATT_2:    0.00 W,
WATT_3:    0.00 W,
WATT_4:    0.00 W,
WATT_5:    0.00 W,
WATT_6:    0.00 W,
WATT_7:    0.00 W,
WATT_8:    0.00 W,
WATT_9:    0.00 W,
WATT_10:    0.00 W,
Energy_1:    0 kWh,
Energy_2:    0 kWh,
Energy_3:    0 kWh,
Energy_4:    0 kWh,
Energy_5:    0 kWh,
Energy_6:    0 kWh,
Energy_7:    0 kWh,
Energy_8:    0 kWh,
Energy_9:    0 kWh,
Energy_10:    0 kWh,
Energy_sum:    0 kWh,
RMS_V:    0.00 V,
Period:    9.53 Hz,
Chip_Temp:    24.2 ^C,
PF:    0.0000 .
>>chip/socket : 2 Info:
RMS_1:    0.00 A,
RMS_2:    0.00 A,
RMS_3:    0.00 A,
RMS_4:    0.00 A,
RMS_5:    0.00 A,
RMS_6:    0.00 A,
RMS_7:    0.00 A,
RMS_8:    0.00 A,
RMS_9:    0.00 A,
RMS_10:    0.00 A,
WATT_1:    0.00 W,
WATT_2:    0.00 W,
WATT_3:    0.00 W,
WATT_4:    0.00 W,
WATT_5:    0.00 W,
WATT_6:    0.00 W,
WATT_7:    0.00 W,
WATT_8:    0.00 W,
WATT_9:    0.00 W,
WATT_10:    0.00 W,
Energy_1:    0 kWh,
Energy_2:    0 kWh,
Energy_3:    0 kWh,
Energy_4:    0 kWh,
Energy_5:    0 kWh,
Energy_6:    0 kWh,
Energy_7:    0 kWh,
Energy_8:    0 kWh,
Energy_9:    0 kWh,
Energy_10:    0 kWh,
Energy_sum:    0 kWh,
RMS_V:    0.00 V,
Period:    9.53 Hz,
Chip_Temp:    23.8 ^C,
PF:    0.0000 .
>>chip/socket : 3 Info:
RMS_1:    0.00 A,
RMS_2:    0.00 A,
RMS_3:    0.00 A,
RMS_4:    0.00 A,
RMS_5:    0.00 A,
RMS_6:    0.00 A,
RMS_7:    0.00 A,
RMS_8:    0.00 A,
RMS_9:    0.00 A,
RMS_10:    0.00 A,
WATT_1:    0.00 W,
WATT_2:    0.00 W,
WATT_3:    0.00 W,
WATT_4:    0.00 W,
WATT_5:    0.00 W,
WATT_6:    0.00 W,
WATT_7:    0.00 W,
WATT_8:    0.00 W,
WATT_9:    0.00 W,
WATT_10:    0.00 W,
Energy_1:    0 kWh,
Energy_2:    0 kWh,
Energy_3:    0 kWh,
Energy_4:    0 kWh,
Energy_5:    0 kWh,
Energy_6:    0 kWh,
Energy_7:    0 kWh,
Energy_8:    0 kWh,
Energy_9:    0 kWh,
Energy_10:    0 kWh,
Energy_sum:    0 kWh,
RMS_V:    0.00 V,
Period:    9.53 Hz,
Chip_Temp:    25.0 ^C,
PF:    0.0000 .
>>chip/socket : 4 Info:
RMS_1:    0.00 A,
RMS_2:    0.00 A,
RMS_3:    0.00 A,
RMS_4:    0.00 A,
RMS_5:    0.00 A,
RMS_6:    0.00 A,
RMS_7:    0.00 A,
RMS_8:    0.00 A,
RMS_9:    0.00 A,
RMS_10:    0.00 A,
WATT_1:    0.00 W,
WATT_2:    0.00 W,
WATT_3:    0.00 W,
WATT_4:    0.00 W,
WATT_5:    0.00 W,
WATT_6:    0.00 W,
WATT_7:    0.00 W,
WATT_8:    0.00 W,
WATT_9:    0.00 W,
WATT_10:    0.00 W,
Energy_1:    0 kWh,
Energy_2:    0 kWh,
Energy_3:    0 kWh,
Energy_4:    0 kWh,
Energy_5:    0 kWh,
Energy_6:    0 kWh,
Energy_7:    0 kWh,
Energy_8:    0 kWh,
Energy_9:    0 kWh,
Energy_10:    0 kWh,
Energy_sum:    0 kWh,
RMS_V:    0.00 V,
Period:    9.53 Hz,
Chip_Temp:    23.6 ^C,
PF:    0.0000 .
>>chip/socket : 5 Info:
RMS_1:    0.00 A,
RMS_2:    0.00 A,
RMS_3:    0.00 A,
RMS_4:    0.00 A,
RMS_5:    0.00 A,
RMS_6:    0.00 A,
RMS_7:    0.00 A,
RMS_8:    0.00 A,
RMS_9:    0.00 A,
RMS_10:    0.00 A,
WATT_1:    0.00 W,
WATT_2:    0.00 W,
WATT_3:    0.00 W,
WATT_4:    0.00 W,
WATT_5:    0.00 W,
WATT_6:    0.00 W,
WATT_7:    0.00 W,
WATT_8:    0.00 W,
WATT_9:    0.00 W,
WATT_10:    0.00 W,
Energy_1:    0 kWh,
Energy_2:    0 kWh,
Energy_3:    0 kWh,
Energy_4:    0 kWh,
Energy_5:    0 kWh,
Energy_6:    0 kWh,
Energy_7:    0 kWh,
Energy_8:    0 kWh,
Energy_9:    0 kWh,
Energy_10:    0 kWh,
Energy_sum:    0 kWh,
RMS_V:    0.00 V,
Period:    9.53 Hz,
Chip_Temp:    24.8 ^C,
PF:    0.0000 .
>>chip/socket : 6 Info:
RMS_1:    0.00 A,
RMS_2:    0.00 A,
RMS_3:    0.00 A,
RMS_4:    0.00 A,
RMS_5:    0.00 A,
RMS_6:    0.00 A,
RMS_7:    0.00 A,
RMS_8:    0.00 A,
RMS_9:    0.00 A,
RMS_10:    0.00 A,
WATT_1:    0.00 W,
WATT_2:    1.50 W,
WATT_3:    0.00 W,
WATT_4:    0.00 W,
WATT_5:    0.00 W,
WATT_6:    0.00 W,
WATT_7:    0.00 W,
WATT_8:    0.00 W,
WATT_9:    0.00 W,
WATT_10:    0.00 W,
Energy_1:    0 kWh,
Energy_2:    0 kWh,
Energy_3:    0 kWh,
Energy_4:    0 kWh,
Energy_5:    0 kWh,
Energy_6:    0 kWh,
Energy_7:    0 kWh,
Energy_8:    0 kWh,
Energy_9:    0 kWh,
Energy_10:    0 kWh,
Energy_sum:    0 kWh,
RMS_V:    233.57 V,
Period:    49.71 Hz,
Chip_Temp:    25.5 ^C,
PF:    0.0000 .
>>Data Finished!>>
heartbeat task is running.
heartbeat task is running.
>>chip/socket : 1 Info:
RMS_1:    0.00 A,
RMS_2:    0.00 A,
RMS_3:    0.00 A,
RMS_4:    0.00 A,
RMS_5:    0.00 A,
RMS_6:    0.00 A,
RMS_7:    0.00 A,
RMS_8:    0.00 A,
RMS_9:    0.00 A,
RMS_10:    0.00 A,
WATT_1:    0.00 W,
WATT_2:    0.00 W,
WATT_3:    0.00 W,
WATT_4:    0.00 W,
WATT_5:    0.00 W,
WATT_6:    0.00 W,
WATT_7:    0.00 W,
WATT_8:    0.00 W,
WATT_9:    0.00 W,
WATT_10:    0.00 W,
Energy_1:    0 kWh,
Energy_2:    0 kWh,
Energy_3:    0 kWh,
Energy_4:    0 kWh,
Energy_5:    0 kWh,
Energy_6:    0 kWh,
Energy_7:    0 kWh,
Energy_8:    0 kWh,
Energy_9:    0 kWh,
Energy_10:    0 kWh,
Energy_sum:    0 kWh,
RMS_V:    0.00 V,
Period:    9.53 Hz,
Chip_Temp:    24.0 ^C,
PF:    0.0000 .
>>chip/socket : 2 Info:
RMS_1:    0.00 A,
RMS_2:    0.00 A,
RMS_3:    0.00 A,
RMS_4:    0.00 A,
RMS_5:    0.00 A,
RMS_6:    0.00 A,
RMS_7:    0.00 A,
RMS_8:    0.00 A,
RMS_9:    0.00 A,
RMS_10:    0.00 A,
WATT_1:    0.00 W,
WATT_2:    0.00 W,
WATT_3:    0.00 W,
WATT_4:    0.00 W,
WATT_5:    0.00 W,
WATT_6:    0.00 W,
WATT_7:    0.00 W,
WATT_8:    0.00 W,
WATT_9:    0.00 W,
WATT_10:    0.00 W,
Energy_1:    0 kWh,
Energy_2:    0 kWh,
Energy_3:    0 kWh,
Energy_4:    0 kWh,
Energy_5:    0 kWh,
Energy_6:    0 kWh,
Energy_7:    0 kWh,
Energy_8:    0 kWh,
Energy_9:    0 kWh,
Energy_10:    0 kWh,
Energy_sum:    0 kWh,
RMS_V:    0.00 V,
Period:    9.53 Hz,
Chip_Temp:    23.8 ^C,
PF:    0.0000 .
>>chip/socket : 3 Info:
RMS_1:    0.00 A,
RMS_2:    0.00 A,
RMS_3:    0.00 A,
RMS_4:    0.00 A,
RMS_5:    0.00 A,
RMS_6:    0.00 A,
RMS_7:    0.00 A,
RMS_8:    0.00 A,
RMS_9:    0.00 A,
RMS_10:    0.00 A,
WATT_1:    0.00 W,
WATT_2:    0.00 W,
WATT_3:    0.00 W,
WATT_4:    0.00 W,
WATT_5:    0.00 W,
WATT_6:    0.00 W,
WATT_7:    0.00 W,
WATT_8:    0.00 W,
WATT_9:    0.00 W,
WATT_10:    0.00 W,
Energy_1:    0 kWh,
Energy_2:    0 kWh,
Energy_3:    0 kWh,
Energy_4:    0 kWh,
Energy_5:    0 kWh,
Energy_6:    0 kWh,
Energy_7:    0 kWh,
Energy_8:    0 kWh,
Energy_9:    0 kWh,
Energy_10:    0 kWh,
Energy_sum:    0 kWh,
RMS_V:    0.00 V,
Period:    9.53 Hz,
Chip_Temp:    25.3 ^C,
PF:    0.0000 .
>>chip/socket : 4 Info:
RMS_1:    0.00 A,
RMS_2:    0.00 A,
RMS_3:    0.00 A,
RMS_4:    0.00 A,
RMS_5:    0.00 A,
RMS_6:    0.00 A,
RMS_7:    0.00 A,
RMS_8:    0.00 A,
RMS_9:    0.00 A,
RMS_10:    0.00 A,
WATT_1:    0.00 W,
WATT_2:    0.00 W,
WATT_3:    0.00 W,
WATT_4:    0.00 W,
WATT_5:    0.00 W,
WATT_6:    0.00 W,
WATT_7:    0.00 W,
WATT_8:    0.00 W,
WATT_9:    0.00 W,
WATT_10:    0.00 W,
Energy_1:    0 kWh,
Energy_2:    0 kWh,
Energy_3:    0 kWh,
Energy_4:    0 kWh,
Energy_5:    0 kWh,
Energy_6:    0 kWh,
Energy_7:    0 kWh,
Energy_8:    0 kWh,
Energy_9:    0 kWh,
Energy_10:    0 kWh,
Energy_sum:    0 kWh,
RMS_V:    0.00 V,
Period:    9.53 Hz,
Chip_Temp:    23.6 ^C,
PF:    0.0000 .
>>chip/socket : 5 Info:
RMS_1:    0.00 A,
RMS_2:    0.00 A,
RMS_3:    0.00 A,
RMS_4:    0.00 A,
RMS_5:    0.00 A,
RMS_6:    0.00 A,
RMS_7:    0.00 A,
RMS_8:    0.00 A,
RMS_9:    0.00 A,
RMS_10:    0.00 A,
WATT_1:    0.00 W,
WATT_2:    0.00 W,
WATT_3:    0.00 W,
WATT_4:    0.00 W,
WATT_5:    0.00 W,
WATT_6:    0.00 W,
WATT_7:    0.00 W,
WATT_8:    0.00 W,
WATT_9:    0.00 W,
WATT_10:    0.00 W,
Energy_1:    0 kWh,
Energy_2:    0 kWh,
Energy_3:    0 kWh,
Energy_4:    0 kWh,
Energy_5:    0 kWh,
Energy_6:    0 kWh,
Energy_7:    0 kWh,
Energy_8:    0 kWh,
Energy_9:    0 kWh,
Energy_10:    0 kWh,
Energy_sum:    0 kWh,
RMS_V:    0.00 V,
Period:    9.53 Hz,
Chip_Temp:    25.3 ^C,
PF:    0.0000 .
>>chip/socket : 6 Info:
RMS_1:    0.00 A,
RMS_2:    0.00 A,
RMS_3:    0.00 A,
RMS_4:    0.00 A,
RMS_5:    0.00 A,
RMS_6:    0.00 A,
RMS_7:    0.00 A,
RMS_8:    0.00 A,
RMS_9:    0.00 A,
RMS_10:    0.00 A,
WATT_1:    0.00 W,
WATT_2:    1.50 W,
WATT_3:    0.00 W,
WATT_4:    0.00 W,
WATT_5:    0.00 W,
WATT_6:    0.00 W,
WATT_7:    0.00 W,
WATT_8:    0.00 W,
WATT_9:    0.00 W,
WATT_10:    0.00 W,
Energy_1:    0 kWh,
Energy_2:    0 kWh,
Energy_3:    0 kWh,
Energy_4:    0 kWh,
Energy_5:    0 kWh,
Energy_6:    0 kWh,
Energy_7:    0 kWh,
Energy_8:    0 kWh,
Energy_9:    0 kWh,
Energy_10:    0 kWh,
Energy_sum:    0 kWh,
RMS_V:    233.49 V,
Period:    49.71 Hz,
Chip_Temp:    25.7 ^C,
PF:    0.0000 .
>>Data Finished!>>
heartbeat task is running.

Print this item

  [arduino code examples for N60]-04 Print TEXT on SSD1306 OLED displayer
Posted by: admin - 08-03-2025, 03:21 AM - Forum: N60 - 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 IO17
* - SDA (data) on pin IO18
*
* 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,  17, 18, 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   4-oled-ssd1306.zip (Size: 1.11 KB / Downloads: 316)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   4-oled-ssd1306.ino.merged.zip (Size: 202.58 KB / Downloads: 362)

Print this item

  [arduino code examples for N10]-04 Print TEXT on SSD1306 OLED displayer
Posted by: admin - 08-03-2025, 03:21 AM - Forum: N10 - 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 IO17
* - SDA (data) on pin IO18
*
* 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,  17, 18, 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   4-oled-ssd1306.zip (Size: 1.11 KB / Downloads: 320)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   4-oled-ssd1306.ino.merged.zip (Size: 202.58 KB / Downloads: 358)

Print this item

  [arduino code examples for N20]-04 Print TEXT on SSD1306 OLED displayer
Posted by: admin - 08-03-2025, 03:21 AM - Forum: N20 - 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 IO17
* - SDA (data) on pin IO18
*
* 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,  17, 18, 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   4-oled-ssd1306.zip (Size: 1.11 KB / Downloads: 313)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   4-oled-ssd1306.ino.merged.zip (Size: 202.58 KB / Downloads: 340)

Print this item

  [arduino code examples for N30]-04 Print TEXT on SSD1306 OLED displayer
Posted by: admin - 08-03-2025, 03:21 AM - Forum: N30 - 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 IO17
* - SDA (data) on pin IO18
*
* 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,  17, 18, 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   4-oled-ssd1306.zip (Size: 1.11 KB / Downloads: 313)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   4-oled-ssd1306.ino.merged.zip (Size: 202.58 KB / Downloads: 352)

Print this item

  [arduino code examples for N60]-03 Ethernet W5500 chip work with TCP Server mode
Posted by: admin - 08-03-2025, 03:18 AM - Forum: N60 - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* This Arduino program sets up an ESP32-S3 with a W5500 Ethernet module
* as a TCP server. It listens on port 4196 and echoes back any string
* received from a client.
*
* Hardware connections:
* - CLK: GPIO42
* - MOSI: GPIO43
* - MISO: GPIO44
* - CS: GPIO41
* - RST: GPIO1
* - INT: GPIO2
*
* Static IP address: 192.168.3.55
* Subnet Mask: 255.255.255.0
* Gateway: 192.168.3.1
* DNS: 192.168.3.1
*/

#include <SPI.h>
#include <Ethernet.h>

// Define the W5500 Ethernet module pins
#define W5500_CS_PIN  41
#define W5500_RST_PIN 1
#define W5500_INT_PIN 2
#define W5500_CLK_PIN 42
#define W5500_MOSI_PIN 43
#define W5500_MISO_PIN 44

// MAC address for your Ethernet shield (must be unique on your network)
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// Static IP address configuration
IPAddress ip(192, 168, 3, 55);       // Static IP address
IPAddress subnet(255, 255, 255, 0);   // Subnet mask
IPAddress gateway(192, 168, 3, 1);    // Default gateway
IPAddress dns(192, 168, 3, 1);        // DNS server address

// Create an EthernetServer object to handle TCP connections
EthernetServer server(4196);

void setup() {
  // Initialize serial communication
  Serial.begin(115200);
  while (!Serial) {
    ; // Wait for serial port to connect
  }

  // Initialize the W5500 module
  pinMode(W5500_RST_PIN, OUTPUT);
  pinMode(W5500_INT_PIN, INPUT);
  digitalWrite(W5500_RST_PIN, LOW);  // Reset the W5500 module
  delay(100);                       // Wait for reset to complete
  digitalWrite(W5500_RST_PIN, HIGH); // Release reset

  // Initialize SPI with the correct pin definitions
  SPI.begin(W5500_CLK_PIN, W5500_MISO_PIN, W5500_MOSI_PIN);

  // Set up the Ethernet library with W5500-specific pins
  Ethernet.init(W5500_CS_PIN);

  // Start the Ethernet connection with static IP configuration
  Ethernet.begin(mac, ip, dns, gateway, subnet);

  // Print the IP address to the serial monitor
  Serial.print("IP Address: ");
  Serial.println(Ethernet.localIP());

  // Start listening for incoming TCP connections
  server.begin();
}

void loop() {
  // Check for incoming client connections
  EthernetClient client = server.available();
  if (client) {
    Serial.println("New client connected");

    // Read data from the client and echo it back
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        server.write(c);
      }
    }

    // Close the connection when done
    client.stop();
    Serial.println("Client disconnected");
  }
}
arduino ino file download:

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

.zip   3-Ethernet-W5500.ino.merged.zip (Size: 191.07 KB / Downloads: 339)

Print this item

  [arduino code examples for N10]-03 Ethernet W5500 chip work with TCP Server mode
Posted by: admin - 08-03-2025, 03:18 AM - Forum: N10 - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* This Arduino program sets up an ESP32-S3 with a W5500 Ethernet module
* as a TCP server. It listens on port 4196 and echoes back any string
* received from a client.
*
* Hardware connections:
* - CLK: GPIO42
* - MOSI: GPIO43
* - MISO: GPIO44
* - CS: GPIO41
* - RST: GPIO1
* - INT: GPIO2
*
* Static IP address: 192.168.3.55
* Subnet Mask: 255.255.255.0
* Gateway: 192.168.3.1
* DNS: 192.168.3.1
*/

#include <SPI.h>
#include <Ethernet.h>

// Define the W5500 Ethernet module pins
#define W5500_CS_PIN  41
#define W5500_RST_PIN 1
#define W5500_INT_PIN 2
#define W5500_CLK_PIN 42
#define W5500_MOSI_PIN 43
#define W5500_MISO_PIN 44

// MAC address for your Ethernet shield (must be unique on your network)
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// Static IP address configuration
IPAddress ip(192, 168, 3, 55);       // Static IP address
IPAddress subnet(255, 255, 255, 0);   // Subnet mask
IPAddress gateway(192, 168, 3, 1);    // Default gateway
IPAddress dns(192, 168, 3, 1);        // DNS server address

// Create an EthernetServer object to handle TCP connections
EthernetServer server(4196);

void setup() {
  // Initialize serial communication
  Serial.begin(115200);
  while (!Serial) {
    ; // Wait for serial port to connect
  }

  // Initialize the W5500 module
  pinMode(W5500_RST_PIN, OUTPUT);
  pinMode(W5500_INT_PIN, INPUT);
  digitalWrite(W5500_RST_PIN, LOW);  // Reset the W5500 module
  delay(100);                       // Wait for reset to complete
  digitalWrite(W5500_RST_PIN, HIGH); // Release reset

  // Initialize SPI with the correct pin definitions
  SPI.begin(W5500_CLK_PIN, W5500_MISO_PIN, W5500_MOSI_PIN);

  // Set up the Ethernet library with W5500-specific pins
  Ethernet.init(W5500_CS_PIN);

  // Start the Ethernet connection with static IP configuration
  Ethernet.begin(mac, ip, dns, gateway, subnet);

  // Print the IP address to the serial monitor
  Serial.print("IP Address: ");
  Serial.println(Ethernet.localIP());

  // Start listening for incoming TCP connections
  server.begin();
}

void loop() {
  // Check for incoming client connections
  EthernetClient client = server.available();
  if (client) {
    Serial.println("New client connected");

    // Read data from the client and echo it back
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        server.write(c);
      }
    }

    // Close the connection when done
    client.stop();
    Serial.println("Client disconnected");
  }
}
arduino ino file download:

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

.zip   3-Ethernet-W5500.ino.merged.zip (Size: 191.07 KB / Downloads: 353)

Print this item

  [arduino code examples for N20]-03 Ethernet W5500 chip work with TCP Server mode
Posted by: admin - 08-03-2025, 03:18 AM - Forum: N20 - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* This Arduino program sets up an ESP32-S3 with a W5500 Ethernet module
* as a TCP server. It listens on port 4196 and echoes back any string
* received from a client.
*
* Hardware connections:
* - CLK: GPIO42
* - MOSI: GPIO43
* - MISO: GPIO44
* - CS: GPIO41
* - RST: GPIO1
* - INT: GPIO2
*
* Static IP address: 192.168.3.55
* Subnet Mask: 255.255.255.0
* Gateway: 192.168.3.1
* DNS: 192.168.3.1
*/

#include <SPI.h>
#include <Ethernet.h>

// Define the W5500 Ethernet module pins
#define W5500_CS_PIN  41
#define W5500_RST_PIN 1
#define W5500_INT_PIN 2
#define W5500_CLK_PIN 42
#define W5500_MOSI_PIN 43
#define W5500_MISO_PIN 44

// MAC address for your Ethernet shield (must be unique on your network)
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// Static IP address configuration
IPAddress ip(192, 168, 3, 55);       // Static IP address
IPAddress subnet(255, 255, 255, 0);   // Subnet mask
IPAddress gateway(192, 168, 3, 1);    // Default gateway
IPAddress dns(192, 168, 3, 1);        // DNS server address

// Create an EthernetServer object to handle TCP connections
EthernetServer server(4196);

void setup() {
  // Initialize serial communication
  Serial.begin(115200);
  while (!Serial) {
    ; // Wait for serial port to connect
  }

  // Initialize the W5500 module
  pinMode(W5500_RST_PIN, OUTPUT);
  pinMode(W5500_INT_PIN, INPUT);
  digitalWrite(W5500_RST_PIN, LOW);  // Reset the W5500 module
  delay(100);                       // Wait for reset to complete
  digitalWrite(W5500_RST_PIN, HIGH); // Release reset

  // Initialize SPI with the correct pin definitions
  SPI.begin(W5500_CLK_PIN, W5500_MISO_PIN, W5500_MOSI_PIN);

  // Set up the Ethernet library with W5500-specific pins
  Ethernet.init(W5500_CS_PIN);

  // Start the Ethernet connection with static IP configuration
  Ethernet.begin(mac, ip, dns, gateway, subnet);

  // Print the IP address to the serial monitor
  Serial.print("IP Address: ");
  Serial.println(Ethernet.localIP());

  // Start listening for incoming TCP connections
  server.begin();
}

void loop() {
  // Check for incoming client connections
  EthernetClient client = server.available();
  if (client) {
    Serial.println("New client connected");

    // Read data from the client and echo it back
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        server.write(c);
      }
    }

    // Close the connection when done
    client.stop();
    Serial.println("Client disconnected");
  }
}
arduino ino file download:

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

.zip   3-Ethernet-W5500.ino.merged.zip (Size: 191.07 KB / Downloads: 341)

Print this item

  [arduino code examples for N30]-03 Ethernet W5500 chip work with TCP Server mode
Posted by: admin - 08-03-2025, 03:18 AM - Forum: N30 - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* This Arduino program sets up an ESP32-S3 with a W5500 Ethernet module
* as a TCP server. It listens on port 4196 and echoes back any string
* received from a client.
*
* Hardware connections:
* - CLK: GPIO42
* - MOSI: GPIO43
* - MISO: GPIO44
* - CS: GPIO41
* - RST: GPIO1
* - INT: GPIO2
*
* Static IP address: 192.168.3.55
* Subnet Mask: 255.255.255.0
* Gateway: 192.168.3.1
* DNS: 192.168.3.1
*/

#include <SPI.h>
#include <Ethernet.h>

// Define the W5500 Ethernet module pins
#define W5500_CS_PIN  41
#define W5500_RST_PIN 1
#define W5500_INT_PIN 2
#define W5500_CLK_PIN 42
#define W5500_MOSI_PIN 43
#define W5500_MISO_PIN 44

// MAC address for your Ethernet shield (must be unique on your network)
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// Static IP address configuration
IPAddress ip(192, 168, 3, 55);       // Static IP address
IPAddress subnet(255, 255, 255, 0);   // Subnet mask
IPAddress gateway(192, 168, 3, 1);    // Default gateway
IPAddress dns(192, 168, 3, 1);        // DNS server address

// Create an EthernetServer object to handle TCP connections
EthernetServer server(4196);

void setup() {
  // Initialize serial communication
  Serial.begin(115200);
  while (!Serial) {
    ; // Wait for serial port to connect
  }

  // Initialize the W5500 module
  pinMode(W5500_RST_PIN, OUTPUT);
  pinMode(W5500_INT_PIN, INPUT);
  digitalWrite(W5500_RST_PIN, LOW);  // Reset the W5500 module
  delay(100);                       // Wait for reset to complete
  digitalWrite(W5500_RST_PIN, HIGH); // Release reset

  // Initialize SPI with the correct pin definitions
  SPI.begin(W5500_CLK_PIN, W5500_MISO_PIN, W5500_MOSI_PIN);

  // Set up the Ethernet library with W5500-specific pins
  Ethernet.init(W5500_CS_PIN);

  // Start the Ethernet connection with static IP configuration
  Ethernet.begin(mac, ip, dns, gateway, subnet);

  // Print the IP address to the serial monitor
  Serial.print("IP Address: ");
  Serial.println(Ethernet.localIP());

  // Start listening for incoming TCP connections
  server.begin();
}

void loop() {
  // Check for incoming client connections
  EthernetClient client = server.available();
  if (client) {
    Serial.println("New client connected");

    // Read data from the client and echo it back
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        server.write(c);
      }
    }

    // Close the connection when done
    client.stop();
    Serial.println("Client disconnected");
  }
}
arduino ino file download:

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

.zip   3-Ethernet-W5500.ino.merged.zip (Size: 191.07 KB / Downloads: 322)

Print this item

  [arduino code examples for N60]-02 How to use SD Card
Posted by: admin - 08-03-2025, 03:17 AM - Forum: N60 - 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: 335)
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: 315)

Print this item