Nope, it’s still crashing
Ima attach the font here:
lv_font_test_16.c (32.0 KB)
and here is the main.cpp as i can’t upload C++ files:
#include <Arduino.h>
#include <lvgl.h>
#include <TFT_eSPI.h>
#define BUF_SIZE (320 * 240 / 10) // Reduced buffer size
TFT_eSPI tft = TFT_eSPI();
static lv_style_t CJK_font;
lv_obj_t *player_lable;
lv_obj_t *title_lable;
lv_obj_t *artist_lable;
static uint8_t buf1[BUF_SIZE];
static uint8_t buf2[BUF_SIZE];
String receivedMessage[6] = {"", "", ""};
String values[6] = {"", "", ""};
int counter = 0;
/* Tick source, tell LVGL how much time (milliseconds) has passed */
static uint32_t get_time(void)
{
return millis(); // Use millis() for Arduino compatibility
}
/* Display flushing */
void my_disp_flush(lv_display_t *disp, const lv_area_t *area, uint8_t *color_p)
{
uint32_t w = (area->x2 - area->x1 + 1);
uint32_t h = (area->y2 - area->y1 + 1);
tft.startWrite();
tft.setAddrWindow(area->x1, area->y1, w, h);
tft.pushColors((uint16_t *)&color_p[0], w * h, true);
tft.endWrite();
lv_display_flush_ready(disp);
}
void setup() {
Serial.begin(115200); // Initialize hardware serial for USB communication
pinMode(2, OUTPUT);
analogWrite(2, 100); // Backlight PWM
lv_init();
// TFT init
tft.init();
tft.setRotation(1); // Adjust rotation as needed
tft.fillScreen(TFT_BLACK);
lv_tick_set_cb(get_time);
lv_display_t * display1 = lv_display_create(320, 240);
lv_display_set_buffers(display1, buf1, buf2, BUF_SIZE, LV_DISPLAY_RENDER_MODE_PARTIAL);
lv_display_set_flush_cb(display1, my_disp_flush);
LV_FONT_DECLARE(lv_font_test_16);
lv_style_init(&CJK_font);
lv_style_set_text_font(&CJK_font, &lv_font_test_16);
//[Player_Name]
player_lable = lv_label_create(lv_scr_act());
lv_label_set_text(player_lable, "Stopped");
lv_obj_align(player_lable, LV_ALIGN_TOP_LEFT, 10, 10);
//[Title]
title_lable = lv_label_create(lv_scr_act());
lv_label_set_text(title_lable, "Fetching");
lv_obj_align(title_lable, LV_ALIGN_TOP_LEFT, 10, 30);
lv_obj_add_style(title_lable, &CJK_font, 0);
//[Artist]
artist_lable = lv_label_create(lv_scr_act());
lv_label_set_text(artist_lable, "Fetching");
lv_obj_align(artist_lable, LV_ALIGN_TOP_LEFT, 10, 50);
lv_obj_add_style(artist_lable, &CJK_font, 0);
while (Serial.available()){
Serial.read();
}
}
void loop() {
while (Serial.available()) { // Check if data is available in the Serial buffer
char incomingChar = Serial.read(); // Read each character
if (incomingChar == '\n') { // If newline character (Enter) is received
receivedMessage[counter] += '\n';
counter++;
if (counter >= 6){
counter = 0;
for (int i = 0; i < 6; i++){
values[i] = receivedMessage[i];
receivedMessage[i] = "";
}
}
} else {
receivedMessage[counter] += incomingChar; // Append characters to the message
}
}
lv_label_set_text(player_lable, values[0].c_str());
lv_label_set_text(title_lable, values[1].c_str());
lv_label_set_text(artist_lable, values[2].c_str());
lv_timer_handler(); // Update the UI
delay(5);
}
Tho im planning to give up on custom font, as I noticed I need to make multiple font files for different font size, and i wanna use CJK fonts, which means most likely i will be short on memory.