Library for drawing on the Hexiwear's OLED - more features being actively worked on

Dependents:   Hexidraw_Demo Hexiwear-FinalProject_v2

API

The API for Hexidraw is made to be simple, with easy to remember function names.

Checkout the official Hexiwear repository for more Hexiwear libraries:

Hexiwear team to share code, project ideas, trick and tips

Turning on the OLED

include the header file:

#include "hexidraw.h"

Create a new instance of the OLED class:

OLED oled;

And then setup the display, and turn it on:

oled.begin();
oled.wake();
oled.clear(WHITE);

wake() and sleep()

The wake() and sleep() functions disable and enable power saving mode on the OLED, which turns on and off the display while retaining the display buffer. It is recommended to turn off the display (sleep()) after a timeout so as to save battery power.

Using colors

You can use the function Color565(r,g,b) which was ported from the Adafruit GFX library to convert 0-255 colors into the 16-bit integers you need for passing to the OLED, e.g:

oled.pixel(OLED_WIDTH/2, OLED_HEIGHT/2, Color565(0,255,0)); // draw a green pixel in the center of the screen

Display Buffer

In hexidraw.h there is an optional define for enabling use of a display buffer.

#define USE_BUFFER 0

By default the buffer is disabled, enable it by changing the 0 to 1. If you enable the buffer, all draw commandsl just draw to the buffer and won't be drawn on the screen until you call

    oled.draw();

Drawing

Drawing pixels

To draw a single pixel on the screen, you use the pixel() function:

oled.pixel(uint16_t x, uint16_t y, uint16_t color)

Drawing Rectangles

oled.rect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color);

Drawing Circles

Drawing a circle on the screen is a combination of using sine and cosine along with some radian conversions and some for loops.

Luckily for you, I've already written all the necessary code!

oled.circle(uint16_t x, uint16_t y, uint16_t radis, uint16_t color, uint16_t width=1); // You can leave the width parameter undefined and it will default to a width of 1

Drawing Images

By converting your image to a 8-bit array using either the official Hexiwear resources converter:

https://github.com/MikroElektronika/HEXIWEAR/tree/master/SW/ResourceCollectionTool

Or by using R. Scott Coppersmith's tool:

https://developer.mbed.org/forum/team-4615-Hexiwear-community/topic/26474/

you can display 16-bit BMP images on the OLED.

oled.image (uint16_t x, uint16_t y, const uint8_t* image, uint32_t image_data_size = OLED_IMAGE_SIZE);

The 'image' parameter should be the array that is exported from the tool you use.

Note on exporting via the Resource collection tool: The exported code does not have the the correct type assigned by default. e.g:

const code char hexi_gradiant_bmp_bmp[18438] = { ... }

Will need to be changed to:

const uint8_t hexi_gradiant_bmp_bmp[18438] = { ... }

Roadmap

  • Function to draw arcs
  • Function to draw filled circle
  • Function to draw rectangle outline only
  • Function for drawing lines
  • Drawing Hexiwear image arrays on the screen
  • Drawing fonts
  • Other types of interesting geometric drawing functions
  • Code optimizations

All wikipages