การโปรแกรม 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 เข้าไปครับ