Arduino/LCD Display: Difference between revisions
From charlesreid1
No edit summary |
|||
| Line 42: | Line 42: | ||
|2 | |2 | ||
|3 | |3 | ||
|[http://robotic-controls.com/learn/arduino/lcd-sainsmart-hd44780-lcd2004] | |[http://robotic-controls.com/learn/arduino/lcd-sainsmart-hd44780-lcd2004 Robotic-Controls.com] | ||
|- | |- | ||
|Mega2560 | |Mega2560 | ||
|20 | |20 | ||
|21 | |21 | ||
|[http://robotic-controls.com/learn/arduino/lcd-sainsmart-hd44780-lcd2004] | |[http://robotic-controls.com/learn/arduino/lcd-sainsmart-hd44780-lcd2004 Robotic-Controls.com] | ||
|- | |- | ||
|Due | |Due | ||
|20 | |20 | ||
|21 | |21 | ||
|[http://robotic-controls.com/learn/arduino/lcd-sainsmart-hd44780-lcd2004] | |[http://robotic-controls.com/learn/arduino/lcd-sainsmart-hd44780-lcd2004 Robotic-Controls.com] | ||
|} | |} | ||
Revision as of 04:33, 19 July 2015
This page covers how to use a SainSmart LCD 2004 display with an Arduino.
Overview
So far we've covered some really simple circuits with single components. We're not doing a whole lot with the voltages in our system, or with the microcontroller. This project will introduce a more advanced output device for the Arduino, namely, an LCD display for printing simple text messages.
The LCD Display
To begin with, we can note a couple of things about the LCD display:
First, the display has its own microcontroller on-board, meaning it has hardware dedicated to turning voltage signals on the microcontroller board (coming from the Arduino) into the right output signals for its LCD display. All of that circuitry and the details of connecting an Arduino to the Sainsmart LCD 2004 are covered on the Sainsmart website (scroll down to the documents section, they link to a zip file that contains a bunch of example sketches and
What is I2C?
We've already noticed there's a separate integrated circuit onboard the LCD display. That means we'll be using something called I2C, which stands for Inter-Integrated Circuit. It's a way for integrated circuits (microprocessors) to talk to each other.
I2C Pins on Arduino
In order to use I2C, you'll need to use special I2C pins onboard the Arduino. There are two wires - one is labeled SDA (System Data) and the other is labeled SCL (System Clock). They're labeled SDA and SCL on the Sainsmart's board, so that side will be clear. But which pins they'll plug into on the Arduino board depends on the type of board.
This site lists the SDA/SCL pins for a couple of boards, and I've added a few:
| Board Type | SDA Pin | SCL Pin | Reference |
|---|---|---|---|
| Micro | 1 | 2 | Arduino.cc website - Arduino Micro |
| Uno | A4 | A5 | An excellent and very thorough I2C example |
| Leonardo | 2 | 3 | Robotic-Controls.com |
| Mega2560 | 20 | 21 | Robotic-Controls.com |
| Due | 20 | 21 | Robotic-Controls.com |
The Circuit
Breadboard Diagram
Breadboard Photo
Hello World Sainsmart Sketch Code
To display static information on the display, Sainsmart provides the following "Hello World" app:
//YWROBOT
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,20,4); // set the LCD address to 0x3F for a 16 chars and 2 line display
void setup()
{
lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("Hello, world!");
lcd.setCursor(2,1);
lcd.print("SainSmart for UNO");
lcd.setCursor(2,2);
lcd.print("SainSmart LCM IIC");
lcd.setCursor(1,3);
lcd.print("Design By SainSmart");
}
void loop()
{
}
Note that you'll find a couple of different I2C addresses floating around, like 0x20 and 0x27. I'm not sure where people are getting those from, but the 0x3F value comes from Sainsmart's website, and it works right out of the box.