Close

Success!

A project log for using uGFX in Arduino

uGFX was written for use with makefiles. Using it in arduino is possible with minimal effort, though. Here's how.

christophChristoph 11/24/2015 at 23:090 Comments


I've successfully created a set of core, display driver, and project config libraries for an SSD1351 OLED display (adafruit's breakout board).

How it works:

I have not yet found a way of getting rid of the config library, but I think that's not too bad.

So let's sum it up!

ugfx-arduino

The wrapper around ugfx, to make the include path and core available.

<sketchbook>/libraries/ugfx-arduino/ugfx-arduino.h:

#ifndef UGFX_ARDUINO_H
#define UGFX_ARDUINO_H

#include <gfx.h>

#endif // UGFX_ARDUINO_H
<sketchbook>/libraries/ugfx-arduino/ugfx-arduino.c:
#include "src/gfx_mk.c"

ugfx-arduino-ssd1351

A driver I adapted from the ugfx sources. I'll not include the code here because it's simply too much, but this is the place where ugfx is told about the driver's features in gdisp_lld_config.h:

<sketchbook>/libraries/ugfx-arduino-ssd1351/
.
├── board_SSD1351.cpp
├── board_SSD1351.h
├── gdisp_lld_config.h
├── gdisp_lld_SSD1351.c
├── SSD1351.h
└── ugfx-arduino-ssd1351.h
The board_ files include hardware specific code, and the initialization and updating logic is in gdisp_lld_SSD1351.c. The code for this driver can be found on github, see links.

teensy3.1-ssd1351-ugfx-config

The config library tailored to our project.
ufxconf.h (ugfx feature selection header):
#ifndef _GFXCONF_H
#define _GFXCONF_H

/* The operating system to use. One of these must be defined - preferably in your Makefile */
//#define GFX_USE_OS_CHIBIOS	FALSE
//#define GFX_USE_OS_WIN32		FALSE
//#define GFX_USE_OS_LINUX		FALSE
//#define GFX_USE_OS_OSX		FALSE
#define GFX_USE_OS_ARDUINO      TRUE
//#define GFX_USE_OS_RAW32 TRUE

/* GFX sub-systems to turn on */
#define GFX_USE_GDISP			TRUE

/* Features for the GDISP sub-system. */
#define GDISP_NEED_VALIDATION	TRUE
#define GDISP_NEED_CLIP			TRUE

#endif /* _GFXCONF_H */
Nothing surprising here if you have already used ugfx.
ugfx-arduino-ssd1351-pins.h:
#ifndef UGFX_ARDUINO_SSD1351_PINS_H
#define UGFX_ARDUINO_SSD1351_PINS_H

#define GPIO_DC    16
#define GPIO_RESET 15
#define GPIO_CS    14

#endif // UGFX_ARDUINO_SSD1351_PINS_H
the driver library needs these three pin defines to work.
teensy3.1-ssd1351-ugfx-config.h:
#ifndef TEENSY31_SSD1351_UGFX_CONFIG_H
#define TEENSY31_SSD1351_UGFX_CONFIG_H

#include <ugfx-arduino.h> // main library
#include <ugfx-arduino-ssd1351.h> // display driver library

#endif // TEENSY31_SSD1351_UGFX_CONFIG_H
so this file just pulls everything into our project.

Sketch

#include <teensy3.1-ssd1351-ugfx-config.h>
#include <SPI.h>

void setup() {
  coord_t    width, height;
  coord_t   i, j;

  SPI.begin();

  // Initialize and clear the display
  gfxInit();

  // Get the screen size
  width = gdispGetWidth();
  height = gdispGetHeight();

  // Code Here
  gdispDrawBox(10, 10, width / 2, height / 2, Yellow);
  gdispFillArea(width / 2, height / 2, width / 2 - 10, height / 2 - 10, Blue);
  gdispDrawLine(5, 30, width - 50, height - 40, Red);

  for (i = 5, j = 0; i < width && j < height; i += 7, j += i / 20)
    gdispDrawPixel(i, j, White);

  SPI.end();
}

void loop() {
}
Code is on github, see link section of this project. It should get you started if you want to make your own driver libs.

Discussions