Arduino OLED Graph Library

These graphs and gauges were made for some projects I working on using Arduino and small OLED screens.

The code is on Github for anyone to get. To use the library, just copy the oled_charts.ino file into your project. The demo.ino sketch has some example implementations calling the functions in oled_charts.ino with random data.

Visualizations

There are two types of visualizations I've worked on here. The first set is "graphs" which chart values over time. The second is "gauges" which show a single instantaneous value.

All of the graphs are designed to work at arbitrary resolutions, and you can combine several of them into one screen.

Graph Types

Bar Graph

draw_bar_graph(int x, int y, int width, int height, int data[], int data_count);
draw_bar_graph(int x, int y, int width, int height, int data[], int data_count, int bar_width, int bar_padding);
draw_autoscale_bar_graph(int x, int y, int width, int height, int data[], int data_count);


Dot Graph

draw_dot_graph(int x, int y, int width, int height, int data[], int data_count);


Line Graph

draw_line_graph(int x, int y, int width, int height, int data[], int data_count);
draw_line_graph(int x, int y, int width, int height, int data[], int data_count, bool line, bool fill);


Area Graph

draw_area_graph(int x, int y, int width, int height, int data[], int data_count);


The scales

Those charts share the utility functions that automatically draw the X and Y scales.

draw_vertical_scale(int x, int y, int height, int spacing, int divisions);
draw_horizontal_scale(int x, int y, int width, int spacing, int divisions);

Gauge Types

Linear Gauge

draw_linear_gauge(int x, int y, int width, int height, int value);




Segmented

draw_segmented_gauge(int x, int y, int width, int height, int value, int segments);

draw_dot_gauge(int x, int y, int width, int height, int value);


Thermometer

draw_thermometer(int x, int y, int width, int height, int value);

Automatically adapts well to different sizes:


Needle

draw_needle_meter(int x, int y, int width, int value);

Adapts to different sizes well:


Radial

draw_radial_gauge(int x, int y, int radius, int value);
draw_radial_gauge(int x, int y, int radius, int value, int padding);
draw_radial_gauge(int x, int y, int radius, int value, int padding, bool outer_border, bool inner_border, bool draw_line, float start_offset);

draw_radial_line_gauge(int x, int y, int radius, int lines, int value, bool outer_border, bool inner_border, float start_offset);

draw_radial_segment_gauge(int x, int y, int radius, int segments, int value);
draw_radial_segment_gauge(int x, int y, int radius, int segments, int value, int padding, bool outer_border, bool inner_border, float start_offset);

draw_radial_dot_gauge(int x, int y, int radius, int dot_radius, int value);
draw_radial_dot_gauge(int x, int y, int radius, int dot_radius, int value, int segments, int empty_dot_radius, float start_offset);


Signal

draw_signal_strength(int x, int y, int width, int height, int value);
draw_signal_strength(int x, int y, int width, int height, int value, int bar_width);


Code Repo

The code for the charts and gauges lives in oled_charts.ino.

An example implementation is in demo.ino.

Published: March 19, 2022

Categories: arduino