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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 5,364
» Latest member: john2305
» Forum threads: 2,574
» Forum posts: 13,303

Full Statistics

Online Users
There are currently 46 online users.
» 1 Member(s) | 34 Guest(s)
Bing, Bytespider, Crawl, Google, Yandex, bot, engrezk

Latest Threads
Need help with configurat...
Forum: KC868-HxB series Smart Controller
Last Post: admin
1 hour ago
» Replies: 32
» Views: 380
ESP32 S3 set up issue
Forum: Extender module
Last Post: admin
6 hours ago
» Replies: 10
» Views: 57
A32 Pro ESPHome yaml incl...
Forum: KC868-A32/A32 Pro
Last Post: admin
6 hours ago
» Replies: 16
» Views: 175
KC868-A8 Schematic
Forum: KC868-A8
Last Post: admin
6 hours ago
» Replies: 7
» Views: 41
change wake up name
Forum: KinCony AS
Last Post: admin
6 hours ago
» Replies: 11
» Views: 65
"KCS" v2.2.8 firmware BIN...
Forum: "KCS" firmware system
Last Post: admin
6 hours ago
» Replies: 2
» Views: 158
Dimensions/drawings of bo...
Forum: Schematic and diagram
Last Post: admin
6 hours ago
» Replies: 1
» Views: 18
how to use AS ESP32-S3 vo...
Forum: KinCony AS
Last Post: admin
12-16-2024, 10:55 PM
» Replies: 12
» Views: 446
Problem with IFTTT automa...
Forum: "KCS" firmware system
Last Post: admin
12-16-2024, 10:53 PM
» Replies: 5
» Views: 34
M16 SHT31 sensor disconne...
Forum: KC868-M16 / M1 / MB / M30
Last Post: bsarra
12-16-2024, 08:36 PM
» Replies: 4
» Views: 38

  how to use AS ESP32-S3 voice assistant in home assistant
Posted by: admin - 10-22-2024, 01:46 AM - Forum: KinCony AS - Replies (12)

Set Up Voice Assist Pipeline

To set up voice assistant, we would need two components to create the Voice Assist pipeline in Home Assistant.

Whisper: For speech-to-text
Piper: For text-to-speech

1: Whisper Addon
2: Piper Addon
3: And finally the entire Voice Assist pipeline.
   
You don't need to set up the Wake Word addon, as we will use the on-device Wake Word detection with the Micro Wake Word framework
So make sure to watch it and set up the Voice Assist pipeline
   
   
   
ESPHome - add device - create new device called AS:
   
copy and paste KinCony AS yaml file:    

Code:
esphome:
  name: as
  friendly_name: AS
  platformio_options:
    board_build.flash_mode: dio
  on_boot:
    - light.turn_on:
        id: led_ww
        blue: 100%
        brightness: 60%
        effect: fast pulse

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

    sdkconfig_options:
      CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240: "y"
      CONFIG_ESP32S3_DATA_CACHE_64KB: "y"
      CONFIG_ESP32S3_DATA_CACHE_LINE_64B: "y"
      CONFIG_AUDIO_BOARD_CUSTOM: "y"
   
psram:
  mode: octal  # quad for N8R2 and octal for N16R8
  speed: 80MHz


# Enable logging
logger:
  hardware_uart: USB_SERIAL_JTAG

# Enable Home Assistant API
api:
  encryption:
    key: "TFpb+pBAvQIS1MVwaA7EoJ2DkpWE+79UvVro7yMyGdU="
  on_client_connected:
        then:
          - delay: 50ms
          - light.turn_off: led_ww
          - micro_wake_word.start:
  on_client_disconnected:
        then:
          - voice_assistant.stop:



ota:
  - platform: esphome
    password: "1245211a05eef56614a2ef5a3f3e971c"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp32-S3-Wake-Word"
    password: "LJfUrdJk3svP"

captive_portal:


button:
  - platform: restart
    name: "Restart"
    id: but_rest

