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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 5,369
» Latest member: talljane
» Forum threads: 2,574
» Forum posts: 13,305

Full Statistics

Online Users
There are currently 46 online users.
» 1 Member(s) | 33 Guest(s)
Bing, Bytespider, Crawl, Google, PetalBot, bot, robdk

Latest Threads
KC868-A2 ESP32 I/O pin de...
Forum: KC868-A2
Last Post: tugra
3 hours ago
» Replies: 7
» Views: 2,261
change wake up name
Forum: KinCony AS
Last Post: gal
10 hours ago
» Replies: 12
» Views: 78
A32 Pro ESPHome yaml incl...
Forum: KC868-A32/A32 Pro
Last Post: xarouli5
11 hours ago
» Replies: 17
» Views: 181
Need help with configurat...
Forum: KC868-HxB series Smart Controller
Last Post: admin
Today, 04:32 AM
» Replies: 32
» Views: 393
ESP32 S3 set up issue
Forum: Extender module
Last Post: admin
Yesterday, 11:43 PM
» Replies: 10
» Views: 66
KC868-A8 Schematic
Forum: KC868-A8
Last Post: admin
Yesterday, 11:40 PM
» Replies: 7
» Views: 48
"KCS" v2.2.8 firmware BIN...
Forum: "KCS" firmware system
Last Post: admin
Yesterday, 11:38 PM
» Replies: 2
» Views: 172
Dimensions/drawings of bo...
Forum: Schematic and diagram
Last Post: admin
Yesterday, 11:37 PM
» Replies: 1
» Views: 22
how to use AS ESP32-S3 vo...
Forum: KinCony AS
Last Post: admin
12-16-2024, 10:55 PM
» Replies: 12
» Views: 448
Problem with IFTTT automa...
Forum: "KCS" firmware system
Last Post: admin
12-16-2024, 10:53 PM
» Replies: 5
» Views: 34

  how to use ESP32-S3 USB port as common serial port in arduino IDE
Posted by: admin - 04-12-2024, 06:37 AM - Forum: KC868-A32/A32 Pro - No Replies

Code:
void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
Serial.print("Test with KinCony A32B Pro Serail");
}
make sure your setting as these image:
   
   

Print this item

  [Arduino code for KC868-A32 Pro]-03 read / write by RS485
Posted by: admin - 04-12-2024, 06:34 AM - Forum: KC868-A32/A32 Pro - No Replies

Code:
#include <arduino.h>
#include "HardwareSerial.h"
String comdata1,comdata2;
HardwareSerial my485Serial(1);
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  my485Serial.begin(9600,SERIAL_8N1,8,9);///rx:32  tx:33
  Serial.println("UsbSerial say hello");
  my485Serial.println("R485 say hello");
}

void loop() {
  // put your main code here, to run repeatedly:
 
    while (my485Serial.available() > 0) {
      delay(100);
      comdata1 = my485Serial.readString();
      my485Serial.print("R485.readString:");
      my485Serial.println(comdata1);
    }
    while (Serial.available() > 0) {
        delay(100);
      comdata1 = Serial.readString();
      Serial.print("UsbSerial.readString:");
      Serial.println(comdata1);
    }
}
source code download:

.zip   RS485.zip (Size: 475 bytes / Downloads: 83)

Print this item

  [Arduino code for KC868-A32 Pro]-02 read digital input by XL9535
Posted by: admin - 04-12-2024, 06:32 AM - Forum: KC868-A32/A32 Pro - No Replies

Code:
#include <PCA95x5.h>

PCA9555 ioex;

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

    Wire.begin(11,10,40000);
    ioex.attach(Wire,0x24);
    ioex.polarity(PCA95x5::Polarity::ORIGINAL_ALL);
    ioex.direction(PCA95x5::Direction::IN_ALL);
}

void loop() {
    Serial.println(ioex.read(), BIN);
    delay(1000);
}

source code download:

.zip   XL9535_input.zip (Size: 372 bytes / Downloads: 71)
before use XL9535 chip, you need to install PCA95x5 arduino library:
[Image: attachment.php?aid=5044]

Print this item

  [Arduino code for KC868-A32 Pro]-01 Control relay by XL9535
Posted by: admin - 04-12-2024, 06:28 AM - Forum: KC868-A32/A32 Pro - No Replies

Code:
#include <PCA95x5.h>

