Return to Robotics Tutorials

Embedded C GUI for Raspberry PI & Arduino

In developing my custom telemetry robot controller with a touchscreen TFT LCD display, I needed to design a GUI library in C to support menus, buttons, text and images. GUIslice is a lightweight C library intended to work with the Raspberry Pi and Arduino.

GUIslice Touchscreen GUI in C
Custom Telemetry Menu Screen

GUIslice C Library Features

GUIslice provides an open source (free), lightweight platform-independent library that enables embedded GUI menus and displays in C.

  • Processor Hardware Support: This library was intended for use on the Raspberry Pi and Arduino, but also runs on ARM Cortex M0 (Adafruit Feather M0). It can easily be compiled for other targets as well.
  • Display Hardware Support: GUIslice can drive a wide range of displays from 2" TFT LCD displays using a SPI interface (such as PiTFT), parallel, OLED to HDMI. It also supports direct LINUX framebuffer graphics (via SDL1.2). See latest testing for compatibility.
  • Touchscreen Support: To facilitate embedded touchscreen GUI designs, optional support is provided for resistive and capacitive touch devices.
  • Lightweight GUI library:
    • Dependencies for LINUX: SDL 1.2 (optional TTF_Font) or SDL2 -- no need for Python or XWindows / X11!
    • Dependencies for Arduino: Adafruit-GFX, graphics lib (eg. ILI9341) and optional touch lib (eg. STMPE610).
    • Enhancements to support GUI elements in Flash memory for RAM-constained devices such as Arduino (ATmega328)
    • Written in pure C with no dynamic memory allocation within GUIslice
  • Graphic elements: Buttons, Checkboxes, Radio buttons, Text areas, Progress bars, Bitmap images, basic drawing primitives, etc. Both text and image-based buttons are supported. Event mechanism with callbacks. Extensions for custom widget creation.
  • Window paging: Support for multiple display pages and switching between them.
  • Font support: For LINUX: Wide variety of TrueType fonts supported via TTF_Font.
  • Permissive License: GUIslice has been released as open source with the very permissive MIT License. It is free to use for personal or commercial use.

Download GUIslice

The source code is now available in the following GitHub repository:

I gladly welcome any code contributions (pull requests), feedback or suggestions for new features / hardware support!

Screenshots of Embedded GUI applications

Raspberry Pi touchscreen GUI  Touchscreen GUI for Arduino

Examples of GUIslice on Arduino

Please see the GUIslice for Arduino page for more details

Installation of GUIslice on Raspberry Pi

Please see the Installation guide for Raspberry Pi

Latest Updates

The following is a brief summary of features or changes have been made recently to the GUIslice library. For more details, please see the detailed release notes.

  • v0.9: Add radial gauges, scrolling textbox / terminal window, scrolling graph / plot. Add filled triangles, quads. Support for polar coordinate line drawing. Fixed-point LUT emulation for trig functions on Arduino.
  • v0.8.7: Add filled circle primitive. Enhancements to SDL touch & mouse handling.
  • v0.8.6: Touch controls more responsive. Fixes for Beaglebone Black.
  • v0.8.5: Add support for ST7735 (eg. 0.96" OLED 128x64) & SSD1306 (eg. 1.44" SPI 128x128)
  • v0.8.4: Add support for FT6206 (capacitive touch) on Arduino. Add line primitive. Touch axis swap and flip for Arduino. Add detailed config guide.

How to use GUIslice

The GUIslice library includes a number of example programs demonstrating basic functionality as well as more complex drawing callbacks and compound elements. For more details, please refer to the GUIslice wiki.

Example touchscreen C GUI code with Button and Event Loop

The following program displays an image-based button and tracks any touch-presses, highlighting the button while hovering on it. Releasing the button ends the program through a callback.

#include "GUIslice.h"
#include "GUIslice_drv.h"

// Instantiate the GUI
#define MAX_PAGE            1
#define MAX_ELEM_PG_MAIN    5
gslc_tsGui                  m_gui;
gslc_tsDriver               m_drv;
gslc_tsPage                 m_asPage[MAX_PAGE];
gslc_tsElem                 m_asPageElem[MAX_ELEM_PG_MAIN];

bool m_bQuit = false;

