ESP32 insufficient storage

Hi, i trying to create code for my project that use Bluetooth and WiFi connection in ESP32. But i facing a problem with insufficient storage. What should i do to reduce the size?

This is my code

#include <WiFi.h> 
#include <HTTPClient.h> 
#include <Wire.h>
#include "BluetoothSerial.h"
#include "Adafruit_Thermal.h"

// Bluetooth
BluetoothSerial SerialBT;
Adafruit_Thermal printer(&SerialBT);

// Web Target
String URL = "x";

// Network Configuration
const char* ssid = "x"; // Nama WiFi
const char* password = "x"; // Password WiFi

// Usltrasonik Pin Configuration
#define echoPin 2               // Echo pin for HC-SR04
#define trigPin 4               // Trigger pin for HC-SR04
long duration, distance;

// Thermal printer pin configuration
uint8_t address[6]  = {0x66, 0x32, 0xD5, 0xE0, 0x5D, 0xC1};
char *pin = "0000";
bool connected;

void setup() {
  Serial.begin(115200); 

  //  Ultrasonic
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  // WiFi 
  connectWiFi();

  //  Thermal printer
  SerialBT.setPin(pin);
  SerialBT.begin("ESP32test", true);    // master = true
  Serial.println("The device started in master mode, make sure remote BT device is on!");
  connected = SerialBT.connect(address);
  Serial.print("connected : ");
  Serial.println(connected);
  if(connected) {
    Serial.println("Connected Succesfully!");
  } else {
    while(!SerialBT.connected(5000)) {
      Serial.println("Failed to connect. Make sure remote device is available and in range, then restart app."); 
    }
  }

// disconnect() may take upto 10 secs max
  if (SerialBT.disconnect()) {
    Serial.println("Disconnected Succesfully!");
  }
  // this would reconnect to the name(will use address, if resolved) or address used with connect(name/address).
  SerialBT.connect();

  if(connected){
      Serial.println("Test printer begin");
      printer.begin();        // Init printer (same regardless of serial type)

      // Print centered "Printer OK" 
      printer.justify('C');
      printer.println(F("Printer OK"));
      
      // After printing procedure
      printer.sleep();      // Tell printer to sleep
      delay(3000L);         // Sleep for 3 seconds
      printer.wake();       // MUST wake() before printing again, even if reset
      printer.setDefault(); // Restore printer to defaults
  }
  
}

void loop() {
  // 
  digitalWrite(trigPin, LOW);
  delay(2);
  digitalWrite(trigPin, HIGH);
  delay(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);
  distance = duration / 58.2;

  if(distance < 5){
    // Cek ketersediaan jaringan WiFi
    if(WiFi.status() != WL_CONNECTED) { 
        connectWiFi();
    }

    // Data
    String postData = "distance=" + String(distance); 

    // Konfigurasi HTTP Request
    HTTPClient http; 
    http.begin(URL);
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");

    // HTTP Request dan Simpan hasilnya di variabel  
    int httpCode = http.POST(postData); 
    String payload = http.getString(); 

    // Print hasil request  
    Serial.print("URL : "); Serial.println(URL); 
    Serial.print("Data: "); Serial.println(postData); 
    Serial.print("httpCode: "); Serial.println(httpCode); 
    Serial.print("payload : "); Serial.println(payload); 
    Serial.println("--------------------------------------------------");
   }
  }


    // Function 
    void connectWiFi() {
      WiFi.mode(WIFI_OFF);
      delay(1000);
      //This line hides the viewing of ESP as wifi hotspot
      WiFi.mode(WIFI_STA);
      
      WiFi.begin(ssid, password);
      Serial.println("Menghubungkan ke jaringan WiFi");
      
      while (WiFi.status() != WL_CONNECTED) {
          delay(500);
          Serial.print(".");
      }
          
      Serial.print("Terkoneksi ke jaringan : "); Serial.println(ssid);
      Serial.print("Alamat IP : "); Serial.println(WiFi.localIP());
    }

and this is my error

Arduino: 1.8.19 (Windows 10), Board: "DOIT ESP32 DEVKIT V1, 80MHz, 921600, None" text section exceeds available space in boardSketch uses 1400529 bytes (106%) of program storage space. Maximum is 1310720 bytes. Global variables use 45888 bytes (14%) of dynamic memory, leaving 281792 bytes for local variables. Maximum is 327680 bytes. Error compiling for board DOIT ESP32 DEVKIT V1.

Thank's!

I moved your topic to a more appropriate forum category @rizqifeb.

The Nano ESP32 category you chose is only used for discussions directly related to the Arduino Nano ESP32 board.

In the future, please take the time to pick the forum category that best suits the subject of your question. There is an "About the _____ category" topic at the top of each category that explains its purpose.

Thanks in advance for your cooperation.

1 Like

Which partition scheme have you got selected in the IDE ?

I guess that the character set(s) require much space. Can you remove character sets from the library?

1 Like

@rizqifeb I ran into as similar problem, not too long ago.

The ESP32 DEVKITs generally come with only 4Mb of Flash.
That 4 Mb is partitioned into (With the default partition scheme):

  1. Some small partitions for the ESP32
  2. Program Flash Partition
  3. OTA Partition
  4. SPIFFS Partition

Here is a link to a good video that will explain it a lot beter than I can:
More Memory for the ESP32 without Soldering (How-to adapt partition sizes)

Hope this helps/ answers your question.

Regards

1 Like

have a look at post nrf24lo1-with-esp32

I can't find partition schema in my tools menu
image

I can't find partition schema in my tools menu
image

No for the DOIT devkit it doesn't have it in the esp32 core.

What board do you have exactly (link from vendor please) Since it probably uses an ESP32-WROOM you can most likely use the more generic 'ESP32 Dev Module' with which you can select a partition scheme.

It still will be worth looking into how you used up that much program memory.

Looking at the EPS32 boards.txt file:
c:\Users[USER_NAME]\AppData\Arduino15\packages\esp32\hardware\esp32[ESP32_VERSION]
ESP32_VERSION : I have 3.0.0-rc1 Installed; You might have 1.0.4 or different

The DOIT board does not have the PartitionScheme menu configured.

You could edit the file and copy a PartitionScheme from a board that uses the same ESP32 Module, for example the ESP32-WROOM.

1 Like

I have found the solution by setting the partition scheme. Thank you very much for the helps and advices.

And how did you do that?

In the IDE Tools menu

Setting the board to "ESP32 Dev Module" enabled these tool menu options.
I tested it on :
ESP32 WROOM 32 (DOIT ESP32 Devkit v1 ) and
ESP32 WROOM 32D (ESP32 DevkitC V4).
It is working quite well.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.