Recently I developed a library for ease the job of displaying texts and numbers on different LCD/OLED modules. This is mainly for my OBD-II data logger project which can be made up of different sets of Arduino hardware. I named the library as Arduino Text Display Library for Multiple LCD, or short as MultiLCD.
The source code is available on Github.
The library encapsulates several libraries for various Arduino LCD/LED display shields or modules into a set of unified APIs.
Currently it supports these hardware:
DFRobot LCD4884 shield
Nokia 3310/5100 LCD module
LCD1602 shield
SSD1306 OLED module
ZT I2C OLED module
The library includes fonts data for ASCII characters (5×7) and digits (8×8, 16×16). By using the library, it is extremely simple for display texts and numbers on desired position on a LCD screen, while very little change is needed to switch from one LCD module to another.
The library class inherits the Print class of Arduino, so that you can display texts on LCD with standard Arduino functions like this:
lcd.print("Hello, World!";)
lcd.print(foo, DEC);
lcd.print(bar, HEX);
lcd.print(1.23) // gives "1.23"
lcd.print(1.23456, 2); // gives "1.23"
Besides, it provides unified APIs for initializing and controlling the LCD, as well as some convenient operations.
void begin(); /* initializing */
void clear(); /* clear screen */
void setCursor(unsigned char column, unsigned char line); /* set current cursor */
void printInt(unsigned int n, FONT_SIZE size); /* display a integer number with desired size of font*/
void printLong(unsigned long n, FONT_SIZE size); /* display a long number with desired size of font*/
The code using the library can be extremely simple.
#include <Wire.h>
#include <MultiLCD.h>
LCD_SSD1306 lcd; /* for SSD1306 OLED module */
void setup()
{
lcd.begin();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Hello, world!");
lcd.setCursor(0, 1);
lcd.printLong(1234567890, FONT_SIZE_SMALL);
lcd.setCursor(0, 2);
lcd.printLong(1234567890, FONT_SIZE_MEDIUM);
lcd.setCursor(0, 3);
lcd.printLong(12345678, FONT_SIZE_LARGE);
}