LCD_I2C Library for Arduino
Author:  Nicolas BOUTIN
Contact: boutwork@gmail.com


Navigation


History

ReleaseDateChanges
1.030/05/2013Initial Release.


Description

Arduino library that allows you to drive a LCD (character-only). Typical clear screen, cursor ON/OFF, back-light ON/OFF, goto X,Y coordinates, print(), println and use of operator<< available.

Written for the following hardware CLCD204-BLB, a Textual LCD 4*20 but also works with smaller or bigger LCD by giving the size of the current LCD in the constructor.

Works through I2C by using Pin A4(SDA) and Pin A5(SCL) on an Arduino Uno R3. Some pull-up resistor(I use 2k ohms) might be needed between power supply (5V) and pin A4 and A5.


Download

Download here: Download LCD_I2C Library

Put the "LCD_I2C" folder in "libraries\".

In the Arduino IDE, create a new sketch (or open one) and select from the menubar "Sktech->Import Library->LCD_I2C".


Constructor

LCD_I2C(uint8_t I2C_add, uint8_t nb_row = 4, uint8_t nb_column = 20);

Example:

  • LCD_I2C lcd(0x00);
  • LCD_I2C lcd(0x00, 2, 16);
  • LCD_I2C lcd(0x00, 4, 20);


Methods

  • void begin (); - lcd.begin(); must be called in order to initialize I2C communication.
  • void clear ();
  • void backlight (const boolean b_on);
  • void cursor (const boolean b_on);
  • void home ();
  • void cursorXY (const uint8_t x, const uint8_t y);
  • void moveToRow (const uint8_t y);
  • void custom (const uint8_t code, const byte* byte_data);

  • template<class T> inline Print& operator<< (Print& stream, T arg);

  • size_t print (const __FlashStringHelper *);
  • size_t print (const String &);
  • size_t print (const char[]);
  • size_t print (char);
  • size_t print (unsigned char, int = DEC);
  • size_t print (int, int = DEC);
  • size_t print (unsigned int, int = DEC);
  • size_t print (long, int = DEC);
  • size_t print (unsigned long, int = DEC);
  • size_t print (double, int = 2);
  • size_t print (const Printable&);

  • size_t println (const __FlashStringHelper *);
  • size_t println (const String &s);
  • size_t println (const char[]);
  • size_t println (char);
  • size_t println (unsigned char, int = DEC);
  • size_t println (int, int = DEC);
  • size_t println (unsigned int, int = DEC);
  • size_t println (long, int = DEC);
  • size_t println (unsigned long, int = DEC);
  • size_t println (double, int = 2);
  • size_t println (const Printable&);
  • size_t println (void);


Example

#How To

  1.  
  2. #include "Arduino.h"
  3. #include "Wire.h"
  4.  
  5. #include "lcd_I2C.h"
  6.  
  7. /**
  8.  * The Streaming library must be included in order to use "operator<<"        
  9.  * It can be find at the following address :
  10.  * http://arduiniana.org/libraries/streaming/
  11.  * I am not the author of it but it is a must-have
  12.  */
  13. #include "Streaming.h"
  14.  
  15.  
  16. LCD_I2C lcd(0x00, 4, 20);
  17.  
  18.  
  19. void setup()
  20. {
  21.   lcd.begin();
  22. }
  23.  
  24.  
  25. void loop() {
  26.         uint32_t ui32_lcd_delay = 3000;
  27.  
  28.         uint8_t uc_val = 0xFF;
  29.         int32_t i32_val = -456798;
  30.         uint32_t ui32_val = 0xFFFFFFFF;
  31.         float f_val = 1234.89;
  32.  
  33.         lcd.clear();
  34.         lcd << "-- Operator << --" << endl;
  35.         delay(ui32_lcd_delay);
  36.  
  37.         lcd.clear();
  38.         lcd.println(F("Const char in flash"));
  39.         lcd.println(F("I am in flash !"));
  40.         delay(ui32_lcd_delay);
  41.  
  42.         lcd.clear();
  43.         lcd.println(F("-- Print String --"));
  44.         String string("I am a string !");
  45.         lcd << string << endl;
  46.         delay(ui32_lcd_delay);
  47.  
  48.         lcd.clear();
  49.         lcd << "-- Print char --" << endl;
  50.         lcd << "char : " << 'a' << endl;
  51.         delay(ui32_lcd_delay);
  52.  
  53.         lcd.clear();
  54.         lcd << "-- Print number --" << endl;
  55.         lcd << "uint8_t: " << uc_val << endl;
  56.         lcd << "uint8_t: 0x" << _HEX(uc_val) << endl;
  57.         lcd << "uint8_t: 0b" << _BIN(uc_val) << endl;
  58.         delay(ui32_lcd_delay);
  59.  
  60.         lcd.clear();
  61.         lcd << "-- Print number --" << endl;
  62.         lcd << "int32_t: " << i32_val << endl;
  63.         lcd << "int32_t: 0x" << _HEX(i32_val) << endl;
  64.         delay(ui32_lcd_delay);
  65.  
  66.         lcd.clear();
  67.         lcd << "-- Print float --" << endl;
  68.         lcd << "float: " << f_val << endl;
  69.         delay(ui32_lcd_delay);
  70.  
  71.         lcd.clear();
  72.         lcd << "-- Backlight OFF --" << endl;
  73.         lcd.backlight(false);
  74.         delay(ui32_lcd_delay);
  75.  
  76.         lcd.clear();
  77.         lcd << "-- Backlight ON --" << endl;
  78.         lcd.backlight(true);
  79.         delay(ui32_lcd_delay);
  80.  
  81.         lcd.clear();
  82.         lcd << "-- CursorXY (5,3) --" << endl;
  83.         lcd.cursorXY(5, 3);
  84.         lcd << 'X';
  85.         delay(ui32_lcd_delay);
  86.  
  87.         lcd.clear();
  88.         lcd << "- CursorXY (10,2) -" << endl;
  89.         lcd << _XY(10, 2) << 'X';
  90.         delay(ui32_lcd_delay);
  91.  
  92.         lcd.clear();
  93.         lcd.print("-- Cursor OFF --");
  94.         lcd.cursor(false);
  95.         delay(ui32_lcd_delay);
  96.  
  97.         lcd.clear();
  98.         lcd.print("-- Cursor ON --");
  99.         lcd.cursor(true);
  100.         delay(ui32_lcd_delay);
  101.  
  102.         lcd.clear();
  103.         lcd << "-- Cursor Home --" << endl;
  104.         lcd.home();
  105.         delay(ui32_lcd_delay);
  106. }


Information about this page

Last Modified: June 01, 2013, at 12:06 PM
By: nicolas_b

Share