This project is a forked version of the Samsung/rlottie project. Therefore, the source code used in this project also follows the original license. For more details, check this out. (https://github.com/Samsung/rlottie/)
Lottie is a JSON-based animation file. Lottie allows designers to move animations as easily as images. It is small in size, works on any device, and can be freely resized without losing resolution.
Lottie has several advantages over other animation file formats:
This rLottie component for an ESP32 project, which is designed to be integrated within the ESP-IDF (Espressif IoT Development Framework) environment. This component allows the rLottie animations to be played on the ESP32 by leveraging the LVGL (Light and Versatile Graphics Library).(https://docs.lvgl.io/master/index.html)
This guide walks you through the process of setting up an ESP32 project with the rLottie component using LVGL, including preparing the display driver.
Setting Up ESP-IDF Environment:
Preparing the Display Driver
Add LVGL component to your project
mkdir components
cd components
git clone https://github.com/lvgl/lvgl.git
Including rLottie Component:
esp_rlottie
component in the components directory of your ESP-IDF project.
git clone https://github.com/0015/esp_rlottie.git
your_project/
├── components/
│ ├── esp_rlottie/
│ │ ├── rlottie/
│ │ │ ├── inc/
│ │ │ ├── src/
│ │ │ ├── CMakeLists.txt
│ │ │ └── ...
│ │ └── CMakeLists.txt
│ ├── lvgl/
│ │ ├── lvgl.h
│ │ ├── env_support/
│ │ │ ├── cmake/
│ │ │ │ ├── esp.cmake
│ │ └── CMakeLists.txt
├── main/
│ ├── main.c
│ └── CMakeLists.txt
├── CMakeLists.txt
└── sdkconfig
Configuration Files
LVGL esp.cmake
Ensure that esp_rlottie
is included in the idf_component_register REQUIRES list in components/lvgl/env_support/cmake/esp.cmake
:
idf_component_register(SRCS ${SOURCES} ${EXAMPLE_SOURCES} ${DEMO_SOURCES}
INCLUDE_DIRS ${LVGL_ROOT_DIR} ${LVGL_ROOT_DIR}/src ${LVGL_ROOT_DIR}/../
${LVGL_ROOT_DIR}/examples ${LVGL_ROOT_DIR}/demos
REQUIRES esp_timer esp_rlottie)
To enable the Lottie library among the LVGL configuration 3rd Party Libraries in sdkconfig
or menuconfig
tool, you'll need to ensure that your project includes the necessary configuration options.
# Enable LVGL
CONFIG_LVGL_ENABLE=y
CONFIG_LVGL_USE_LOTTIE=y
Main Application Code
In your main/main.c
, you need to register lvgl
since esp_rlottie
depends on it:
idf_component_register(
SRCS "main.c"
INCLUDE_DIRS "."
REQUIRES lvgl
)
Here's a simplified main.c
:
#include "lvgl.h"
...
const char battery[] = "Escape string in JSON";
...
void rlottie_display()
{
lv_obj_t *scr = lv_screen_active();
lv_obj_t *lottie = lv_rlottie_create_from_raw(scr, 100, 100, (const char *)battery);
lv_obj_center(lottie);
}
When working with animations and graphics on the ESP32, memory management is critical due to the limited resources available on the microcontroller. The error in multi_heap_internal_lock
typically indicates a memory allocation issue.