switch:
  - platform: template
    id: mute
    name: mute
    optimistic: true
    on_turn_on:
      - micro_wake_word.stop:
      - voice_assistant.stop:
      - light.turn_on:
          id: led_ww           
          red: 100%
          green: 0%
          blue: 0%
          brightness: 60%
          effect: fast pulse
      - delay: 2s
      - light.turn_off:
          id: led_ww
      - light.turn_on:
          id: led_ww           
          red: 100%
          green: 0%
          blue: 0%
          brightness: 30%
    on_turn_off:
      - micro_wake_word.start:
      - light.turn_on:
          id: led_ww           
          red: 0%
          green: 100%
          blue: 0%
          brightness: 60%
          effect: fast pulse
      - delay: 2s
      - light.turn_off:
          id: led_ww
   
light:
  - platform: esp32_rmt_led_strip
    id: led_ww
    rgb_order: GRB
    pin: GPIO16
    num_leds: 1
    rmt_channel: 0
    chipset: ws2812
    name: "on board light"
    effects:
      - pulse:
      - pulse:
          name: "Fast Pulse"
          transition_length: 0.5s
          update_interval: 0.5s
          min_brightness: 0%
          max_brightness: 100%
         
         
# Audio and Voice Assistant Config         
i2s_audio:
  - id: i2s_in
    i2s_lrclk_pin: GPIO3  #WS
    i2s_bclk_pin: GPIO2 #SCK
  - id: i2s_speaker
    i2s_lrclk_pin: GPIO6  #LRC
    i2s_bclk_pin: GPIO7 #BLCK

microphone:
  - platform: i2s_audio
    id: va_mic
    adc_type: external
    i2s_din_pin: GPIO4 #SD pin on the INMP441
    channel: left
    pdm: false
    i2s_audio_id: i2s_in
    bits_per_sample: 32 bit
   
speaker:
    platform: i2s_audio
    id: va_speaker
    i2s_audio_id: i2s_speaker
    dac_type: external
    i2s_dout_pin: GPIO8   #  DIN Pin of the MAX98357A Audio Amplifier
    channel: mono

micro_wake_word:
  on_wake_word_detected:
    # then:
    - voice_assistant.start:
        wake_word: !lambda return wake_word;
    - light.turn_on:
        id: led_ww           
        red: 30%
        green: 30%
        blue: 70%
        brightness: 60%
        effect: fast pulse
  models:
    - model: hey_jarvis
   
voice_assistant:
  id: va
  microphone: va_mic
  noise_suppression_level: 2.0
  volume_multiplier: 4.0
  speaker: va_speaker
  on_stt_end:
       then:
         - light.turn_off: led_ww
  on_error:
          - micro_wake_word.start: 
  on_end:
        then:
          - light.turn_off: led_ww
          - wait_until:
              not:
                voice_assistant.is_running:
          - micro_wake_word.start: 
Note: replace wifi router's ssid and password by yourself.
yaml file download from: https://www.kincony.com/forum/showthread.php?tid=6890
now connect AS to your Server16's USB port (raspberry pi or your own server) 
   
click right top windows "install" button, then will show you install way, chose "Plug into the computer running ESPHome Dashboard" item
   
click "USB=JTAG" option that detected.
   
ESPHome begin compile and download firmware:
   
now you will find the AS device discovered on "setting" - "device webpage". Just click "CONFIGURE" button, assign a room to the device.
   
AS is ready. 
   
if you speak "hey jarvis" command, voice assistant will show "listening", then you can say, such as "turn on light", "turn off light". just say the name of your device.

Print this item

  [arduino code examples for AS]-08 how to use WS2812B RGB LED by bottom direction
Posted by: admin - 10-22-2024, 01:30 AM - Forum: KinCony AS - No Replies

Code:
/*
  Made by KinCony IoT: https://www.kincony.com
  This code controls 3 WS2812 RGB LEDs connected to GPIO 15 on an ESP32-S3.
  Each LED will be set to blue with adjustable brightness.
  The Adafruit NeoPixel library is used to communicate with the WS2812 LEDs.

  Hardware setup:
  - WS2812 RGB LEDs are connected to GPIO 15 (data pin).
  - Total number of LEDs: 3.
*/

