The Official Raspberry Pi 7" Touchscreen is very cost effective device which can turn a RaPi into a very sophisticated GUI for all sorts of home projects.

This article is about using the touchscreen as a dedicated interface to home-brew code on a head-less RaPi, that is, a Pi which does not utilise the X-Windows GUI.

After a bit of research I have found a great library which provides elegant user interface objects, it's called LittlevGL and comes free of charge. The library is written in C and designed to work with embedded devices. Here is a link to the library website.

The library comes with pretty good install instructions and it's easy to get the demo graphics to display.

I have followed these steps and added the Makefile from the pc_simulator project on GitHub.

The LCD interface of the screen is connected to the onboard DSI connector and the driver is already part of Raspbian and LittlevGL uses the frame buffer device /dev/fb0 to drive the screen. 
The touch interface is connected to the RaPi via I2C interface but Raspbian provides the hardware level interface and presents the touch events at /dev/input/event0.

The following settings are required in the config files:


#define LV_HOR_RES (800)
#define LV_VER_RES (480)
#define LV_COLOR_DEPTH 24 


#define USE_FBDEV 1
#define FBDEV_PATH "/dev/fb0"
#define USE_EVDEV 1
#define EVDEV_NAME "/dev/input/event0"


#define USE_LV_DEMO 1

This should sufficient to get the screen output working. First with the "Hello World" example and then with the demo_create() function. 
To get touch input working add the following lines after lv_init() in main().

lv_indev_drv_t indev_drv;
indev_drv.type = LV_INDEV_TYPE_POINTER; = evdev_read;

The porting guide provides some information on adding touch input but is missing a couple of very crucial bits of information.

With those modifications the touch screen should now be functional.

One final step is required to eliminate the blinking cursor which keep re-appearing on the screen:

add the following into /boot/cmdline.txt



You have no rights to post comments