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
  gslc_Init(&m_gui,&m_drv,m_asPage,MAX_PAGE,NULL,0));
  
  // Build the main page
  gslc_PageAdd(&m_gui,E_PG_MAIN,m_asPageElem,MAX_ELEM_PG_MAIN);  
  
  // Background flat color
  gslc_SetBkgndColor(&m_gui,GSLC_COL_GRAY_DK2);

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

  // 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},
          gslc_GetImageFromFile("btn-exit.bmp",GSLC_IMGREF_FMT_BMP16),
          gslc_GetImageFromFile("btn-exit-sel.bmp",GSLC_IMGREF_FMT_BMP16),
          &CbBtnQuit);

  // Start up display on main page
  gslc_SetPageCur(&m_gui,E_PG_MAIN);

  // Main event loop
  m_bQuit = false;
  while (!m_bQuit) {
    // Update GUI
    gslc_Update(&m_gui);
  }

  // Close down display
  gslc_Quit(&m_gui);
  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!
2017-02-14kevin
 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.
2016-12-27park
 Hi, i am interesting your microSDL library.
please send me the link!
Thank you!
 Email sent!
2016-12-10G
 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!
 
2016-12-05ibis
 Very promising and interesting project according to this article.

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

May I look closer?

Thanks.
 Definitely! Private message sent
2016-10-29Keith
 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.

Thanks,
Keith
 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?
Dick
 Thanks for the interest! The library is currently available on GitHub for testing. Private message sent with link.
2016-09-11David
 Calvin,

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

Thanks,
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)
 

Visits!