#include <Adafruit_NeoPixel.h>

// Create an instance of the Adafruit_NeoPixel class
// Parameters: number of LEDs (3), data pin (GPIO 15), LED type (NEO_GRB with 800 KHz communication)
Adafruit_NeoPixel rgb_display = Adafruit_NeoPixel(3, 15, NEO_GRB + NEO_KHZ800);

void setup() {
  // Initialize the NeoPixel library and prepare the LEDs for use
  rgb_display.begin();
}

void loop() {
  /*
    rgb_display.setPixelColor(uint16_t n, uint32_t c);
    This function sets the color of a specific LED.

    Parameters:
    - n: The LED number (starting from 0).
    - c: The color to set the LED to, in hexadecimal (0x0000ff = blue in RGB format).
  */

  // Set the first LED (LED 0) to blue
  rgb_display.setPixelColor(0, (0x0000ff)); // Blue color for the first LED (index 0)
  rgb_display.setBrightness(100);           // Set brightness to 100 out of 255
  rgb_display.show();                       // Update the LED to reflect the change

  // Set the second LED (LED 1) to blue
  rgb_display.setPixelColor(1, (0x0000ff)); // Blue color for the second LED (index 1)
  rgb_display.setBrightness(100);           // Set brightness to 100 out of 255
  rgb_display.show();                       // Update the LED to reflect the change

  // Set the third LED (LED 2) to blue
  rgb_display.setPixelColor(2, (0x0000ff)); // Blue color for the third LED (index 2)
  rgb_display.setBrightness(100);           // Set brightness to 100 out of 255
  rgb_display.show();                       // Update the LED to reflect the change
}
arduino ino file download:
.zip   LED_WS2812B-3pcs.zip (Size: 879 bytes / Downloads: 27)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:
.zip   LED_WS2812B.ino.merged.zip (Size: 177.55 KB / Downloads: 35)
   

Print this item

  [arduino code examples for AS]-07 how to use WS2812B RGB LED by vertical direction
Posted by: admin - 10-22-2024, 01:25 AM - Forum: KinCony AS - No Replies

Code:
/*
  Made by KinCony IoT: https://www.kincony.com
  This code controls 1 WS2812 RGB LEDs connected to GPIO 16 on an ESP32-S3.
  Each LED will be set to blue with adjustable brightness.
  The Adafruit NeoPixel library is used to communicate with the WS2812 LEDs.

  Hardware setup:
  - WS2812 RGB LEDs are connected to GPIO 15 (data pin).
  - Total number of LEDs: 3.
*/

#include <Adafruit_NeoPixel.h>

// Create an instance of the Adafruit_NeoPixel class
// Parameters: number of LEDs (3), data pin (GPIO 15), LED type (NEO_GRB with 800 KHz communication)
Adafruit_NeoPixel rgb_display = Adafruit_NeoPixel(1, 16, NEO_GRB + NEO_KHZ800);

void setup() {
  // Initialize the NeoPixel library and prepare the LEDs for use
  rgb_display.begin();
}

void loop() {
  /*
    rgb_display.setPixelColor(uint16_t n, uint32_t c);
    This function sets the color of a specific LED.

    Parameters:
    - n: The LED number (starting from 0).
    - c: The color to set the LED to, in hexadecimal (0x0000ff = blue in RGB format).
  */

  // Set the first LED (LED 0) to blue
  rgb_display.setPixelColor(0, (0x0000ff)); // Blue color for the first LED (index 0)
  rgb_display.setBrightness(100);           // Set brightness to 100 out of 255
  rgb_display.show();                       // Update the LED to reflect the change

}
arduino ino file download:

.zip   LED_WS2812B-1pc.zip (Size: 834 bytes / Downloads: 28)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:
.zip   LED_WS2812B-1pc.ino.merged.zip (Size: 179.91 KB / Downloads: 32)
   

