acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

ESP32_TTGO-TAudio.ino (2494B)

      1 // Copied from https://github.com/LilyGO/TTGO-TAudio/issues/12
      2 
      3 
      4 // Required Libraries (Download zips and add to the Arduino IDE library).
      5 #include "Arduino.h"
      6 #include <WM8978.h> // https://github.com/CelliesProjects/wm8978-esp32
      7 #include <Audio.h>  // https://github.com/schreibfaul1/ESP32-audioI2S
      8 
      9 // T-Audio 1.6 WM8978 I2C pins.
     10 #define I2C_SDA     19
     11 #define I2C_SCL     18
     12 
     13 // T-Audio 1.6 WM8978 I2S pins.
     14 #define I2S_BCK     33
     15 #define I2S_WS      25
     16 #define I2S_DOUT    26
     17 
     18 // T-Audio 1.6 WM8978 MCLK gpio number
     19 #define I2S_MCLKPIN  0
     20 
     21 Audio audio;
     22 WM8978 dac;
     23 
     24 void setup() {
     25     Serial.begin(115200);
     26 
     27   // Setup wm8978 I2C interface.
     28   if (!dac.begin(I2C_SDA, I2C_SCL)) {
     29     ESP_LOGE(TAG, "Error setting up dac: System halted.");
     30     while (1) delay(100);
     31   }
     32 
     33   // Select I2S pins
     34   audio.setPinout(I2S_BCK, I2S_WS, I2S_DOUT);
     35   audio.i2s_mclk_pin_select(I2S_MCLKPIN);
     36 
     37   // WiFi Settings here.
     38   WiFi.begin("EnterSSIDHere", "EnterPasswordHere");
     39   while (!WiFi.isConnected()) {
     40     delay(10);
     41   }
     42   ESP_LOGI(TAG, "Connected. Starting MP3...");
     43   // Enter your Icecast station URL here.
     44   audio.setVolume(21);
     45   audio.connecttohost("http://hestia2.cdnstream.com/1458_128");
     46   // Volume control.
     47   dac.setSPKvol(63); // Change volume here for board speaker output (Max 63).
     48   dac.setHPvol(63, 63); // Change volume here for headphone jack left, right channel.
     49 }
     50 
     51 void loop() {
     52   // Start the stream.
     53   audio.loop();
     54 }
     55 
     56 // optional
     57 void audio_info(const char *info){
     58     Serial.print("info        "); Serial.println(info);
     59 }
     60 void audio_id3data(const char *info){  //id3 metadata
     61     Serial.print("id3data     ");Serial.println(info);
     62 }
     63 void audio_eof_mp3(const char *info){  //end of file
     64     Serial.print("eof_mp3     ");Serial.println(info);
     65 }
     66 void audio_showstation(const char *info){
     67     Serial.print("station     ");Serial.println(info);
     68 }
     69 void audio_showstreamtitle(const char *info){
     70     Serial.print("streamtitle ");Serial.println(info);
     71 }
     72 void audio_bitrate(const char *info){
     73     Serial.print("bitrate     ");Serial.println(info);
     74 }
     75 void audio_commercial(const char *info){  //duration in sec
     76     Serial.print("commercial  ");Serial.println(info);
     77 }
     78 void audio_icyurl(const char *info){  //homepage
     79     Serial.print("icyurl      ");Serial.println(info);
     80 }
     81 void audio_lasthost(const char *info){  //stream URL played
     82     Serial.print("lasthost    ");Serial.println(info);
     83 }
     84 void audio_eof_speech(const char *info){
     85     Serial.print("eof_speech  ");Serial.println(info);
     86 }