UDA1334 i2s DAC with ESP32 - sketch too big

Hello everyone. I am trying to implement a web radio streaming device with ESP32 (DEVKITV1 from Aliexpress) and UDA1334A DAC. The problem is that when compiling in the Arduino IDE (2.3.3 nightly) I get the "sketch too big" error:

Sketch uses 1356645 bytes (103%) of program storage space. Maximum is 1310720 bytes.

The sketch from this source Interfacing UDA1334A I2S Stereo Decoder Module with ESP32 is actually garbage, does not even compile. I made it try to compile (with the too big error) by adding the missing "()" in every single function.

The sketch from this source Simple ESP32 Internet Web Radio with OLED Display actually tries to compile (gets the too big error), I even stripped it from the display part to try and save space.

In the Arduino IDE I tried to select both "uPesy ESP32 Wroom DEVkit" and "DO IT ESP32 DEVkit V1" as boards, no difference (still get the "sketch too big" error).

Any ideas as to why a sketch supposedly working (from a tutorial) does not compile?

EDIT: this is the promising code:

#include "Arduino.h"
#include "Audio.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
 
//Digital I/O used  //Makerfabs Audio V2.0
#define I2S_DOUT 27
#define I2S_BCLK 26
#define I2S_LRC 25
 
//SSD1306
#define MAKEPYTHON_ESP32_SDA 4
#define MAKEPYTHON_ESP32_SCL 5
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1    // Reset pin # (or -1 if sharing Arduino reset pin)
 
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
 
//Button
const int Pin_vol_up = 39;
const int Pin_vol_down = 36;
const int Pin_mute = 35;
 
const int Pin_previous = 15;
const int Pin_pause = 33;
const int Pin_next = 2;
 
Audio audio;
 
const char *ssid = "Alexahome";
const char *password = "loranthus";
 
 
struct Music_info
{
    String name;
    int length;
    int runtime;
    int volume;
    int status;
    int mute_volume;
} music_info = {"", 0, 0, 0, 0, 0};
 
int volume = 21;
int mute_volume = 0;
 
int runtime = 0;
int length = 0;
 
String stations[] = {
    "0n-80s.radionetz.de:8000/0n-70s.mp3",
    "mediaserv30.live-streams.nl:8000/stream",
    "www.surfmusic.de/m3u/100-5-das-hitradio,4529.m3u",
    "stream.1a-webradio.de/deutsch/mp3-128/vtuner-1a",
    "mp3.ffh.de/radioffh/hqlivestream.aac", //  128k aac
    "www.antenne.de/webradio/antenne.m3u",
    "listen.rusongs.ru/ru-mp3-128",
    "edge.audio.3qsdn.com/senderkw-mp3",
    "macslons-irish-pub-radio.com/media.asx"};
int station_index = 0;
int station_count = sizeof(stations) / sizeof(stations[0]);
 
void setup()
{
    //IO mode init
    pinMode(Pin_vol_up, INPUT_PULLUP);
    pinMode(Pin_vol_down, INPUT_PULLUP);
    pinMode(Pin_mute, INPUT_PULLUP);
    pinMode(Pin_previous, INPUT_PULLUP);
    pinMode(Pin_pause, INPUT_PULLUP);
    pinMode(Pin_next, INPUT_PULLUP);
 
    //Serial
    Serial.begin(115200);
 
    //LCD
    Wire.begin(MAKEPYTHON_ESP32_SDA, MAKEPYTHON_ESP32_SCL);
    // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
    if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
    { // Address 0x3C for 128x32
        Serial.println(F("SSD1306 allocation failed"));
        for (;;)
            ; // Don't proceed, loop forever
    }
    display.clearDisplay();
    logoshow();
 
    //connect to WiFi
    Serial.printf("Connecting to %s ", ssid);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED)
    {
        delay(500);
        Serial.print(".");
    }
    Serial.println(" CONNECTED");
    lcd_text("Wifi CONNECT");
 
    //Audio(I2S)
    audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
    audio.setVolume(21); // 0...21
 
    open_new_radio(stations[station_index]);
}
 
uint run_time = 0;
uint button_time = 0;
 