Print this item

  [arduino code examples for AS]-06 how to play MP3 file by SD Card
Posted by: admin - 10-22-2024, 01:12 AM - Forum: KinCony AS - No Replies

Code:
/*
  ESP32 SD I2S Music Player
  esp32-i2s-sd-player.ino
  Plays MP3 file from microSD card
  Uses MAX98357 I2S Amplifier Module
  Uses ESP32-audioI2S Library - https://github.com/schreibfaul1/ESP32-audioI2S
*/

// Include required libraries
#include "Arduino.h"
#include "Audio.h"
#include "SD.h"
#include "FS.h"

// microSD Card Reader connections
#define SD_CS         13
#define SPI_MOSI      12
#define SPI_MISO      10
#define SPI_SCK       11

// I2S Connections
#define I2S_DOUT      8
#define I2S_BCLK      7
#define I2S_LRC       6

// Create Audio object
Audio audio;

void setup() {
   
    // Set microSD Card CS as OUTPUT and set HIGH
    pinMode(SD_CS, OUTPUT);     
    digitalWrite(SD_CS, HIGH);
   
    // Initialize SPI bus for microSD Card
    SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
   
    // Start Serial Port
    Serial.begin(115200);
   
    // Start microSD Card
    if(!SD.begin(SD_CS))
    {
      Serial.println("Error accessing microSD card!");
      while(true);
    }
   
    // Setup I2S
    audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
   
    // Set Volume
    audio.setVolume(50);
   
    // Open music file
    audio.connecttoFS(SD,"/music.mp3");
   
}

void loop()
{
    audio.loop();   
}
place music.mp3 file on your SD card, make sure SD card is FAT32 format. when board power on, will auto play the MP3 file.
arduino ino file download:
.zip   AS-mp3.zip (Size: 760 bytes / Downloads: 29)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:
.zip   AS-mp3.ino.merged.zip (Size: 878.75 KB / Downloads: 32)
arduino IDE compile setting:    

Print this item

  [arduino code examples for AS]-05 how to use SD Card
Posted by: admin - 10-22-2024, 01:01 AM - Forum: KinCony AS - No Replies

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

#define SCK  11
#define MISO  10
#define MOSI  12
#define CS  13

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();
}

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();
}

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();
}

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");
  }
}

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(){
  Serial.begin(115200);
  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);

  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(){

}
make sure your SC Card is FAT32 format.
arduino ino file download:
.zip   AS-SD.zip (Size: 1.1 KB / Downloads: 30)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:
.zip   AS-SD.ino.merged.zip (Size: 221.37 KB / Downloads: 46)

Print this item

  [arduino code examples for AS]-04 how to output dynamic wave to speaker by MAX98357A
Posted by: admin - 10-22-2024, 12:57 AM - Forum: KinCony AS - No Replies

Code:
/*
  ESP32 I2S Audio Test with Dynamic Frequency and Amplitude
  This code generates a sine wave with changing frequency and amplitude
  to test the MAX98357A amplifier output.
*/

// Include I2S driver
#include <driver/i2s.h>
#include <math.h>

// Connections to MAX98357A amplifier
#define I2S_DOUT  8
#define I2S_BCLK  7
#define I2S_LRC   6

// Use I2S Processor 0
#define I2S_PORT I2S_NUM_0

// Sample rate and initial parameters
const int sampleRate = 44100;
const float baseFrequency = 440.0;  // Base frequency (A4 note)
const int baseAmplitude = 3000;     // Base amplitude
const float frequencyStep = 5.0;    // Frequency change rate
const int amplitudeStep = 50;       // Amplitude change rate

// Variables to control dynamic frequency and amplitude
float currentFrequency = baseFrequency;
int currentAmplitude = baseAmplitude;
int direction = 1;  // To control increase or decrease of frequency and amplitude

void i2s_install() {
  // Set up I2S Processor configuration for TX only
  const i2s_config_t i2s_config = {
    .mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_TX),
    .sample_rate = sampleRate,
    .bits_per_sample = i2s_bits_per_sample_t(16),
    .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
    .communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_STAND_I2S),
    .intr_alloc_flags = 0,
    .dma_buf_count = 8,
    .dma_buf_len = 64,
    .use_apll = false
  };

  i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
}

