LCD-Blue-I2C

From ArduinoInfo
Jump to navigation Jump to search

LCD Displays (Blue and Yellow) with I2C/TWI Interface

NOTE! NOTE! MANY UPDATES 11/28/2020 moving to Perry LCD Library

YwRobotLCD-4x20-400.jpg


IMPORTANT LCD Software Library INSTALL Info:

ALL these displays will now use the great Library written by Bill Perry . You can install the library from the Arduino Library Manager. In the Arduino software IDE, Use the top menu:

Tools and then Library Manager ... Then WAIT (It is slow) You should see this:

LM-start.jpg

Now move your cursor to the field marked with red spot. .... WAIT until you see your cursor and you can type. Type "Bill Perry" and ... WAIT. You should see this:

LM-BillPerry.jpg

Click on INSTALL. (It may be over on the right more like this:) Screen Shot 2020-11-28 at 4.19.40 PM.png NOTE!! Move any other LCD libraries to another folder,or rename or delete them.

OK. With that library installed, let's connect your LCD I2C display.


NOTE!! Move any other LCD libraries to another folder,or rename or delete them.

NOTE! THERE ARE THREE (or More??) VERSIONS OF THE 2 and 4 LINE DISPLAYS. Check the small "backpack" interface board on the back. These small circuit boards on the back interface a 2-wire I2C "I Squared C" bus (plus Ground and +5V power) to the many pins on the LCD display itself. This allows running the display from only 2 signal pins on Arduino.

The YourDuino RoboRED (UNO Compatible) has a 4-pin connector that works well for this type display.

These displays are Available HERE:

NOTE! These displays are very clear bright white on dark blue (or Black on Yellow) background: it is difficult to get a good digital photo due to polarization effects.

I2C ADDRESSES:

NOTE: With the Perry library you should NOT have to worry about I2C addresses ! But if you care, see:

I2C Address Scanner Sketch HERE The "backpack" modules used on these displays utilize the PCF8574A IC Chip. The Datasheet is HERE: File:Pcf8574a.pdf

The modules used on these displays may also be used for general-purpose 8-bit I/O expanders. A module with the address pins available is HERE These I2C interface displays have a built-in ADDRESS. If you try to run a display and there is no response or nothing is displayed you may have the wrong address in the code you are using. You can run the I2C ADDRESS SCANNER (Bottom of this page) on your Arduino to check the address on your display if necessary. For LOTS of detailed technical information about I2C Interfaces see THIS from Nick Gammon.

WHY THE I2C (IIC) TYPE LCD DISPLAY?

To use this type LCD directly with Arduino, you would need 6 pins: RS, EN, D7, D6, D5, and D4 to talk to the LCD. If you are doing more than a simple project, you may be out of pins using a normal LCD shield. With this I2C interface LCD module, you only need 2 lines (I2C) to display information. If you already have I2C devices in your project, this LCD module actually uses no more pins at all. More information about I2C/TWI (Wikipedia) This unit connects with 4 wires including Vcc and Gnd. It is easiest with a 4-wire cable that plugs into the [/SensorShield Sensor Shield] communications connector or directly to a YourDuino RoboRED (UNO Compatible: See it HERE (click)).. See the lower right: "I2C" 4-pin connector. But you can wire it directly yourself if needed: There are 4 pins on the display.. (see photo below)
4-pinCable-Pinout-500.jpg YwRobotLCD-CU-450.jpg RoboRED-Annotated-I2c-400.jpg

UNO

MEGA

SDA

Analog 4

Pin 20

SCL

Analog 5

Pin 21

On most Arduino boards, SDA (data line) is on analog input pin 4, and SCL (clock line) is on analog input pin 5. On the newer Arduino UNO (The "V3" pinout), the SCL and SDA pins are also on two new leftmost top pins. The YourDuino RoboRED has those pins and also a nice 4-pin connector arranged exactly like the LCD display pins. On the Arduino Mega, SDA is digital pin 20 and SCL is pin 21. NOTE: The Blue Potentiometer (Photo) adjusts Contrast. If you don't see any characters, adjust it. Start clockwise and back down to where the characters are bright and the background does not have boxes behind the characters.

EXAMPLE: See a LCD used in the Temperature-Humidity project.

