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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,122
» Latest member: devidjohans
» Forum threads: 2,791
» Forum posts: 14,671

Full Statistics

Online Users
There are currently 73 online users.
» 3 Member(s) | 46 Guest(s)
Amazonbot, Bing, Bytespider, Crawl, Google, PetalBot, Semrush, Yandex, bot, help@dataminr.com, cofffee124, devidjohans, raheastbay

Latest Threads
Several controllers in on...
Forum: KC868-A6
Last Post: peacemakerv
4 hours ago
» Replies: 2
» Views: 9
"KCS" v2.2.10 firmware BI...
Forum: "KCS" v2 firmware system
Last Post: draugen
5 hours ago
» Replies: 25
» Views: 2,213
Kc868-a32 spi
Forum: KC868-A32/A32 Pro
Last Post: admin
6 hours ago
» Replies: 1
» Views: 7
PROGRAM KC868 A16 DI, DO ...
Forum: KC868-A16
Last Post: admin
6 hours ago
» Replies: 18
» Views: 226
KinCony KC868-A6v3 ESP32-...
Forum: News
Last Post: admin
10 hours ago
» Replies: 0
» Views: 7
KC868, is there some API...
Forum: "KCS" v2 firmware system
Last Post: admin
10 hours ago
» Replies: 1
» Views: 6
Product suggestion: bus b...
Forum: Suggestions and feedback on KinCony's products
Last Post: admin
10 hours ago
» Replies: 7
» Views: 152
http_request on ethernet
Forum: KC868-A series and Uair Smart Controller
Last Post: admin
10 hours ago
» Replies: 3
» Views: 15
THT22 and 5v
Forum: Development
Last Post: admin
10 hours ago
» Replies: 15
» Views: 197
KC868-COL have integrate ...
Forum: News
Last Post: athxp
Yesterday, 08:53 PM
» Replies: 20
» Views: 21,783

  [arduino code examples for A16v3]-09 RF433MHz decode
Posted by: admin - 01-15-2025, 06:08 AM - Forum: KC868-A16v3 - No Replies

Code:
/*
  Simple example for receiving
 
  https://github.com/sui77/rc-switch/
*/

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup() {
  Serial.begin(9600);
  mySwitch.enableReceive(digitalPinToInterrupt(8));
}

void loop() {
  if (mySwitch.available()) {
   
    Serial.print("Received ");
    Serial.print( mySwitch.getReceivedValue() );
    Serial.print(" / ");
    Serial.print( mySwitch.getReceivedBitlength() );
    Serial.print("bit ");
    Serial.print("Protocol: ");
    Serial.println( mySwitch.getReceivedProtocol() );

    mySwitch.resetAvailable();
  }
}
arduino ino file download:
.zip   9-RF433M-decode.zip (Size: 451 bytes / Downloads: 28)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:
.zip   9-RF433M-decode.ino.merged.zip (Size: 181.08 KB / Downloads: 33)

Print this item

  [arduino code examples for A16v3]-08 Ethernet W5500 chip work with TCP Server mode
Posted by: admin - 01-15-2025, 06:06 AM - Forum: KC868-A16v3 - 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  15
#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   8-Ethernet-W5500.zip (Size: 1.23 KB / Downloads: 31)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:
.zip   8-Ethernet-W5500.ino.merged.zip (Size: 188.94 KB / Downloads: 27)

Print this item

  [arduino code examples for A16v3]-07 how to DS3231 RTC clock
Posted by: admin - 01-15-2025, 06:04 AM - Forum: KC868-A16v3 - 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
*    Set date and time command example: D2024-09-19T11:50:22
*    print current date and time command: current time
*
*
* Hardware Connections:
* - SDA: GPIO 9
* - SCL: GPIO 10
*/

#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   9
#define SCL_PIN   10

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.56 KB / Downloads: 33)
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: 191.07 KB / Downloads: 35)

Print this item

  [arduino code examples for A16v3]-06 How to use SD Card
Posted by: admin - 01-15-2025, 06:02 AM - Forum: KC868-A16v3 - 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 13
* - MISO: GPIO 14
* - MOSI: GPIO 12
* - CS: GPIO 11
*/

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

// Pin definitions for SD card
#define SCK  13
#define MISO 14
#define MOSI 12
#define CS   11

/**
* @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: 27)
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: 221.26 KB / Downloads: 26)

Print this item

  [arduino code examples for A16v3]-05 Read free GPIO state
Posted by: admin - 01-15-2025, 06:01 AM - Forum: KC868-A16v3 - No Replies

Code:
/*
  Version: 1.0.0
  Created by KinCony (https://www.kincony.com)
  Description:
    This program monitors the state of selected GPIO pins (47, 48, 38, 39, 40, 41, 0)
    and prints the state of each pin when there is a change (HIGH to LOW or LOW to HIGH).
  Date: 2024-12-24
*/