void i2s_setpin() {
  // Set I2S pin configuration for output (amp)
  const i2s_pin_config_t pin_config = {
    .bck_io_num = I2S_BCLK,
    .ws_io_num = I2S_LRC,
    .data_out_num = I2S_DOUT,
    .data_in_num = I2S_PIN_NO_CHANGE
  };

  i2s_set_pin(I2S_PORT, &pin_config);
}

void setup() {
  // Set up Serial Monitor
  Serial.begin(115200);
  Serial.println("Generating dynamic sine wave on MAX98357A amplifier");

  // Set up I2S
  i2s_install();
  i2s_setpin();
  i2s_start(I2S_PORT);
}

void loop() {
  // Buffer to hold the audio data
  int16_t buffer[64];

  // Generate dynamic sine wave (with changing frequency and amplitude)
  for (int i = 0; i < 64; i++) {
    // Generate sine wave with current frequency and amplitude
    float sample = sinf(2.0f * M_PI * currentFrequency * i / sampleRate);
    buffer[i] = (int16_t)(sample * currentAmplitude);  // Convert float to 16-bit integer
  }

  // Send the buffer to the I2S amplifier
  size_t bytesWritten;
  i2s_write(I2S_PORT, &buffer, sizeof(buffer), &bytesWritten, portMAX_DELAY);

  // Adjust frequency and amplitude for the next loop iteration
  currentFrequency += frequencyStep * direction;
  currentAmplitude += amplitudeStep * direction;

  // Change direction of frequency and amplitude when reaching limits
  if (currentFrequency > 880.0 || currentFrequency < 220.0) {
    direction = -direction;  // Reverse direction when frequency reaches upper or lower limit
  }
  if (currentAmplitude > 5000 || currentAmplitude < 1000) {
    direction = -direction;  // Reverse direction when amplitude reaches upper or lower limit
  }
}
arduino ino file download:
.zip   AS-Speaker-Dynamic-wave.zip (Size: 1.38 KB / Downloads: 36)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:
.zip   AS-Speaker-Dynamic-wave.ino.merged.zip (Size: 192.38 KB / Downloads: 36)

Print this item

  [arduino code examples for AS]-03 how to output simple wave to speaker by MAX98357A
Posted by: admin - 10-22-2024, 12:54 AM - Forum: KinCony AS - No Replies

Code:
/*
  ESP32 I2S Audio Test
  This code generates a simple sine wave to test the MAX98357A amplifier output.
*/

// Include I2S driver
#include <driver/i2s.h>
#include <math.h>

// Connections to MAX98357A amplifier
#define I2S_DOUT  8
#define I2S_BCLK  7
#define I2S_LRC   6

// Use I2S Processor 0
#define I2S_PORT I2S_NUM_0

// Sample rate and wave parameters
const int sampleRate = 44100;
const float frequency = 440.0; // Frequency of the sine wave (A4 note)
const int amplitude = 3000;    // Amplitude of the sine wave

void i2s_install() {
  // Set up I2S Processor configuration for TX only
  const i2s_config_t i2s_config = {
    .mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_TX),
    .sample_rate = sampleRate,
    .bits_per_sample = i2s_bits_per_sample_t(16),
    .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
    .communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_STAND_I2S),
    .intr_alloc_flags = 0,
    .dma_buf_count = 8,
    .dma_buf_len = 64,
    .use_apll = false
  };

  i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
}

void i2s_setpin() {
  // Set I2S pin configuration for output (amp)
  const i2s_pin_config_t pin_config = {
    .bck_io_num = I2S_BCLK,
    .ws_io_num = I2S_LRC,
    .data_out_num = I2S_DOUT,
    .data_in_num = I2S_PIN_NO_CHANGE
  };

  i2s_set_pin(I2S_PORT, &pin_config);
}