PCA9555 ioex;

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

    Wire.begin(11,10,100000);
    ioex.attach(Wire,0x21);
    ioex.polarity(PCA95x5::Polarity::ORIGINAL_ALL);
    ioex.direction(PCA95x5::Direction::OUT_ALL);
    ioex.write(PCA95x5::Level::H_ALL);
    delay(2000);
}

void loop() {
    for (size_t i = 0; i < 16; ++i) {
        Serial.print("set port low: ");  //turn ON relay
        Serial.println(i);

        ioex.write((PCA95x5::Port::Port)i, PCA95x5::Level::L);
        Serial.println(ioex.read(), BIN);
        delay(500);
    }

    for (size_t i = 0; i < 16; ++i) {
        Serial.print("set port high: "); //turn OFF relay
        Serial.println(i);

        ioex.write((PCA95x5::Port::Port)i, PCA95x5::Level::H);
        Serial.println(ioex.read(), BIN);
        delay(500);
    }
}
source code download:

.zip   XL9535_output.zip (Size: 492 bytes / Downloads: 87)

before use XL9535 chip, you need to install PCA95x5 arduino library:
   

Print this item

  A32 Pro ESPHome yaml for home assistant
Posted by: admin - 04-12-2024, 06:21 AM - Forum: KC868-A32/A32 Pro - No Replies

   

Code:
esphome:
  name: a32-pro
  friendly_name: a32-Pro
  platformio_options:
    board_build.flash_mode: dio

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: esp-idf

# Enable logging
logger:
  hardware_uart: USB_SERIAL_JTAG

# Enable Home Assistant API
api:

# ota:
#   password: "5f17bccba50c65f60200db69f1b1ebbe"

# wifi:
#   ssid: KinCony
#   password: a12345678

#   # Enable fallback hotspot (captive portal) in case wifi connection fails
#   ap:
#     ssid: "A32-Pro Fallback Hotspot"
#     password: "25JYfblp8QJP"

# captive_portal:

ethernet:
  type: W5500
  clk_pin: GPIO42
  mosi_pin: GPIO44
  miso_pin: GPIO40
  cs_pin: GPIO39
  interrupt_pin: GPIO41
  reset_pin: GPIO43

i2c:
   - id: bus_a
     sda: 11
     scl: 10
     scan: true
     frequency: 400kHz

xl9535:
  - id: xl9535_hub_out1 # for output channel 1-16
    address: 0x21
  - id: xl9535_hub_out2 # for output channel 17-32
    address: 0x22
  - id: xl9535_hub_in1 # for input channel 1-16
    address: 0x24
  - id: xl9535_hub_in2 # for input channel 17-32
    address: 0x25

pcf8574:
  - id: 'pcf8574_in_3'  # for input channel 33-40
    address: 0x23

uart:
  - id: uart_1
    baud_rate: 9600
    debug:
      direction: BOTH
      dummy_receiver: true
      after:
        timeout: 10ms
    tx_pin: 9
    rx_pin: 8

  - id: uart_tuya
    baud_rate: 115200
    debug:
      direction: BOTH
      dummy_receiver: true
      after:
        timeout: 10ms
    tx_pin: 15
    rx_pin: 16

  - id: uart_sim7600
    baud_rate: 115200
    debug:
      direction: BOTH
      dummy_receiver: true
      after:
        timeout: 10ms
      sequence:
        - lambda: UARTDebug::log_string(direction, bytes);
    tx_pin: 18
    rx_pin: 17

