What do you want to achieve?
I have successfully gotten lvgl to run on my raspberry pi 5 with the touch screen with the Debian os. The issue is I have to run ROS2 in a docker image and I’d like to just run it natively on the Raspberry Pi.
What have you tried so far?
So I installed Ubuntu on a sd card and put it in the Pi
And for the pi you use the sudo service lightdm stop to turn off the display and then run the lvgl program. I have not had any success though when running the pi on Ubuntu. I found that the command is different it is sudo service gdb3 stop. Running that command I get the ubuntu screen to turn off and I see a black screen with a blinking cursor. However, when I run my lvgl program the screen just stays black. Currently I just have a white screen with a simple button when I run it on the Debian system. Any help with figuring out how to run this on the Raspberry Pi with Ubuntu and the Touch Screen 2 would be greatly appreciated
Code to reproduce
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "lvgl/lvgl.h"
#include "wiringPi.h"
#include "wiringPiSPI.h"
#include <semaphore.h>
#include <sys/ioctl.h>
#include <asm/ioctl.h>
#include <linux/spi/spidev.h>
#include <wiringPiI2C.h>
/* Global Variables */
/* Functions */
void lv_linux_run_loop(void);
void search_handler(lv_event_t *event);
void read_cb(lv_indev_t * indev, lv_indev_data_t*data);
/* TO START PROGRAM ON PI
Run command sudo service lightdm stop
*/
int main(void) {
lv_init();
const char *device = getenv("LV_LINUX_FBDEV_DEVICE") ? : "/dev/fb0";
printf("device %s", device);
lv_display_t * display = lv_linux_fbdev_create();
lv_linux_fbdev_set_file(display, device);
// lv_obj_set_style_bg_color(lv_screen_active(), lv_color_hex(0x000000), LV_PART_MAIN);
// Run libinput list-devices to list devices and find keyboard touch event
/* Touchpad Monitor
Need to add code to search /proc/bus/input/devices for name of event Name="10-0038 generic ft5x06 (79)"
for(int i =0; i < )
*/
lv_indev_t *touch = lv_evdev_create(LV_INDEV_TYPE_POINTER, "/dev/input/event6");
lv_indev_set_display(touch, display);
/* LAYOUT */
lv_obj_t* label;
lv_obj_t *searchButton = lv_button_create(lv_screen_active());
lv_obj_align(searchButton, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_size(searchButton, lv_pct(20), lv_pct(10));
lv_obj_add_event_cb(searchButton, search_handler, LV_EVENT_PRESSED, NULL);
lv_obj_remove_flag(searchButton, LV_OBJ_FLAG_PRESS_LOCK);
lv_obj_add_flag(searchButton, LV_OBJ_FLAG_CLICKABLE);
label = lv_label_create(searchButton);
lv_label_set_text(label, "Search");
lv_obj_center(label);
/* STYLE */
static lv_style_t style;
lv_style_init(&style);
/*Set a background color and a radius*/
lv_style_set_bg_color(&style, lv_color_hex(0x0040DD));
lv_style_set_radius(&style, 25);
/*Add a shadow*/
lv_style_set_shadow_width(&style, 25);
lv_style_set_shadow_spread(&style, 1);
lv_style_set_shadow_color(&style, lv_color_white());
lv_style_set_shadow_offset_x(&style, 0);
lv_style_set_shadow_offset_y(&style, 0);
lv_obj_add_style(searchButton, &style, 0);
lv_linux_run_loop();
return 0;
}
void lv_linux_run_loop(void)
{
uint32_t idle_time;
/*Handle LVGL tasks*/
while(1) {
idle_time = lv_timer_handler(); /*Returns the time to the next timer execution*/
usleep(idle_time * 1000);
}
}
void search_handler(lv_event_t *event) {
lv_event_code_t code = lv_event_get_code(event);
if(code == LV_EVENT_PRESSED) {
LV_LOG_USER("Clicked\n");
printf("Tapped\n");
}
}
Screenshot and/or video
Environment
- MCU/MPU/Board:
Raspberry Pi with the latest Debian OS and Ubuntu 24.4 - LVGL version: See
lv_version.h
LVGL V9.3