void setup() {
  // Set up Serial Monitor
  Serial.begin(115200);
  Serial.println("Generating sine wave on MAX98357A amplifier");

  // Set up I2S
  i2s_install();
  i2s_setpin();
  i2s_start(I2S_PORT);
}

void loop() {
  // Buffer to hold the audio data
  int16_t buffer[64];

  // Generate sine wave and write it to I2S buffer
  for (int i = 0; i < 64; i++) {
    float sample = sinf(2.0f * M_PI * frequency * i / sampleRate);
    buffer[i] = (int16_t)(sample * amplitude); // Convert float to 16-bit integer
  }

  // Send the buffer to the I2S amplifier
  size_t bytesWritten;
  i2s_write(I2S_PORT, &buffer, sizeof(buffer), &bytesWritten, portMAX_DELAY);
}
arduino ino file download:
.zip   AS-Speaker-Simple-wave.zip (Size: 1.09 KB / Downloads: 35)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:
.zip   AS-Speaker-Simple-wave.ino.merged.zip (Size: 192.24 KB / Downloads: 35)

Print this item

  [arduino code examples for AS]-02 how to use INMP441 Microphone
Posted by: admin - 10-22-2024, 12:50 AM - Forum: KinCony AS - No Replies

Code:
/*
  ESP32 I2S Microphone Sample
  esp32-i2s-mic-sample.ino
  Sample sound from I2S microphone, display on Serial Plotter
  Requires INMP441 I2S microphone
*/

// Include I2S driver
#include <driver/i2s.h>

// Connections to INMP441 I2S microphone
#define I2S_WS 3
#define I2S_SD 4
#define I2S_SCK 2

// Use I2S Processor 0
#define I2S_PORT I2S_NUM_0

// Define input buffer length
#define bufferLen 64
int16_t sBuffer[bufferLen];

void i2s_install() {
  // Set up I2S Processor configuration
  const i2s_config_t i2s_config = {
    .mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX),
    .sample_rate = 44100,
    .bits_per_sample = i2s_bits_per_sample_t(16),
    .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
    .communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_STAND_I2S),
    .intr_alloc_flags = 0,
    .dma_buf_count = 8,
    .dma_buf_len = bufferLen,
    .use_apll = false
  };

  i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
}

void i2s_setpin() {
  // Set I2S pin configuration
  const i2s_pin_config_t pin_config = {
    .bck_io_num = I2S_SCK,
    .ws_io_num = I2S_WS,
    .data_out_num = -1,
    .data_in_num = I2S_SD
  };

  i2s_set_pin(I2S_PORT, &pin_config);
}

void setup() {

  // Set up Serial Monitor
  Serial.begin(115200);
  Serial.println(" ");

  delay(1000);

  // Set up I2S
  i2s_install();
  i2s_setpin();
  i2s_start(I2S_PORT);


  delay(500);
}

void loop() {

  // False print statements to "lock range" on serial plotter display
  // Change rangelimit value to adjust "sensitivity"
  int rangelimit = 3000;
  Serial.print(rangelimit * -1);
  Serial.print(" ");
  Serial.print(rangelimit);
  Serial.print(" ");

  // Get I2S data and place in data buffer
  size_t bytesIn = 0;
  esp_err_t result = i2s_read(I2S_PORT, &sBuffer, bufferLen, &bytesIn, portMAX_DELAY);

  if (result == ESP_OK)
  {
    // Read I2S data buffer
    int16_t samples_read = bytesIn / 8;
    if (samples_read > 0) {
      float mean = 0;
      for (int16_t i = 0; i < samples_read; ++i) {
        mean += (sBuffer[i]);
      }

      // Average the data reading
      mean /= samples_read;

      // Print to serial plotter
      Serial.println(mean);
 
    }
  }
}
arduino ino file download:
.zip   INMP441.zip (Size: 1.1 KB / Downloads: 52)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:
.zip   INMP441.ino.merged.zip (Size: 187.09 KB / Downloads: 34)
demo use arduino serial plotter tool to detect microphone sound.
   