switch:

  - platform: gpio
    pin: 45
    name: "LED"

  - platform: uart
    uart_id: uart_1
    name: "RS485 Button"
    data: [0x11, 0x22, 0x33, 0x44, 0x55]

  - platform: uart
    uart_id: uart_sim7600
    name: "UART 4G"
    data: "AT+CGSN\r\n" # read 4G SIM7600 ID

  # - platform: uart
  #   uart_id: uart_tuya
  #   name: "UART TUYA2"
  #   data: [0x55, 0xaa, 0x03, 0x00, 0x00, 0x01, 0x01, 0x04]

  - platform: gpio
    name: A32 Pro Switch01
    pin:
      xl9535: xl9535_hub_out1
      number: 0
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch02
    pin:
      xl9535: xl9535_hub_out1
      number: 1
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch03
    pin:
      xl9535: xl9535_hub_out1
      number: 2
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch04
    pin:
      xl9535: xl9535_hub_out1
      number: 3
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch05
    pin:
      xl9535: xl9535_hub_out1
      number: 4
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch06
    pin:
      xl9535: xl9535_hub_out1
      number: 5
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch07
    pin:
      xl9535: xl9535_hub_out1
      number: 6
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch08
    pin:
      xl9535: xl9535_hub_out1
      number: 7
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch09
    pin:
      xl9535: xl9535_hub_out1
      number: 10
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch10
    pin:
      xl9535: xl9535_hub_out1
      number: 11
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch11
    pin:
      xl9535: xl9535_hub_out1
      number: 12
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch12
    pin:
      xl9535: xl9535_hub_out1
      number: 13
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch13
    pin:
      xl9535: xl9535_hub_out1
      number: 14
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch14
    pin:
      xl9535: xl9535_hub_out1
      number: 15
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch15
    pin:
      xl9535: xl9535_hub_out1
      number: 16
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch16
    pin:
      xl9535: xl9535_hub_out1
      number: 17
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: A32 Pro Switch17
    pin:
      xl9535: xl9535_hub_out2
      number: 0
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch18
    pin:
      xl9535: xl9535_hub_out2
      number: 1
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch19
    pin:
      xl9535: xl9535_hub_out2
      number: 2
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch20
    pin:
      xl9535: xl9535_hub_out2
      number: 3
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch21
    pin:
      xl9535: xl9535_hub_out2
      number: 4
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch22
    pin:
      xl9535: xl9535_hub_out2
      number: 5
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch23
    pin:
      xl9535: xl9535_hub_out2
      number: 6
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch24
    pin:
      xl9535: xl9535_hub_out2
      number: 7
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch25
    pin:
      xl9535: xl9535_hub_out2
      number: 10
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch26
    pin:
      xl9535: xl9535_hub_out2
      number: 11
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch27
    pin:
      xl9535: xl9535_hub_out2
      number: 12
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch28
    pin:
      xl9535: xl9535_hub_out2
      number: 13
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch29
    pin:
      xl9535: xl9535_hub_out2
      number: 14
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch30
    pin:
      xl9535: xl9535_hub_out2
      number: 15
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch31
    pin:
      xl9535: xl9535_hub_out2
      number: 16
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: A32 Pro Switch32
    pin:
      xl9535: xl9535_hub_out2
      number: 17
      mode: OUTPUT
      inverted: true