// Button callback
bool CbBtnQuit(void* pvGui,void *pvElem,gslc_teTouch eTouch,int16_t nX,int16_t nY)
  if (eTouch == GSLC_TOUCH_UP_IN) {
    m_bQuit = true;
  return true;

int main( int argc, char* args[] )
  gslc_tsElem*  pElem = NULL;

  // Initialize
  // Build the main page
  // Background flat color

  // Create background box
  pElem = gslc_ElemCreateBox(&m_gui,E_ELEM_BOX,E_PG_MAIN,(gslc_tsRect){10,50,300,150});

  // Create Quit button with image label and callback
  pElem = gslc_ElemCreateBtnImg(&m_gui,E_ELEM_BTN_QUIT,E_PG_MAIN,(gslc_tsRect){258,70,32,32},

  // Start up display on main page

  // Main event loop
  m_bQuit = false;
  while (!m_bQuit) {
    // Update GUI

  // Close down display
  return 0;

Example Code

Example code is provided in the GUIslice repository in the following subdirectories:

  • LINUX: /tests/
  • Arduino sketches: /arduino/

Supported Devices

The following CPUs, boards and hardware devices have been tested to work with GUIslice:

  • Processors
  • Displays
    • Adafruit 2.2" 18-bit color TFT LCD with microSD card breakout
    • Adafruit 2.8" TFT Touch shield for Arduino (resistive screen)
    • PiTFT Plus 2.8" TFT 320x240 + Capacitive Touchscreen for Raspberry Pi
    • PiTFT 3.5" TFT 480x320 + Resistive Touchscreen for Raspberry Pi
    • Waveshare 3.5" 320x480 TFT LCD
    • 0.96" SPI 128x64 OLED LCD
    • 1.44" 128x128 SPI TFT LCD
    • Tested soon:
      • 2.4" SPI TFT Serial LCD Touch Panel
      • 1.8" SPI TFT 128x160
  • Graphic driver chips
    • ILI9341 / ILI9340
    • ST7735
    • SSD1306
    • XPT2046 (via SDL)
    • HX8357-D (via SDL)
  • Touch driver chips
    • STMPE610
    • FT6206
    • FT6X06 (via SDL)
    • Tested soon:
      • ADS7843


Reader's Comments:

Please leave your comments or suggestions below!
 Just wanted to leave a thank you too - really nice software kit!
 Thanks, glad it has been useful!

I'm trying to get GUI Slice to work with the RA8875 + Teensy 4.0, but cannot get it to work, possibly due to no support being present for the Teensy 4.0 for GUI Slice yet, is it possible for you to add this support? I would be massively grateful if this is possible.

Kind regards
 Hi -- Can you confirm what display library you are currently using to test the RA8876 with the Teensy 4? For example, are you able to successfully use thanks
 This looks like just what I need for displaying some flight parameters in my airplane! One thing I'd really like to see is a bit of expanded functionality on the bar display to depict custom ranges. That is, perhaps 0-250 could be green, 250-300 yellow, and 300+ red. Also, a line could be drawn to show where the boundary is (such as a red line for max RPM).
 Hi Nate -- thanks! Yes, that's a good suggestion. It should be relatively straightforward to create a variant of the XProgress control with small changes to ElemXProgressDrawHelp() to offer multi-colored ranges and additional markers. I can followup with you via email.
 Thank you so much more making such a useful and time saving tool!

Do you have any plans on adding support for the RA8875 TFT driver chip in the future? Or have any advise for adapting your library to work with it?

Thank you,
 Hi Griffin --

Glad to hear that the library might be useful!
I don't currently have any displays that use the RA8875 controller, so haven't added support for it yet. However, I could probably add it, assuming that you might be interested in testing it out for me. Could you confirm the device you would want to run it on and what touch controller?

Thank you for creating this nice toolkit. I'm using it for OSD purpose. I's easy to generate useful widgets. But since it naturally supports touch input event handling, I wonder if it's easy to add keyboard and mouse input event handling. Because from the source code I see that the callback of a button press is bind to touch event.

 Hi Jiang -- Glad to hear GUIslice has been helpful!
What device are you running GUIslice on? eg. Raspberry Pi with a PiTFT?
I have not done much testing with mouse input but I think it could be adapted to support it in SDL mode (what behavior do you currently see with mouse input?) As for keyboard, I haven't tried binding keypresses to the GUI, but presumably one could create a hotkey for various controls or else enable one to cycle through various controls (using a hover state to show the currently selected item). This could be a bit more involved, so I am inclined to focus on mouse support if there is interest.

Any plans to support the additional fonts that the newest Adafruit GFX library now includes?

 Sounds like a great idea... I'll take a look and determine the best way to integrate the feature into GUIslice.

UPDATE: Support for the enhanced fonts are available in the recent releases of GUIslice!
 I have tried to install SDL on Beaglebone Black. Have you experimented with BBB? I would appreciate your comments on using GUIslice on BBB. Many thanks for your excellent article.
 Hi Kevin! Thanks for your interest in GUIslice. I have sent a private email to see if we can get it working for you.
 Hi, i am interesting your microSDL library.
please send me the link!
Thank you!
 Email sent!
 The library looks awesome! I'm interested in testing it out. Do you mind if I ask for read access?
 Glad to hear it! Email sent
2016-12-10hal pitts
 please send me the link to the microSDL library

thank you
 Email sent!
 Very promising and interesting project according to this article.

I'd really like to taste the implementation of microSDL.

May I look closer?

 Definitely! Private message sent
 I would also like to try this c library to test. I have been playing with Kivy but am a C programmer and all the Pi code I have is in C and would like to have my Gui that I am now trying to incorporate to be in C also.

 Sure! Private email message sent to you with link to repository.
2016-10-22Dick Wilder
 Calvin -
I'd like to beta-test the current version. Please contact me via email.

I'm looking forward to the first release, any estimate of when you will post to github?
 Thanks for the interest! The library is currently available on GitHub for testing. Private message sent with link.

I am interested in your microSDL library. Have you put the source code in the public domain?

D A Uhen
 Hi David! I will be releasing the microSDL library into the public domain shortly -- most likely onto github. I will send you an email update once I have tightened up the code and uploaded it. Thanks for the interest!


Leave a comment or suggestion for this page:

(Never Shown - Optional)