#include "Arduino.h"

// Define GPIO pins to be monitored as input
const int gpioPins[] = {47, 48, 38, 39, 40, 41, 0};
const int numPins = sizeof(gpioPins) / sizeof(gpioPins[0]);
int lastStates[numPins]; // To store the previous states of each pin

void setup() {
  Serial.begin(115200);  // Initialize serial communication at 115200 baud

  // Set all specified GPIO pins as input
  for (int i = 0; i < numPins; i++) {
    pinMode(gpioPins[i], INPUT);  // Set each GPIO pin to INPUT mode
    lastStates[i] = digitalRead(gpioPins[i]);  // Initialize last state to current state
  }

  Serial.println("GPIO Monitoring Started...");  // Print message to indicate the monitoring has started
}

void loop() {
  // Loop through each pin and check for state change
  for (int i = 0; i < numPins; i++) {
    int currentState = digitalRead(gpioPins[i]);  // Read the current state of the pin

    // If the state has changed (from LOW to HIGH or HIGH to LOW)
    if (currentState != lastStates[i]) {
      // Print the pin number and its new state
      Serial.print("GPIO ");
      Serial.print(gpioPins[i]);
      Serial.print(" changed to: ");
      Serial.println(currentState == HIGH ? "HIGH" : "LOW");

      // Update the last state to the current state
      lastStates[i] = currentState;
    }
  }

  // Add a small delay to reduce the load on the MCU and debounce the inputs
  delay(50);  // Delay for 50 milliseconds
}
arduino ino file download:
.zip   5-free-gpio-state.zip (Size: 956 bytes / Downloads: 34)
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: 179.48 KB / Downloads: 28)

Print this item

  [arduino code examples for A16v3]-04 RS485 communication test
Posted by: admin - 01-15-2025, 05:50 AM - Forum: KC868-A16v3 - 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 18 and RXD pin is defined as GPIO 8.
*/

#include <HardwareSerial.h>

// Define RS485 pins
#define RS485_RXD 17
#define RS485_TXD 16

// 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 IoT");

  // 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: 759 bytes / Downloads: 29)
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: 184.34 KB / Downloads: 32)

Print this item

  [arduino code examples for A16v3]-03 Read analog input ports value
Posted by: admin - 01-15-2025, 05:48 AM - Forum: KC868-A16v3 - No Replies

Code:
#include "Arduino.h"

#define ANALOG_A1   4
#define ANALOG_A2   6
#define ANALOG_A3   7
#define ANALOG_A4   5

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

  pinMode(ANALOG_A1,INPUT);
  pinMode(ANALOG_A2,INPUT);
  pinMode(ANALOG_A3,INPUT);
  pinMode(ANALOG_A4,INPUT);
}

void loop()
{
  delay(1000);
  Serial.printf("Current Reading A1 on Pin(%d)=%d\n",ANALOG_A1,analogRead(ANALOG_A1));
  Serial.printf("Current Reading A2 on Pin(%d)=%d\n",ANALOG_A2,analogRead(ANALOG_A2));
  Serial.printf("Current Reading A3 on Pin(%d)=%d\n",ANALOG_A3,analogRead(ANALOG_A3));
  Serial.printf("Current Reading A4 on Pin(%d)=%d\n",ANALOG_A4,analogRead(ANALOG_A4));
}
arduino ino file download:
.zip   3-analog-input.zip (Size: 415 bytes / Downloads: 41)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:
.zip   3-analog-input.ino.merged.zip (Size: 184.51 KB / Downloads: 34)

Print this item

  [arduino code examples for A16v3]-02 Read digital input ports state
Posted by: admin - 01-15-2025, 05:46 AM - Forum: KC868-A16v3 - No Replies

Code:
/*
KeyPressed on PIN1
by Mischianti Renzo <http://www.mischianti.org>

https://www.mischianti.org/2019/01/02/pcf8574-i2c-digital-i-o-expander-fast-easy-usage/
*/

#include "Arduino.h"
#include "PCF8574.h"