binary_sensor:
  - platform: gpio
    name: A32 Pro DI01
    pin:
      xl9535: xl9535_hub_in1
      number: 0
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI02
    pin:
      xl9535: xl9535_hub_in1
      number: 1
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI03
    pin:
      xl9535: xl9535_hub_in1
      number: 2
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI04
    pin:
      xl9535: xl9535_hub_in1
      number: 3
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI05
    pin:
      xl9535: xl9535_hub_in1
      number: 4
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI06
    pin:
      xl9535: xl9535_hub_in1
      number: 5
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI07
    pin:
      xl9535: xl9535_hub_in1
      number: 6
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI08
    pin:
      xl9535: xl9535_hub_in1
      number: 7
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI09
    pin:
      xl9535: xl9535_hub_in1
      number: 10
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI10
    pin:
      xl9535: xl9535_hub_in1
      number: 11
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI11
    pin:
      xl9535: xl9535_hub_in1
      number: 12
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI12
    pin:
      xl9535: xl9535_hub_in1
      number: 13
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI13
    pin:
      xl9535: xl9535_hub_in1
      number: 14
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI14
    pin:
      xl9535: xl9535_hub_in1
      number: 15
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI15
    pin:
      xl9535: xl9535_hub_in1
      number: 16
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI16
    pin:
      xl9535: xl9535_hub_in1
      number: 17
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "A32 Pro TMP1"
    pin:
      number: 1
      inverted: true


  - platform: gpio
    name: "A32 Pro TMP2"
    pin:
      number: 2
      inverted: true

  - platform: gpio
    name: "A32 Pro DL"
    pin:
      number: 0
      inverted: true

  - platform: gpio
    name: "A32 Pro DTUYA"
    pin:
      number: 21
      inverted: true

  - platform: gpio
    name: A32 Pro DI17
    pin:
      xl9535: xl9535_hub_in2
      number: 0
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI18
    pin:
      xl9535: xl9535_hub_in2
      number: 1
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI19
    pin:
      xl9535: xl9535_hub_in2
      number: 2
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI20
    pin:
      xl9535: xl9535_hub_in2
      number: 3
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI21
    pin:
      xl9535: xl9535_hub_in2
      number: 4
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI22
    pin:
      xl9535: xl9535_hub_in2
      number: 5
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI23
    pin:
      xl9535: xl9535_hub_in2
      number: 6
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI24
    pin:
      xl9535: xl9535_hub_in2
      number: 7
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI25
    pin:
      xl9535: xl9535_hub_in2
      number: 10
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI26
    pin:
      xl9535: xl9535_hub_in2
      number: 11
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI27
    pin:
      xl9535: xl9535_hub_in2
      number: 12
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI28
    pin:
      xl9535: xl9535_hub_in2
      number: 13
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI29
    pin:
      xl9535: xl9535_hub_in2
      number: 14
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI30
    pin:
      xl9535: xl9535_hub_in2
      number: 15
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI31
    pin:
      xl9535: xl9535_hub_in2
      number: 16
      mode: INPUT
      inverted: true
  - platform: gpio
    name: A32 Pro DI32
    pin:
      xl9535: xl9535_hub_in2
      number: 17
      mode: INPUT
      inverted: true

  - platform: gpio
    name: A32 Pro DI33
    pin:
      pcf8574: pcf8574_in_3
      number: 0
      mode: INPUT
      inverted: true

  - platform: gpio
    name: A32 Pro DI34
    pin:
      pcf8574: pcf8574_in_3
      number: 1
      mode: INPUT
      inverted: true

  - platform: gpio
    name: A32 Pro DI35
    pin:
      pcf8574: pcf8574_in_3
      number: 2
      mode: INPUT
      inverted: true

  - platform: gpio
    name: A32 Pro DI36
    pin:
      pcf8574: pcf8574_in_3
      number: 3
      mode: INPUT
      inverted: true

  - platform: gpio
    name: A32 Pro DI37
    pin:
      pcf8574: pcf8574_in_3
      number: 4
      mode: INPUT
      inverted: true

  - platform: gpio
    name: A32 Pro DI38
    pin:
      pcf8574: pcf8574_in_3
      number: 5
      mode: INPUT
      inverted: true

  - platform: gpio
    name: A32 Pro DI39
    pin:
      pcf8574: pcf8574_in_3
      number: 6
      mode: INPUT
      inverted: true

  - platform: gpio
    name: A32 Pro DI40
    pin:
      pcf8574: pcf8574_in_3
      number: 7
      mode: INPUT
      inverted: true

gp8403:
  id: my_gp8403
  voltage: 10V

output:
  - platform: gp8403
    id: gp8403_output_1
    gp8403_id: my_gp8403
    channel: 0
  - platform: gp8403
    id: gp8403_output_2
    gp8403_id: my_gp8403
    channel: 1

light:
  - platform: monochromatic
    name: "A32 Pro-DAC-0"
    output: gp8403_output_1

  - platform: monochromatic
    name: "A32 Pro-DAC-1"
    output: gp8403_output_2

sensor:
  - platform: adc
    pin: 7
    name: "A32 Pro A1 Voltage"
    update_interval: 5s
    attenuation: 11db
    filters:
      - lambda:
          if (x >= 3.11) {
            return x * 1.60256;
          } else if (x <= 0.15) {
            return 0;
          } else {
            return x * 1.51;
          }
  - platform: adc
    pin: 6
    name: "A32 Pro A2 Voltage"
    update_interval: 5s
    attenuation: 11db
    filters:
      # - multiply: 1.51515
      - lambda:
          if (x >= 3.11) {
            return x * 1.60256;
          } else if (x <= 0.15) {
            return 0;
          } else {
            return x * 1.51;
          }
  - platform: adc
    pin: 5
    name: "A32 Pro A3 Current"
    update_interval: 5s
    unit_of_measurement: mA
    attenuation: 11db
    filters:
      - multiply: 6.66666666
  - platform: adc
    pin: 4
    name: "A32 Pro A4 Current"
    update_interval: 5s
    unit_of_measurement: mA
    attenuation: 11db
    filters:
      - multiply: 6.66666666

web_server:
  port: 80

font:
  - file: "gfonts://Roboto"
    id: roboto
    size: 20

display:
  - platform: ssd1306_i2c
    i2c_id: bus_a
    model: "SSD1306 128x64"
    address: 0x3C
    lambda: |-
      it.printf(0, 0, id(roboto), "A32 Pro");
download yaml:



