Interacting with an OLED and an Accelerometer

This is a tutorial that demonstrates how to use an ADXL335 accelerometer with an SSD1306 (128x64) OLED display to create a simple game.

A ball is displayed on the screen and as we tilt the screen, the ball moves in the corresponding direction.

The OLED uses the JUGL library (Jaycon Universal Graphic Library) which supports the following drivers:

Epaper KS107 PFC8833 SSD1306 (96x16) SSD1306 (128x32) SSD1306 (128x64)

And the following features:

Pixels Lines Rectangles Squares Polygons Circles Triangles Text

You can download the library here:

You can refer to the previous tutorial to see how OLEDs work.

I loaded the libraries and got loads of error messages :-(

Arduino: 1.6.9 (Windows 7), Board: "Arduino/Genuino Uno"

In file included from C:\Users\Arduino\arduino-1.6.9\libraries\JUGL_Core/JUGL.h:29:0,

                 from C:\Users\Arduino\arduino-1.6.9\libraries\JUGL_SSD1306_128x32\examples\Ant\Ant.ino:1:

C:\Users\Arduino\arduino-1.6.9\libraries\JUGL_Core/headers/colors.h:182:25: error: expected '(' before 'packed'

    struct __attribute__(packed) {


C:\Users\Arduino\arduino-1.6.9\libraries\JUGL_Core/headers/colors.h:182:33: error: expected ')' before '{' token

    struct __attribute__(packed) {


C:\Users\Arduino\arduino-1.6.9\libraries\JUGL_Core/headers/colors.h:187:5: error: expected identifier before ';' token



C:\Users\Arduino\arduino-1.6.9\libraries\JUGL_Core/headers/colors.h: In constructor 'JUGL::Color::Color(uint8_t, uint8_t, uint8_t, uint8_t)':

C:\Users\Arduino\arduino-1.6.9\libraries\JUGL_Core/headers/colors.h:192:3: error: class 'JUGL::Color' does not have any field named 'Blue'

   Blue(b), Green(g), Red(r), AlphaFlag(0) {}


C:\Users\Arduino\arduino-1.6.9\libraries\JUGL_Core/headers/colors.h:192:12: error: class 'JUGL::Color' does not have any field named 'Green'

   Blue(b), Green(g), Red(r), AlphaFlag(0) {}


C:\Users\Arduino\arduino-1.6.9\libraries\JUGL_Core/headers/colors.h:192:22: error: class 'JUGL::Color' does not have any field named 'Red'

   Blue(b), Green(g), Red(r), AlphaFlag(0) {}


C:\Users\Arduino\arduino-1.6.9\libraries\JUGL_Core/headers/colors.h:192:30: error: class 'JUGL::Color' does not have any field named 'AlphaFlag'

   Blue(b), Green(g), Red(r), AlphaFlag(0) {}


C:\Users\Arduino\arduino-1.6.9\libraries\JUGL_Core/headers/colors.h: In constructor 'JUGL::Color::Color(JUGL::DefinedColor)':

C:\Users\Arduino\arduino-1.6.9\libraries\JUGL_Core/headers/colors.h:194:39: error: 'AlphaFlag' was not declared in this scope

   Color(DefinedColor dc) {Value = dc; AlphaFlag = 0;}


Using library JUGL_Core in folder: C:\Users\Arduino\arduino-1.6.9\libraries\JUGL_Core (legacy)
Using library SPI at version 1.0 in folder: C:\Users\Arduino\arduino-1.6.9\hardware\arduino\avr\libraries\SPI 
Using library Wire at version 1.0 in folder: C:\Users\Arduino\arduino-1.6.9\hardware\arduino\avr\libraries\Wire 
Using library JUGL_SSD1306_128x32 in folder: C:\Users\Arduino\arduino-1.6.9\libraries\JUGL_SSD1306_128x32 (legacy)
exit status 1
Error compiling for board Arduino/Genuino Uno.

OK, fixed that now I get error:

In file included from C:\Arduino\arduino-1.6.9\libraries\JUGL_Core\default_font.cpp:23:0:

C:\Arduino\arduino-1.6.9\libraries\JUGL_Core\default_font.cpp:30:30: error: variable 'defaultFont' must be const in order to be put into read-only section by means of '__attribute__((progmem))'

 unsigned char  defaultFont[] PROGMEM = {


That is easy to fix too.

OK, now I get error:

C:\Users\Arduino\arduino-1.6.9\libraries\JUGL_Core\default_font.cpp: In member function 'virtual void JUGL::_DefaultFont::SelectChar(char)':

C:\Users\Arduino\arduino-1.6.9\libraries\JUGL_Core\default_font.cpp:294:30: error: invalid conversion from 'const unsigned char*' to 'unsigned char*' [-fpermissive]

   _currentChar = defaultFont + (c*5); // setting the font to the address of the char



OK, fixed that, example is now compiled and running :)

Please make the library compatible with the latest IDE!

This library was tested using Arduino 1.0.5

We will try to work on a new library that is compatible with the latest version of Arduino.

Thank you for your feedback.

1.0.5 is quite old now and no longer supported by the Arduino team.

Only a few very simple changes are needed to get the library to work with later IDEs.

It would be nice to be able to change the I2C address of the display too and redefine the reset pin number for an I2C display without having to hack the library file.

Hi Bodmer

Could show how to fix those compilation problems ?

I want to use this lib too ,



I have deleted my copy of this library...

I suggest you contact, maybe they have fixed the problems now.

OK, Thanks