// Set i2c address
PCF8574 pcf8574_1(0x21);
PCF8574 pcf8574_2(0x22);
unsigned long timeElapsed;
void setup()
{
    Wire.begin(9, 10); // SDA: GPIO9, SCL: GPIO10 (for I2C communication)
  Serial.begin(115200);
    delay(1000);

//    pcf8574.pinMode(P0, OUTPUT);
pcf8574_1.pinMode(P0, INPUT);
pcf8574_1.pinMode(P1, INPUT);
pcf8574_1.pinMode(P2, INPUT);
pcf8574_1.pinMode(P3, INPUT);
pcf8574_1.pinMode(P4, INPUT);
pcf8574_1.pinMode(P5, INPUT);
pcf8574_1.pinMode(P6, INPUT);
pcf8574_1.pinMode(P7, INPUT);

pcf8574_2.pinMode(P0, INPUT);
pcf8574_2.pinMode(P1, INPUT);
pcf8574_2.pinMode(P2, INPUT);
pcf8574_2.pinMode(P3, INPUT);
pcf8574_2.pinMode(P4, INPUT);
pcf8574_2.pinMode(P5, INPUT);
pcf8574_2.pinMode(P6, INPUT);
pcf8574_2.pinMode(P7, INPUT);

    Serial.print("Init pcf8574...");
    if (pcf8574_1.begin()){
        Serial.println("pcf8574_1_OK");
    }else{
        Serial.println("pcf8574_1_KO");
    }

  Serial.print("Init pcf8574...");
  if (pcf8574_2.begin()){
    Serial.println("pcf8574_2_OK");
  }else{
    Serial.println("pcf8574_2_KO");
  }


}

void loop()
{
uint8_t val1 = pcf8574_1.digitalRead(P0);
uint8_t val2 = pcf8574_1.digitalRead(P1);
uint8_t val3 = pcf8574_1.digitalRead(P2);
uint8_t val4 = pcf8574_1.digitalRead(P3);
uint8_t val5 = pcf8574_1.digitalRead(P4);
uint8_t val6 = pcf8574_1.digitalRead(P5);
uint8_t val7 = pcf8574_1.digitalRead(P6);
uint8_t val8 = pcf8574_1.digitalRead(P7);

uint8_t val9 = pcf8574_2.digitalRead(P0);
uint8_t val10 = pcf8574_2.digitalRead(P1);
uint8_t val11 = pcf8574_2.digitalRead(P2);
uint8_t val12 = pcf8574_2.digitalRead(P3);
uint8_t val13 = pcf8574_2.digitalRead(P4);
uint8_t val14 = pcf8574_2.digitalRead(P5);
uint8_t val15 = pcf8574_2.digitalRead(P6);
uint8_t val16 = pcf8574_2.digitalRead(P7);
 
if (val1==LOW) Serial.println("KEY1 PRESSED");
if (val2==LOW) Serial.println("KEY2 PRESSED");
if (val3==LOW) Serial.println("KEY3 PRESSED");
if (val4==LOW) Serial.println("KEY4 PRESSED");
if (val5==LOW) Serial.println("KEY5 PRESSED");
if (val6==LOW) Serial.println("KEY6 PRESSED");
if (val7==LOW) Serial.println("KEY7 PRESSED");
if (val8==LOW) Serial.println("KEY8 PRESSED");

if (val9==LOW) Serial.println("KEY9 PRESSED");
if (val10==LOW) Serial.println("KEY10 PRESSED");
if (val11==LOW) Serial.println("KEY11 PRESSED");
if (val12==LOW) Serial.println("KEY12 PRESSED");
if (val13==LOW) Serial.println("KEY13 PRESSED");
if (val14==LOW) Serial.println("KEY14 PRESSED");
if (val15==LOW) Serial.println("KEY15 PRESSED");
if (val16==LOW) Serial.println("KEY16 PRESSED");
    delay(300);
}
arduino ino file download:
.zip   2-digital-input.zip (Size: 870 bytes / Downloads: 28)
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: 191.48 KB / Downloads: 27)

Print this item

  [arduino code examples for A16v3]-01 Turn ON/OFF OUTPUT
Posted by: admin - 01-15-2025, 05:45 AM - Forum: KC868-A16v3 - No Replies

Code:
/*
  Version: 1.0.0
  Created by KinCony (https://www.kincony.com)
  Description:
    This program controls two PCF8574 I/O expanders connected via I2C to create a chase effect
    across 16 output pins (P0-P7 on PCF8574_1 and PCF8574_2).
    The effect consists of sequentially turning on and off LEDs to create a "running light" or "chase" effect.
  Date: 2024-12-24
*/

#include "Arduino.h"
#include "PCF8574.h"

// Set i2c addresses for the two PCF8574 devices
PCF8574 pcf8574_1(0x24);  // PCF8574 at address 0x24
PCF8574 pcf8574_2(0x25);  // PCF8574 at address 0x25