void loop()
{
    audio.loop();
    print_song_time();
 
    //Display logic
    if (millis() - run_time > 1000)
    {
        run_time = millis();
        display_music();
    }
 
    //Button logic
    if (millis() - button_time > 300)
    {
        if (digitalRead(Pin_next) == 0)
        {
            Serial.println("Pin_next");
            if (station_index < station_count - 1)
            {
                station_index++;
            }
            else
            {
                station_index = 0;
            }
            button_time = millis();
            open_new_radio(stations[station_index]);
        }
        if (digitalRead(Pin_previous) == 0)
        {
            Serial.println("Pin_previous");
            if (station_index > 0)
            {
                station_index--;
            }
            else
            {
                station_index = station_count - 1;
            }
            button_time = millis();
            open_new_radio(stations[station_index]);
        }
        if (digitalRead(Pin_vol_up) == 0)
        {
            Serial.println("Pin_vol_up");
            if (volume < 21)
                volume++;
            audio.setVolume(volume);
            button_time = millis();
        }
        if (digitalRead(Pin_vol_down) == 0)
        {
            Serial.println("Pin_vol_down");
            if (volume > 0)
                volume--;
            audio.setVolume(volume);
            button_time = millis();
        }
        if (digitalRead(Pin_mute) == 0)
        {
            Serial.println("Pin_mute");
            if (volume != 0)
            {
                mute_volume = volume;
                volume = 0;
            }
            else
            {
                volume = mute_volume;
            }
            audio.setVolume(volume);
            button_time = millis();
        }
        if (digitalRead(Pin_pause) == 0)
        {
            Serial.println("Pin_pause");
            audio.pauseResume();
            button_time = millis();
        }
    }
 
    //Serial logic
    if (Serial.available())
    {
        String r = Serial.readString();
        r.trim();
        if (r.length() > 5)
        {
            audio.stopSong();
            open_new_radio(r);
        }
        else
        {
            audio.setVolume(r.toInt());
        }
    }
}
 
void print_song_time()
{
    runtime = audio.getAudioCurrentTime();
    length = audio.getAudioFileDuration();
}
 
void open_new_radio(String station)
{
    audio.connecttohost(station);
    runtime = audio.getAudioCurrentTime();
    length = audio.getAudioFileDuration();
    Serial.println("**********start a new radio************");
}
 
void display_music()
{
    int line_step = 24;
    int line = 0;
    char buff[20];
    ;
    sprintf(buff, "RunningTime:%d",runtime);
 
    display.clearDisplay();
 
    display.setTextSize(1);              // Normal 1:1 pixel scale
    display.setTextColor(SSD1306_WHITE); // Draw white text
 
    display.setCursor(0, line); // Start at top-left corner
    display.println(stations[station_index]);
    line += line_step * 2;
 
    display.setCursor(0, line);
    display.println(buff);
    line += line_step;
 
    display.display();
}
 
void logoshow(void)
{
    display.clearDisplay();
 
    display.setTextSize(2);              // Normal 1:1 pixel scale
    display.setTextColor(SSD1306_WHITE); // Draw white text
    display.setCursor(0, 0);             // Start at top-left corner
    display.println(F("My ESP32"));
    display.setCursor(0, 20); // Start at top-left corner
    display.println(F("WEB` RADIO"));
    display.setCursor(0, 40); // Start at top-left corner
    display.println(F(""));
    display.display();
    delay(2000);
}
 
void lcd_text(String text)
{
    display.clearDisplay();
 
    display.setTextSize(2);              // Normal 1:1 pixel scale
    display.setTextColor(SSD1306_WHITE); // Draw white text
    display.setCursor(0, 0);             // Start at top-left corner
    display.println(text);
    display.display();
    delay(500);
}
 
//**********************************************
// optional
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);
}
1 Like

Click bait and incompatible libraries.

Click bait - they make a jump-cut video of something unverified "working," post it with unverified code and they get paid for your click.

Libraries - they make a video two versions of library ago, and you try to use the most recent library, things break, and they get paid for your click.

So... post the code that you think is promising... and your detailed wiring diagram... and maybe you can get this thing working.

Perhaps moving some program data into non-program memory can make it not-too-big?

Sturgeon's Law in action, perhaps?

Have you tried changing the partition scheme in the build options to allow for a larger sketch? Assuming that option is available for your board, of course.

Thank you for the reply. How could I go about to move data into non-program memory with Arduino IDE?

Thank you for the reply. If available, where in the Arduino IDE I would go to change build options/ partition scheme?

I was not thinking right. You use the ESP32. I was thinking of Arduino's PROGMEM and F() macro. Not useful with the ESP architecture (it is allowed for code compatibility).

Tools > Partition Scheme, pick one with a larger "APP" size.
The number of options depend on the ESP32 variant you choose.
Leo..

1 Like

Did you manage to solve the problem? I have the same problem, the IDE says the sketch is too big, I'm using the ESP32 Dev Module board

Nope, still not solved

Have you asked the ESP forum? https://esp32.com/