Attached Files
.txt   A32_Pro-ESPHome.txt (Size: 14.46 KB / Downloads: 287)
Print this item

  A32 Pro ESP32 io pins define
Posted by: admin - 04-12-2024, 06:17 AM - Forum: KC868-A32/A32 Pro - No Replies

#define ANALOG_A1  GPIO7
#define ANALOG_A2  GPIO6
#define ANALOG_A3  GPIO5
#define ANALOG_A4  GPIO4

IIC Bus:

SDA:GPIO11
SCL:GPIO10

XL9535:U57 (relay1-16): address:0x21
XL9535:U60 (relay17-32): address:0x22

XL9535:U58 (input1-16): address:0x24
XL9535:U61 (input17-32): address:0x25

PCF8574:U72(input33-40): address:0x23

GP8403 DAC i2c address: 0x58
SSD1306 display: address:0x3c
-----------------

1-wire:
GPIO1
GPIO2

-----------------

Ethernet (W5500) I/O define:

clk_pin: GPIO42
mosi_pin: GPIO44
miso_pin: GPIO40
cs_pin: GPIO39
interrupt_pin: GPIO41
reset_pin: GPIO43

--------------------
RS485:
RXD:GPIO8
TXD:GPIO9

4G module:
RXD:GPIO17
TXD:GPIO18

Tuya module:
RXD:GPIO16
TXD:GPIO15
--------------------
RF 433M receiver: GPIO38

Print this item

  KinCony ATF (ESP32 SD card module) print information arduino demo code
Posted by: admin - 04-12-2024, 05:32 AM - Forum: Extender module - No Replies

Code:
#include <Arduino.h>
//SD library
#include <SD.h>
#include <FS.h>
#include <SPI.h>
//HSPI or VSPI define
//#define  hspi
#define  vspi
#ifdef vspi
SPIClass sdSPI(VSPI);
#define SD_MISO     19
#define SD_MOSI     23
#define SD_SCLK     18
#define SD_CS       5

#else
SPIClass sdSPI(HSPI);
#define SD_MISO     12
#define SD_MOSI     13
#define SD_SCLK     14
#define SD_CS       15

#endif
void SD_init();

void setup()
{
  Serial.begin(115200);
  delay(500);
#ifdef  hspi
  Serial.println("please insert SD card");
  delay(12000);
#endif
  SD_init();

}

void loop() {
  //print SD card information
  Serial.printf("SD card total size: %lluMB \n", SD.cardSize() / (1024 * 1024));
  Serial.printf("File system whole size: %lluB \n", SD.totalBytes());
  Serial.printf("File system used: %lluB \n", SD.usedBytes());
  delay(5000);
}


void SD_init() {
  //load file system
   sdSPI.begin(SD_SCLK, SD_MISO, SD_MOSI, SD_CS);
  if (!SD.begin(SD_CS, sdSPI))
  {
    // if(!SD.begin()){
    Serial.println("load SD card error");
    return;
  }
  uint8_t cardType = SD.cardType();

  if (cardType == CARD_NONE)
  {
    Serial.println("not connected SD card");
    return;
  }
  else if (cardType == CARD_MMC)
  {
    Serial.println("MMC card");
  }
  else if (cardType == CARD_SD)
  {
    Serial.println("SDSC card");
  }
  else if (cardType == CARD_SDHC)
  {
    Serial.println("SDHC card");
  }
  else
  {
    Serial.println("unknow card");
  }
}
download:

.zip   ATF-SD-Size.zip (Size: 725 bytes / Downloads: 70)

Print this item

  KinCony ATF (ESP32 SD card module) Read/Write arduino demo code
Posted by: admin - 04-12-2024, 05:26 AM - Forum: Extender module - No Replies

Code:
/*
-----------------------------------------------
|  NodeMCU32s            |   SD Card          |
|  --------------------------------------------
|  -                     |   D02              |
|  -                     |   D01              |
|  GPIO23                |   CMD(MOSI)        |
|  GPIO19                |   D00(MISO)        |
|  GPIO18                |   CLK(SCK)         |
|  GPIO5                 |   D03(SS)          |
|  GND                   |   GND              |
|  VCC(3.3v)             |   VCC              |
-----------------------------------------------
*/
#include "FS.h"
#include "SD.h"
#include "SD_MMC.h"

