I’m developing a project where the ESP32 uses an encoder to trigger 2 GPIOs depending on the encoder value. The code works perfectly when compiled in one computer, but behaves slightly different when compiled and uploaded from my laptop.
After some investigation, I found some differences in the upload log output. The package’s versions are different, so the output binaries have different size and simply, does not do the same job.
I had to specify the working versions in my platform.ini file, but I believe it’s weird that old versions of the packages produce a faster and better code than the newer ones.
As an example, this is the memory usage with old libraries (code that works):
RAM: [== ] 20.1% (used 65700 bytes from 327680 bytes)
Flash: [======= ] 65.6% (used 860110 bytes from 1310720 bytes)
And this is the memory usage when using the latest and greatest packages, with a compact code that is not working as expected:
RAM: [== ] 21.0% (used 68808 bytes from 327680 bytes)
Flash: [====== ] 61.5% (used 806085 bytes from 1310720 bytes)
The difference is not big, but there’s something in that compilation that produces a smaller code that works slower!
When you compile your code with the latest Arduino-ESP32 core (2.0.4) in the Arduino IDE, does it also behave slower than when you install e.g. 1.0.6 in the board manager? If yes → issue to Issues · espressif/arduino-esp32 · GitHub
Here you have more detailed information, the versions I have installed are 1.0.6 and 2.0.1. I will try the latest version too and check how it behaves.
This is the output of the working/fast version:
PLATFORM: Espressif 32 (3.5.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
- framework-arduinoespressif32 @ 3.10006.210326 (1.0.6)
- tool-esptoolpy @ 1.30100.210531 (3.1.0)
- tool-mkspiffs @ 2.230.0 (2.30)
- toolchain-xtensa32 @ 2.50200.97 (5.2.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 33 compatible libraries
Scanning dependencies...
Dependency Graph
|-- lvgl @ 8.3.1
| |-- ESP32 BLE Arduino @ 1.0.1
|-- LovyanGFX @ 0.4.18
| |-- SPI @ 1.0
| |-- Wire @ 1.0.1
|-- ESP32Encoder @ 0.9.2
|-- Utilities @ 0.4.6
|-- Preferences @ 1.0
Building in release mode
Retrieving maximum program size .pio\build\esp32dev\firmware.elf
Checking size .pio\build\esp32dev\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [== ] 20.1% (used 65700 bytes from 327680 bytes)
Flash: [======= ] 65.6% (used 860222 bytes from 1310720 bytes)
And this the ouput of the slow/non working version:
Tested with the latest & greatest. Does not wrk as expected. Is missing encoder pulses and missing triggers.
The code is more compact, but somehow, is slower than the one that produces old versions.