Print this item

  [arduino code examples for AS]-01 internet radio
Posted by: admin - 10-22-2024, 12:39 AM - Forum: KinCony AS - No Replies

Code:
/*
  Simple Internet Radio Demo
  esp32-i2s-simple-radio.ino
  Simple ESP32 I2S radio
  Uses MAX98357 I2S Amplifier Module
  Uses ESP32-audioI2S Library - https://github.com/schreibfaul1/ESP32-audioI2S
*/

// Include required libraries
#include "Arduino.h"
#include "WiFi.h"
#include "Audio.h"

// Define I2S connections AS
#define I2S_DOUT  8
#define I2S_BCLK  7
#define I2S_LRC   6

// Create audio object
Audio audio;

// Wifi Credentials
String ssid =    "KinCony";
String password = "a12345678";

void setup() {

  // Start Serial Monitor
  Serial.begin(115200);

  // Setup WiFi in Station mode
  WiFi.disconnect();
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid.c_str(), password.c_str());

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  // WiFi Connected, print IP to serial monitor
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.println("");

  // Connect MAX98357 I2S Amplifier Module
  audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);

  // Set thevolume (0-100)
  audio.setVolume(10);

  // Connect to an Internet radio station (select one as desired)
  audio.connecttohost("http://vis.media-ice.musicradio.com/CapitalMP3");
  //audio.connecttohost("mediaserv30.live-nect MAX98357 I2S Amplifier Module
  //audio.connecttohost("www.surfmusic.de/m3u/100-5-das-hitradio,4529.m3u");
  //audio.connecttohost("stream.1a-webradio.de/deutsch/mp3-128/vtuner-1a");
  //audio.connecttohost("www.antenne.de/webradio/antenne.m3u");
  //audio.connecttohost("0n-80s.radionetz.de:8000/0n-70s.mp3");

}

void loop()

{
  // Run audio player
  audio.loop();

}

// Audio status functions

void audio_info(const char *info) {
  Serial.print("info        "); Serial.println(info);
}
void audio_id3data(const char *info) { //id3 metadata
  Serial.print("id3data     "); Serial.println(info);
}
void audio_eof_mp3(const char *info) { //end of file
  Serial.print("eof_mp3     "); Serial.println(info);
}
void audio_showstation(const char *info) {
  Serial.print("station     "); Serial.println(info);
}
void audio_showstreaminfo(const char *info) {
  Serial.print("streaminfo  "); Serial.println(info);
}
void audio_showstreamtitle(const char *info) {
  Serial.print("streamtitle "); Serial.println(info);
}
void audio_bitrate(const char *info) {
  Serial.print("bitrate     "); Serial.println(info);
}
void audio_commercial(const char *info) { //duration in sec
  Serial.print("commercial  "); Serial.println(info);
}
void audio_icyurl(const char *info) { //homepage
  Serial.print("icyurl      "); Serial.println(info);
}
void audio_lasthost(const char *info) { //stream URL played
  Serial.print("lasthost    "); Serial.println(info);
}
void audio_eof_speech(const char *info) {
  Serial.print("eof_speech  "); Serial.println(info);
}
arduino ino file download:
.zip   internet-radio.zip (Size: 1.15 KB / Downloads: 40)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:
.zip   internet-radio.ino.merged.zip (Size: 849.07 KB / Downloads: 44)
just make sure replace wifi router's ssid and password by yourself.

Print this item

  Server16 raspberry pi
Posted by: Saif Kitany - 10-21-2024, 06:28 PM - Forum: KinCony Server-Mini / Server-16 Raspberry Pi4 relay module - Replies (4)

Hello kincony technical team support ,

I Have H32b controller, my question is like this:

If I purchase server16 raspberry pi iot getway, then can i by node red to control h32b with a diagram that stand on my requirements?

For example:

My h32b is to control electrical windows in my home. So i want for example to open:

1. Window number 1at 5%
2. Window number 2 at 10%
3window number 3 at 100%
.
.
.
Etc…

Print this item