Extensible hd44780 LCD library Functions HOW-TO

See Bill's documentation HERE: (Scroll down a little. Especially see the section API Summary. These are the commands you can use to control your LCD. In your code you will normally put lcd. at the beginning to make a complete command. Examples:

  • lcd.begin(16,2); (For a 2 line 16 character LCD)
  • lcd.begin(20,4); (For a 4 line 20 character LCD)
  • lcd.setCursor(col, row); (Both Columns and Rows start at 0 origin, so the first column of the first row is lcd.setCursor(0, 0);
  • lcd.setCursor(4,1); ( 5th character in second row).
  • lcd.print("Hello!") (First you set the starting cursor position, right??)
  • lcd.print(int 5); {Display a numeric value)

It will take some learning and experimentation to mix text and data on your LCD!

Below are Example Software Sketches for different displays. They will also display characters you type on the Serial Monitor screen on the LCD. NOTE: Line 1 only is correct when writing a long sequence of characters. The characters fill the first line and continue on the third, due to the way the LCD internal addressing works. So this is "normal" and has to do with the LCD hardware. Usually you will set the cursor position before writing characters. (Details in the document linked at the end of this page, if you want them.) (Cut and paste these examples into a blank page on the Arduino IDE).

I2C LCD DISPLAY VERSION 1:


LCD-A0A1A2.jpg These type displays have the 4 pins in the right order to connect directly to the Yourduino RoboRED by a 4-pin cable.

I2C LCD DISPLAY VERSION 2:

LCD-Arduino-IIC-LCD-GY-LCD-V1.jpg Marked "Arduino-IIC-LCD GY-LCD-V1" NOTE: The wire connections are in a different order! See the labels on the PC Board.

Example Software Sketch for 2 line 16 character Displays:

This sketch should work for almost all 2 line 16 character LCD displays with an I2C "Backpack" PC Board with PCF8574 chip on the back.

<shtml hash="fd467f8f78a4996d63434ac69fb44488039b09b79636a8041f4d1dbe7b3fcff7">
<font color="#95a5a6">/* YourDuino.com Example Software Sketch</font>
<font color="#95a5a6"> *  _2_Line_I2C_Display_TestV2.ino</font>
<font color="#95a5a6"> *   16 character 2 line I2C Display</font>
<font color="#95a5a6"> *   Uses Bill Perry's HD44780 Library, which can be installed from the Arduino Library Manager</font>
<font color="#95a5a6"> *   See Bills documentation: </font><u><font color="#95a5a6">https://github.com/duinoWitchery/hd44780</font></u><font color="#95a5a6"></font>
<font color="#95a5a6"> *   See the "API Summary" section.  Use "lcd" in front like lcdbegin(cols, rows)</font>
<font color="#95a5a6"> *   </font>
<font color="#95a5a6"> *   LCD Display Blue or Yellow: I2C/TWI "Backpack" Interface</font>
<font color="#95a5a6"> questions??  terry@yourduino.com </font>
<font color="#95a5a6">  </font>
<font color="#95a5a6"> */</font>
 <font color="#434f54">// ----------------------------------------------------------------------------</font>
<font color="#95a5a6">/*LiquidCrystal compability:</font>
<font color="#95a5a6">Since this hd44780 library is LiquidCrystal API compatible, most existing LiquidCrystal</font>
<font color="#95a5a6">sketches should work with hd44780 hd44780_I2Cexp i/o class once the</font>
<font color="#95a5a6">includes are changed to use hd44780 and the lcd object constructor is</font>
<font color="#95a5a6">changed to use the hd44780_I2Cexp i/o class.</font>
<font color="#95a5a6">*/</font>

<font color="#95a5a6">/*-----( Import needed libraries )-----*/</font>
<font color="#5e6d03">#include</font> <font color="#434f54"><</font><font color="#d35400">Wire</font><font color="#434f54">.</font><font color="#000000">h</font><font color="#434f54">></font>
<font color="#5e6d03">#include</font> <font color="#434f54"><</font><b><font color="#d35400">hd44780</font></b><font color="#434f54">.</font><font color="#000000">h</font><font color="#434f54">></font>                       <font color="#434f54">// main hd44780 header</font>
<font color="#5e6d03">#include</font> <font color="#434f54"><</font><font color="#000000">hd44780ioClass</font><font color="#434f54">/</font><b><font color="#d35400">hd44780_I2Cexp</font></b><font color="#434f54">.</font><font color="#000000">h</font><font color="#434f54">></font> <font color="#434f54">// i2c expander i/o class header</font>


<font color="#95a5a6">/*-----( Declare Constants )-----*/</font>
<font color="#434f54">// LCD geometry</font>
<font color="#00979c">const</font> <font color="#00979c">int</font> <font color="#000000">LCD_COLS</font> <font color="#434f54">=</font> <font color="#000000">16</font><font color="#000000">;</font>
<font color="#00979c">const</font> <font color="#00979c">int</font> <font color="#000000">LCD_ROWS</font> <font color="#434f54">=</font> <font color="#000000">2</font><font color="#000000">;</font>

<font color="#95a5a6">/*-----( Declare objects )-----*/</font>
<b><font color="#d35400">hd44780_I2Cexp</font></b> <font color="#000000">lcd</font><font color="#000000">;</font> <font color="#434f54">// declare lcd object: auto locate & auto config expander chip  </font>
<font color="#95a5a6">/*-----( Declare Variables )-----*/</font>
<font color="#00979c">int</font> <font color="#d35400">status</font><font color="#000000">;</font>

<font color="#00979c">void</font> <font color="#5e6d03">setup</font><font color="#000000">(</font><font color="#000000">)</font>   <font color="#95a5a6">/*----( SETUP: RUNS ONCE )----*/</font>
<font color="#000000">{</font>
  <font color="#d35400">status</font> <font color="#434f54">=</font> <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">begin</font><font color="#000000">(</font><font color="#000000">LCD_COLS</font><font color="#434f54">,</font> <font color="#000000">LCD_ROWS</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#5e6d03">if</font><font color="#000000">(</font><font color="#d35400">status</font><font color="#000000">)</font> <font color="#434f54">// non zero status means it was unsuccesful</font>
  <font color="#000000">{</font>
    <font color="#434f54">// hd44780 has a fatalError() routine that blinks an led if possible</font>
    <font color="#434f54">// begin() failed so blink error code using the onboard LED if possible</font>
    <b><font color="#d35400">hd44780</font></b><font color="#434f54">:</font><font color="#434f54">:</font><font color="#d35400">fatalError</font><font color="#000000">(</font><font color="#d35400">status</font><font color="#000000">)</font><font color="#000000">;</font> <font color="#434f54">// does not return</font>
  <font color="#000000">}</font>  
  <b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">begin</font><font color="#000000">(</font><font color="#000000">9600</font><font color="#000000">)</font><font color="#000000">;</font>

  <font color="#434f54">// Print a message to the LCD.</font>
  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">setCursor</font><font color="#000000">(</font><font color="#000000">0</font><font color="#434f54">,</font> <font color="#000000">0</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">print</font><font color="#000000">(</font><font color="#005c5f">"2-Line DISPLAY"</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#d35400">delay</font><font color="#000000">(</font><font color="#000000">1500</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">setCursor</font><font color="#000000">(</font><font color="#000000">0</font><font color="#434f54">,</font> <font color="#000000">1</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">print</font><font color="#000000">(</font><font color="#005c5f">"YourDuino: HI!"</font><font color="#000000">)</font><font color="#000000">;</font>  
  
  <font color="#d35400">delay</font><font color="#000000">(</font><font color="#000000">5000</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">setCursor</font><font color="#000000">(</font><font color="#000000">0</font><font color="#434f54">,</font> <font color="#000000">0</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">print</font><font color="#000000">(</font><font color="#005c5f">"Now YOU Type    "</font><font color="#000000">)</font><font color="#000000">;</font>  
  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">setCursor</font><font color="#000000">(</font><font color="#000000">0</font><font color="#434f54">,</font> <font color="#000000">1</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">print</font><font color="#000000">(</font><font color="#005c5f">"On SerialMonitor"</font><font color="#000000">)</font><font color="#000000">;</font>    
<font color="#000000">}</font><font color="#95a5a6">/*--(end setup )---*/</font>


<font color="#00979c">void</font> <font color="#5e6d03">loop</font><font color="#000000">(</font><font color="#000000">)</font>   <font color="#95a5a6">/*----( LOOP: RUNS CONSTANTLY )----*/</font>
<font color="#000000">{</font>
  <font color="#000000">{</font>
    <font color="#434f54">// when characters arrive over the serial port...</font>
    <font color="#5e6d03">if</font> <font color="#000000">(</font><b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">available</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
      <font color="#434f54">// wait a bit for the entire message to arrive</font>
      <font color="#d35400">delay</font><font color="#000000">(</font><font color="#000000">100</font><font color="#000000">)</font><font color="#000000">;</font>
      <font color="#434f54">// clear the screen</font>
      <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">clear</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
      <font color="#434f54">// read all the available characters</font>
      <font color="#5e6d03">while</font> <font color="#000000">(</font><b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">available</font><font color="#000000">(</font><font color="#000000">)</font> <font color="#434f54">></font> <font color="#000000">0</font><font color="#000000">)</font> <font color="#000000">{</font>
        <font color="#434f54">// display each character to the LCD</font>
        <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">write</font><font color="#000000">(</font><b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">read</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">)</font><font color="#000000">;</font>
      <font color="#000000">}</font>
    <font color="#000000">}</font>
  <font color="#000000">}</font>

<font color="#000000">}</font><font color="#95a5a6">/* --(end main loop )-- */</font>

<font color="#95a5a6">/*-----( Declare User-written Functions )-----*/</font>


<font color="#95a5a6">/* ( THE END ) */</font>

</shtml>

Example Software Sketch for 4 line 20 character Displays:

This sketch should work for almost all 4 line 20 character LCD displays with an I2C "Backpack" PC Board with PCF8574 chip on the back.

<shtml hash="2ef5cb3b7159694659447d68afcce4c013adf1edc6ccd54060f84413d9df8d01">
<font color="#95a5a6">/* YourDuino.com Example Software Sketch</font>
<font color="#95a5a6"> *  LCD_I2C_4x20_TEST.ino</font>
<font color="#95a5a6"> *   20 character 4 line I2C Display</font>
<font color="#95a5a6"> *   Uses Bill Perry's HD44780 Library, which can be installed from the Arduino Library Manager</font>
<font color="#95a5a6"> *   See Bill's documentation: </font><u><font color="#95a5a6">https://github.com/duinoWitchery/hd44780</font></u><font color="#95a5a6"></font>
<font color="#95a5a6"> *   See the "API Summary" section.  Use "lcd" in front like lcd.begin(cols, rows)</font>
<font color="#95a5a6"> *   </font>
<font color="#95a5a6"> *   LCD Display Blue or Yellow: I2C/TWI "Backpack" Interface</font>
<font color="#95a5a6"> questions??  terry@yourduino.com </font>
<font color="#95a5a6">  </font>
<font color="#95a5a6"> */</font>
 <font color="#434f54">// ----------------------------------------------------------------------------</font>
<font color="#95a5a6">/*LiquidCrystal compability:</font>
<font color="#95a5a6">Since this hd44780 library is LiquidCrystal API compatible, most existing LiquidCrystal</font>
<font color="#95a5a6">sketches should work with hd44780 hd44780_I2Cexp i/o class once the</font>
<font color="#95a5a6">includes are changed to use hd44780 and the lcd object constructor is</font>
<font color="#95a5a6">changed to use the hd44780_I2Cexp i/o class.</font>
<font color="#95a5a6">*/</font>
<font color="#95a5a6">/*-----( Import needed libraries )-----*/</font>
<font color="#5e6d03">#include</font> <font color="#434f54"><</font><font color="#d35400">Wire</font><font color="#434f54">.</font><font color="#000000">h</font><font color="#434f54">></font>
<font color="#5e6d03">#include</font> <font color="#434f54"><</font><b><font color="#d35400">hd44780</font></b><font color="#434f54">.</font><font color="#000000">h</font><font color="#434f54">></font>                       <font color="#434f54">// main hd44780 header</font>
<font color="#5e6d03">#include</font> <font color="#434f54"><</font><font color="#000000">hd44780ioClass</font><font color="#434f54">/</font><b><font color="#d35400">hd44780_I2Cexp</font></b><font color="#434f54">.</font><font color="#000000">h</font><font color="#434f54">></font> <font color="#434f54">// i2c expander i/o class header</font>


<font color="#95a5a6">/*-----( Declare Constants )-----*/</font>
<font color="#434f54">// LCD geometry</font>
<font color="#00979c">const</font> <font color="#00979c">int</font> <font color="#000000">LCD_COLS</font> <font color="#434f54">=</font> <font color="#000000">20</font><font color="#000000">;</font>
<font color="#00979c">const</font> <font color="#00979c">int</font> <font color="#000000">LCD_ROWS</font> <font color="#434f54">=</font> <font color="#000000">4</font><font color="#000000">;</font>


<font color="#95a5a6">/*-----( Declare objects )-----*/</font>
<b><font color="#d35400">hd44780_I2Cexp</font></b> <font color="#000000">lcd</font><font color="#000000">;</font> <font color="#434f54">// declare lcd object: auto locate & auto config expander chip  </font>
<font color="#95a5a6">/*-----( Declare Variables )-----*/</font>
<font color="#00979c">int</font> <font color="#d35400">status</font><font color="#000000">;</font>

<font color="#00979c">void</font> <font color="#5e6d03">setup</font><font color="#000000">(</font><font color="#000000">)</font>   <font color="#95a5a6">/*----( SETUP: RUNS ONCE )----*/</font>
<font color="#000000">{</font>
  <b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">begin</font><font color="#000000">(</font><font color="#000000">9600</font><font color="#000000">)</font><font color="#000000">;</font>  <font color="#434f54">// Used to type in characters</font>

  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">begin</font><font color="#000000">(</font><font color="#000000">20</font><font color="#434f54">,</font><font color="#000000">4</font><font color="#000000">)</font><font color="#000000">;</font>         <font color="#434f54">// initialize the lcd for 20 chars 4 lines, turn on backlight</font>

<font color="#434f54">// ------- Quick 3 blinks of backlight  -------------</font>
  <font color="#5e6d03">for</font><font color="#000000">(</font><font color="#00979c">int</font> <font color="#000000">i</font> <font color="#434f54">=</font> <font color="#000000">0</font><font color="#000000">;</font> <font color="#000000">i</font><font color="#434f54"><</font> <font color="#000000">3</font><font color="#000000">;</font> <font color="#000000">i</font><font color="#434f54">++</font><font color="#000000">)</font>
  <font color="#000000">{</font>
    <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">backlight</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
    <font color="#d35400">delay</font><font color="#000000">(</font><font color="#000000">250</font><font color="#000000">)</font><font color="#000000">;</font>
    <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">noBacklight</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
    <font color="#d35400">delay</font><font color="#000000">(</font><font color="#000000">250</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#000000">}</font>
  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">backlight</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font> <font color="#434f54">// finish with backlight on  </font>

<font color="#434f54">//-------- Write characters on the display ------------------</font>
  <font color="#434f54">// NOTE: Cursor Position: Lines and Characters start at 0  </font>
  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">setCursor</font><font color="#000000">(</font><font color="#000000">3</font><font color="#434f54">,</font><font color="#000000">0</font><font color="#000000">)</font><font color="#000000">;</font> <font color="#434f54">//Start at character 4 on line 0</font>
  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">print</font><font color="#000000">(</font><font color="#005c5f">"Hello, world!"</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#d35400">delay</font><font color="#000000">(</font><font color="#000000">1000</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">setCursor</font><font color="#000000">(</font><font color="#000000">2</font><font color="#434f54">,</font><font color="#000000">1</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">print</font><font color="#000000">(</font><font color="#005c5f">"From YourDuino"</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#d35400">delay</font><font color="#000000">(</font><font color="#000000">1000</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">setCursor</font><font color="#000000">(</font><font color="#000000">0</font><font color="#434f54">,</font><font color="#000000">2</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">print</font><font color="#000000">(</font><font color="#005c5f">"20 by 4 Line Display"</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">setCursor</font><font color="#000000">(</font><font color="#000000">0</font><font color="#434f54">,</font><font color="#000000">3</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#d35400">delay</font><font color="#000000">(</font><font color="#000000">2000</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">print</font><font color="#000000">(</font><font color="#005c5f">"http://YourDuino.com"</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#d35400">delay</font><font color="#000000">(</font><font color="#000000">8000</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#434f54">// Wait and then tell user they can start the Serial Monitor and type in characters to</font>
  <font color="#434f54">// Display. (Set Serial Monitor option to "No Line Ending")</font>
  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">setCursor</font><font color="#000000">(</font><font color="#000000">0</font><font color="#434f54">,</font><font color="#000000">0</font><font color="#000000">)</font><font color="#000000">;</font> <font color="#434f54">//Start at character 0 on line 0</font>
  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">print</font><font color="#000000">(</font><font color="#005c5f">"Start Serial Monitor"</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">setCursor</font><font color="#000000">(</font><font color="#000000">0</font><font color="#434f54">,</font><font color="#000000">1</font><font color="#000000">)</font><font color="#000000">;</font>
  <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">print</font><font color="#000000">(</font><font color="#005c5f">"Type chars 2 display"</font><font color="#000000">)</font><font color="#000000">;</font>


<font color="#000000">}</font><font color="#95a5a6">/*--(end setup )---*/</font>


<font color="#00979c">void</font> <font color="#5e6d03">loop</font><font color="#000000">(</font><font color="#000000">)</font>   <font color="#95a5a6">/*----( LOOP: RUNS CONSTANTLY )----*/</font>
<font color="#000000">{</font>
  <font color="#000000">{</font>
    <font color="#434f54">// when characters arrive over the serial port...</font>
    <font color="#5e6d03">if</font> <font color="#000000">(</font><b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">available</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
      <font color="#434f54">// wait a bit for the entire message to arrive</font>
      <font color="#d35400">delay</font><font color="#000000">(</font><font color="#000000">100</font><font color="#000000">)</font><font color="#000000">;</font>
      <font color="#434f54">// clear the screen</font>
      <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">clear</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
      <font color="#434f54">// read all the available characters</font>
      <font color="#5e6d03">while</font> <font color="#000000">(</font><b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">available</font><font color="#000000">(</font><font color="#000000">)</font> <font color="#434f54">></font> <font color="#000000">0</font><font color="#000000">)</font> <font color="#000000">{</font>
        <font color="#434f54">// display each character to the LCD</font>
        <font color="#000000">lcd</font><font color="#434f54">.</font><font color="#d35400">write</font><font color="#000000">(</font><b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">read</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">)</font><font color="#000000">;</font>
      <font color="#000000">}</font>
    <font color="#000000">}</font>
  <font color="#000000">}</font>

<font color="#000000">}</font><font color="#95a5a6">/* --(end main loop )-- */</font>


<font color="#95a5a6">/* ( THE END ) */</font>

</shtml>

Example: Display DS18B20 Temperature Sensors on LCD

See THIS PAGE

I2C ADDRESS DETAILS

I2C ADDRESS SCANNER FOR ARDUINO/YOURDUINO:

You can scan for the I2C address used by your display. Connect your display (See connection info at top of this page). Then upload the following sketch to your Arduino. Click on "Serial Monitor at upper right. Set the Speed (lower right pulldown) to 115200. Push the Reset button on your Arduino and see the results. The results should look like this (address changes):

 
 I2C scanner. Scanning ...
 Found address: 39 (0x27)
 Done.
 Found 1 device(s).
 

Copy and Paste this sketch (Thanks Nick Gammon!) into a blank Arduino IDE window:


// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011

#include <Wire.h>

void setup() {
  Serial.begin (115200);

  // Leonardo: wait for serial port to connect
  while (!Serial)
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;

  Wire.begin();
  for (byte i = 8; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

CHANGING I2C ADDRESSES:

SOME I2C interfaces have pins (or solder pads) that can be changed to change the address. They are usually labelled A0-A1-A2 . Here's the way addresses change from a default 0x27 with if you connect address pads together. (1 = Not Connected. 0 = Connected):

A0

A1

A2

HEX Address

1

1

1

0x27

0

1

1

0x26

1

0

1

0x25

0

0

1

0x24

1

1

0

0x23

0

1

0

0x22

1

0

0

0x21

0

0

0

0x20

If you make a change use the I2C Address Scanner to confirm it...

MORE INFORMATION ABOUT THE I2C "BACKPACK" USED ON THESE DISPLAYS: Schematic Diagram:

Ic2-BackPackSchematic-1.jpg