Sketch too big is a common issue faced inside Arduino IDE while working with BLE. Most of us set up the Arduino IDE for ESP32 and forget to alter any other settings of the IDE because except some situations, we never face this problem. The error will suggest you navigate to this official webpage of Arduino (which is not exactly related to ESP32), which will tell you :
1 2 3 4 5 6 7 | The ATmega168 chip on the Arduino board is cheap, but it has only 16 Kb of program code, which isn't very much (and 2 Kb is used by the bootloader). If you're using floating point, try to rewrite your code with integer math, which should save you about 2 Kb. Delete any #include statements at the top of your sketch for libraries that you're not using. Otherwise, see if you can make your program shorter. We're always working to reduce the size of the Arduino core to leave more room for your sketches. |
I copy-pasted the above text to point you towards writing clean code. When we write our code with integer and use less number of #include statements then it will consume less space.
Steps to Solve ESP32 Sketch Too Big Error
Anyway, solving our present issue is not difficult. On Arduino IDE, navigate to Tools > Partition Scheme. Then select the option “Minimal SPIFFS (Large APPS with OTA)” or “No OTA (Large APP)” option. This way you can have a sketch size up to 1966080 bytes or 2097152 bytes respectively. Doing so you are sacrificing size of SPIFFS or OTA. We are choosing these files :
---
1 | https://github.com/espressif/arduino-esp32/tree/master/tools/partitions |
You need to do another change. Navigate to the directory where you have installed the software for ESP32 (it is in a location like — C:\Users\abhishekghosh\Documents\Arduino\hardware\espressif\esp32
where abhishekghosh
is the user namespace). At the location, you’ll find a text file named “boards”. Open that file. Find the below value :
1 | esp32.upload.maximum_size= |
For dOIT DEVKIT V1 it should look like this:
1 | esp32doit-devkit-v1.upload.maximum_size=1966080 |
Bluetooth is not small to ESP32 from a resource perspective. Combining WiFi with BLE pushes it to the end. But the trick will increase the space which hopefully enough for your work. Here is a small code to print the ESP32 free heap memory :
1 2 3 4 5 6 | void setup() { Serial.begin(115200); Serial.println(ESP.getFreeHeap()); } void loop() {} |
Uploading to ESP32 you’ll get a print on the serial monitor (press the reset button) something like this :
1 2 3 4 5 6 7 8 9 10 11 12 | ets Jun 8, 2016, 00:22:57 rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:1 load:0x3fff0018,len:4 load:0x3fff001c,len:1100 load:0x40078000,len:10208 load:0x40080400,len:6460 entry 0x400806a4 378768 |
We were looking for 378768
.
While uploading the code, you’ll get this info :
1 2 3 | Sketch uses 199620 bytes (10%) of program storage space. Maximum is 1966080 bytes. Global variables use 12976 bytes (3%) of dynamic memory, leaving 314704 bytes for local variables. Maximum is 327680 bytes. ... |
So, you got some space now.
Tagged With writing C code for espssrif/arduino esp32 , esp32 optimize sketch size , ESP32 large sketch , ESP32 increase space , esp32 devkit v1 sketch memory size , esp32 arduino too much void , esp32 arduino program size , esp camera web server sketch too big , esp arduino sketch size , arduino sketch too big