Home Theater Guide webboard > มุม Thai DIY Audio

ESP32 >>Bluetooth>> I2S ขับ DAC

<< < (2/2)

masterAT:
 :kicking  ภาพตัวอย่าง ผมใช้ ESP32 ตัวที่มีเสาอากาศในตัว เอาสัญญาณ I2S ไปขับ ชุด DAC TDA1541A ครับ


ข้อควรระวัง
1 ใช้ได้กับ ตระกูล ESP32 ธรรมดา นะครับ พวก ESP32 c2 c3 s1 s2 s3 ไม่ support
2 การต่อสาย I2S ต่อสั้นๆ ครับ ยาวไป จะมีเสียง แปลกๆ กวน


รูปล่าง ใช้ ESP-32U มีต่อสายอากาศภายนอกครับ

masterAT:
การโปรแกรม ESP32


 เบื้องต้น ขออนุมาณว่า ทุกท่านพอจะใช้ Arduino IDE กันเป็นแล้วนะครับ
 ก่อนอื่นก็ต้องไปโหลด ไลบลารี่ ของ 2รายการนี้ แล้วมาแตกไพล์ ลงไว้ ใน ไลบรารี่ ของ Arduino IDE
 
 


 1. GitHub - pschatzmann/arduino-audio-tools: Arduino Audio Tools (a powerful Audio library not only for Arduino)
 2. GitHub - pschatzmann/ESP32-A2DP: A Simple ESP32 Bluetooth A2DP Library (to implement a Music Receiver or Sender) that supports Arduino, PlatformIO and Espressif IDF


แล้ว เอาโปรแกรมข่างล่างนี้นี้ไปวาง ใน หน้าโปรแกรมของ Arduino IDE



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

/*
  Streaming Music from Bluetooth
 
  Copyright (C) 2020 Phil Schatzmann
  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


// ==> Example which shows how to use the built in ESP32 I2S >= 3.0.0


#include "ESP_I2S.h"
#include "BluetoothA2DPSink.h"


const uint8_t I2S_SCK = xx;       /* Audio data bit clock */
const uint8_t I2S_WS = yy;       /* Audio data left and right clock */
const uint8_t I2S_SDOUT = zz;    /* ESP32 audio data output (to speakers) */
I2SClass i2s;


BluetoothA2DPSink a2dp_sink(i2s);


void setup() {
    i2s.setPins(I2S_SCK, I2S_WS, I2S_SDOUT);
    if (!i2s.begin(I2S_MODE_STD, 44100, I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO, I2S_STD_SLOT_BOTH)) {
      Serial.println("Failed to initialize I2S!");
      while (1); // do nothing
    }


    a2dp_sink.start("Myname");
}


void loop() {
}

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

โดยมี 4 จุดที่ต้องกำหนดให้ถูกต้องดังต่อไปนี้
เช่นผมต้องการ ให้ ขา GIPO 27 เป็น bck  ก็เอา 27 ไปใส่ใน xx
                      ขา GPIO 26 เป็น ws     ก็เอา 26  ไปใส่ใน yy
                      ขา GPIO 25 เป็น sd     ก็ใส่ 25 ไปใน zz
                      ส่วน Myname ก็เป็นชื่อของ ESP32 นี้ ชื่ออะไร เช่นผมใส่ masterat เวลาเปิดเครื่อง ก็จะเห็นชื่อ ที่เรากำหนด โผล่ขึ้นมาให้เรา connect เข้าไปครับ


                     

masterAT:
ESP32 มีเยอะมากๆ หลากหลายรุ่น แนะนำให้ใช้รุ่น ESP32 Wroom 32U ซึ่งต้องซื้อเสาอากาศ ต่อภายนอกมาต่อเพิ่ม แต่จะได้ประสิทธิภาพ ดีขึ้นมาก


ตามภาพจะเป็นแบบตัวขวามือครับ


หากท่านใดมี ESP32 ตัวอื่นอยู่แล้ว ก็สามารถใช้ได้นะครับ เพียงแต่อาจจะต้องอยู่ไกล้ๆหน่อยถึงจะมองเห็น Bluetooth ครับ

masterAT:

เป้าหมายคือ เรา จะเอา ESP32 มาโปรแกรม ให้สามารถ ส่ง I2S ไปที่ DAC โดยรับสัญญาณ Bluetooth มาจาก PC หรือมือถือ

สิ่งที่ต้องมี
 1 PC ที่ จะโปรแกรม บอร์ด ESP32 และ เป็น PC ที่มี WIFI+Bluetooth ด้วยก็จะดีครับ
 2 บอร์ด ESP32 (ราคาไม่น่าเกิน 200 บาท)

นำร่อง

[0] ดัชนีข้อความ

[*] หน้าที่แล้ว

Go to full version