// Setup function, runs once when the program starts
void setup() {
  Wire.begin(9, 10); // SDA: GPIO9, SCL: GPIO10 (for I2C communication)
  Serial.begin(115200); // Start serial communication for debugging

  // Set pinMode to OUTPUT for all 16 pins on both PCF8574 chips
  for (int i = 0; i < 8; i++) {
    pcf8574_1.pinMode(i, OUTPUT);  // Set pins P0-P7 of pcf8574_1 to OUTPUT
    pcf8574_2.pinMode(i, OUTPUT);  // Set pins P0-P7 of pcf8574_2 to OUTPUT
  }

  // Initialize PCF8574_1 and check if it's successful
  Serial.print("Init pcf8574_1...");
  if (pcf8574_1.begin()) {
    Serial.println("PCF8574_1_OK");
  } else {
    Serial.println("PCF8574_1_KO");
  }

  // Initialize PCF8574_2 and check if it's successful
  Serial.print("Init pcf8574_2...");
  if (pcf8574_2.begin()) {
    Serial.println("PCF8574_2_OK");
  } else {
    Serial.println("PCF8574_2_KO");
  }
}

// Loop function, runs repeatedly
void loop() {
  // Create the "chase" effect by turning on one LED at a time

  // First pass: Turn on pins one by one from P0 to P7 on both PCF8574 chips
  for (int i = 0; i < 8; i++) {
    pcf8574_1.digitalWrite(i, HIGH);  // Turn on the LED on pcf8574_1 (pin P0 to P7)
    delay(100);                       // Delay for 100ms to create the "chase" effect
    pcf8574_1.digitalWrite(i, LOW);   // Turn off the LED on pcf8574_1

    // Similarly, turn on LEDs on pcf8574_2 from P0 to P7
    if (i < 8) {
      pcf8574_2.digitalWrite(i, HIGH);  // Turn on the LED on pcf8574_2
      delay(100);                       // Delay for 100ms
      pcf8574_2.digitalWrite(i, LOW);   // Turn off the LED on pcf8574_2
    }
  }

  // Optionally reverse the sequence for a full "chase" effect
  // Second pass: Turn on LEDs in reverse order from P7 to P0
  for (int i = 7; i >= 0; i--) {
    pcf8574_1.digitalWrite(i, HIGH);  // Turn on the LED on pcf8574_1 (pin P7 to P0)
    delay(100);                       // Delay for 100ms
    pcf8574_1.digitalWrite(i, LOW);   // Turn off the LED on pcf8574_1

    // Similarly, reverse the LEDs on pcf8574_2 from P7 to P0
    if (i < 8) {
      pcf8574_2.digitalWrite(i, HIGH);  // Turn on the LED on pcf8574_2
      delay(100);                       // Delay for 100ms
      pcf8574_2.digitalWrite(i, LOW);   // Turn off the LED on pcf8574_2
    }
  }
}
arduino ino file download:
.zip   1-output.zip (Size: 1.06 KB / Downloads: 32)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:
.zip   1-output.ino.merged.zip (Size: 191.2 KB / Downloads: 28)

Print this item

  [arduino code examples for A6v3]-11 SX1278 LoRA wireless receiver and transmitter
Posted by: admin - 01-15-2025, 03:21 AM - Forum: KC868-A6v3 - No Replies

SX1278  Transmitter:

Code:
#include <LoRa.h>
#include <SPI.h>

#define ss 38
#define rst 42
#define dio0 41

int counter = 0;

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  Serial.println("LoRa Sender");

  LoRa.setPins(ss, rst, dio0);    //setup LoRa transceiver module
 
  while (!LoRa.begin(433E6))     //433E6 - Asia, 866E6 - Europe, 915E6 - North America
  {
    Serial.println(".");
    delay(500);
  }
  LoRa.setSyncWord(0xA5);
  Serial.println("LoRa Initializing OK!");
}

void loop()
{
  Serial.print("Sending packet: ");
  Serial.println(counter);

  LoRa.beginPacket();   //Send LoRa packet to receiver
  LoRa.print("hello ");
  LoRa.print(counter);
  LoRa.endPacket();

  counter++;

  delay(2000);
}

SX1278 Receiver:
Code:
#include <LoRa.h>
#include <SPI.h>

#define ss 38
#define rst 42
#define dio0 41

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  Serial.println("LoRa Receiver");

  LoRa.setPins(ss, rst, dio0);    //setup LoRa transceiver module

  while (!LoRa.begin(433E6))     //433E6 - Asia, 866E6 - Europe, 915E6 - North America
  {
    Serial.println(".");
    delay(500);
  }
  LoRa.setSyncWord(0xA5);
  Serial.println("LoRa Initializing OK!");
}

void loop()
{
  int packetSize = LoRa.parsePacket();    // try to parse packet
  if (packetSize)
  {
   
    Serial.print("Received packet '");

    while (LoRa.available())              // read packet
    {
      String LoRaData = LoRa.readString();
      Serial.print(LoRaData);
    }
    Serial.print("' with RSSI ");         // print RSSI of packet
    Serial.println(LoRa.packetRssi());
  }
}

Print this item