From 0b915b02cc9c7ccea8a53d0ebc99780c6e1c861b Mon Sep 17 00:00:00 2001 From: LILYGO_L <13073925292@163.com> Date: Mon, 4 Mar 2024 17:03:55 +0800 Subject: [PATCH] Update WIFI-AudioI2S Example --- examples/WIFI_Audio_I2S/WIFI_Audio_I2S.cpp | 126 +++++++++++++++++++++ platformio.ini | 5 +- 2 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 examples/WIFI_Audio_I2S/WIFI_Audio_I2S.cpp diff --git a/examples/WIFI_Audio_I2S/WIFI_Audio_I2S.cpp b/examples/WIFI_Audio_I2S/WIFI_Audio_I2S.cpp new file mode 100644 index 0000000..de58acb --- /dev/null +++ b/examples/WIFI_Audio_I2S/WIFI_Audio_I2S.cpp @@ -0,0 +1,126 @@ +/* + * @Description: WIFI_Audio_I2S test + + * @version: V1.0.0 + * @Author: None + * @Date: 2023-06-12 14:27:51 + * @LastEditors: LILYGO_L + * @LastEditTime: 2024-03-04 16:43:25 + * @License: GPL 3.0 + */ +#include +#include "WiFiMulti.h" +#include "Audio.h" +#include "SPI.h" +#include "SD.h" +#include "FS.h" +#include "TFT_eSPI.h" +#include "pin_config.h" + +// IIS 1 +#define PIN_PCM5102A_DIN 43 +#define PIN_PCM5102A_BCLK 44 +#define PIN_PCM5102A_LRCLK 18 +// IIS 2 +// #define PIN_PCM5102A_DIN 11 +// #define PIN_PCM5102A_BCLK 12 +// #define PIN_PCM5102A_LRCLK 13 + +Audio audio; +TFT_eSPI tft; +String ssid = "LilyGo-AABB"; +String password = "xinyuandianzi"; + +void setup() +{ + pinMode(15 /* PWD */, OUTPUT); + digitalWrite(15 /* PWD */, HIGH); + + Serial.begin(115200); + Serial.println("Hello T-Display-S3"); + + tft.begin(); + tft.setRotation(3); + tft.fillScreen(TFT_BLACK); + + ledcAttachPin(TFT_BL, 1); + ledcSetup(1, 2000, 8); + ledcWrite(1, 255); + + WiFi.disconnect(); + WiFi.mode(WIFI_STA); + WiFi.begin(ssid.c_str(), password.c_str()); + delay(2000); + while (WiFi.status() != WL_CONNECTED) + { + Serial.println("WiFi connection failed"); + tft.println("WiFi connection failed"); + delay(1000); + } + + Serial.println("WiFi connection successful"); + tft.println("WiFi connection successful"); + + audio.setPinout(PIN_PCM5102A_BCLK, PIN_PCM5102A_LRCLK, PIN_PCM5102A_DIN); + audio.setVolume(10); // 0...21,Volume setting + // audio.setBalance(-16); + + Serial.println("Trying to play music..."); + tft.println("Trying to play music..."); + + audio.connecttohost("http://music.163.com/song/media/outer/url?id=29747854.mp3"); // MP3 +} + +void loop() +{ + audio.loop(); +} + +// optional +void audio_info(const char *info) +{ + Serial.print("info "); + Serial.println(info); + tft.print("info "); + tft.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_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); +} diff --git a/platformio.ini b/platformio.ini index 0fd2d9a..6a397d8 100644 --- a/platformio.ini +++ b/platformio.ini @@ -11,7 +11,7 @@ [platformio] ; default_envs = Arduino_GFX_PDQgraphicstest -default_envs = Arduino_GFXDemo +; default_envs = Arduino_GFXDemo ; default_envs = factory ; default_envs = lv_demos ; default_envs = nes @@ -27,7 +27,7 @@ default_envs = Arduino_GFXDemo ; default_envs = GetBatteryVoltage ; default_envs = PokerS3 ; default_envs = PCBClock - +default_envs = WIFI_Audio_I2S src_dir = examples/${platformio.default_envs} boards_dir = ./boards @@ -230,5 +230,6 @@ lib_ignore = PCF8575 library PCA95x5 lvgl +[env:WIFI_Audio_I2S]