void WriteFile(fs::FS &fs, const char *path, uint8_t *buf, int len)
{
  //unsigned long start_time = millis();
  Serial.printf("write [%s]...\n", path);

  File file = fs.open(path, FILE_WRITE);
  if (!file) {
    Serial.println("Failed to open file for writing");
    return;
  }
 
  if (!file.write(buf, len)) {
      Serial.println("Write failed");
      return;
    }

  file.flush();
  file.close();

  Serial.printf("Write [%s] Complete", path);
}

void ReadFile(fs::FS &fs, const char *path, uint8_t *buf, int len)
{
  Serial.printf("read [%s]...\n", path);

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

  if (!file.read(buf, len)) {
      Serial.println("Read failed");
      return;
  }
 
  file.close();

  Serial.printf("Read [%s] Complete: %s", path, buf);
}

void testIO(fs::FS &fs)
{
  char buf[] = "hello world";

  WriteFile(fs, "/test.txt", (uint8_t *)buf, strlen(buf));
  ReadFile(fs, "/test.txt", (uint8_t *)buf, strlen(buf));
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);

  Serial.println("please insert SD card");
  delay(8000);

  /* SD SPI Mode at VSPI */
  SPIClass spi = SPIClass(HSPI);
  spi.begin(18 /* SCK */, 19 /* MISO */, 23 /* MOSI */, 5 /* SS */);
  if (!SD.begin(5 /* SS */, spi, 80000000)) {
    Serial.println("Card Mount Failed");
    return;
  }
  testIO(SD);
  SD_MMC.end(); // cancel load SD card
}
void loop() {
}
source code download:

.zip   ATF-READ-WRITE.zip (Size: 909 bytes / Downloads: 82)

Print this item

  KinCony ATF (ESP32 SD card module) ESPHome yaml for home assistant
Posted by: admin - 04-12-2024, 05:23 AM - Forum: Extender module - No Replies

   
download yaml:

.txt   ATF-HA.txt (Size: 2.08 KB / Downloads: 81)

Code:
esphome:
  name: atf
  friendly_name: atf

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "w7SHSfiO/jo57FMsWHzLoexB93cf1YmRH7YUVvJuVQ4="

ota:
  password: "122b54ecaa3db2cc9455e008d112a4b6"

wifi:
  ssid: "KinCony"
  password: "a12345678"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Atf Fallback Hotspot"
    password: "dPQX1XykXHPe"

captive_portal:

binary_sensor:
  - platform: gpio
    name: "21"
    pin:
      number: 21
      inverted: true
  - platform: gpio
    name: "22"
    pin:
      number: 22
      inverted: true
  - platform: gpio
    name: "14"
    pin:
      number: 14
      inverted: true
  - platform: gpio
    name: "27"
    pin:
      number: 27
      inverted: true
  - platform: gpio
    name: "13"
    pin:
      number: 13
      inverted: true
  - platform: gpio
    name: "15"
    pin:
      number: 15
      inverted: true
  - platform: gpio
    name: "16"
    pin:
      number: 16
      inverted: true
  - platform: gpio
    name: "4"
    pin:
      number: 4
      inverted: true
  - platform: gpio
    name: "36"
    pin:
      number: 36
      inverted: true
  - platform: gpio
    name: "37"
    pin:
      number: 37
      inverted: true
  - platform: gpio
    name: "38"
    pin:
      number: 38
      inverted: true
  - platform: gpio
    name: "39"
    pin:
      number: 39
      inverted: true
  - platform: gpio
    name: "34"
    pin:
      number: 34
      inverted: true
  - platform: gpio
    name: "35"
    pin:
      number: 35
      inverted: true
  - platform: gpio
    name: "TMP1"
    pin:
      number: 26
      inverted: true
  - platform: gpio
    name: "TMP2"
    pin:
      number: 25
      inverted: true
  - platform: gpio
    name: "32"
    pin:
      number: 32
      inverted: true
  - platform: gpio
    name: "33"
    pin:
      number: 33
      inverted: true
web_server:
  port: 80

Print this item

  KinCony ATF (ESP32 SD card module) pin defines
Posted by: admin - 04-12-2024, 05:21 AM - Forum: Extender module - No Replies

SD Card:

MISO:io19
MOSI:io23
SCLK:io18
CS:io5

--------------
extend serial port:
TXD:io33
RXD:io32

--------------

free GPIOs:
io4
io16
io15
io13
io27
io14
io22
io21
-----------------
only for ADC:
io35
io34
io39
io38
io37
io36
-----------------
1-wire:
TMP1:io26
TMP2:io25

Print this item