From charlesreid1

No edit summary
No edit summary
Line 1: Line 1:
This page covers how to use a SainSmart LCD 2004 display with an Arduino.
[[Image:Sainsmart.jpg|650px]]
=Overview=
=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.
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 [http://www.sainsmart.com/sainsmart-iic-i2c-twi-serial-2004-20x4-lcd-module-shield-for-arduino-uno-mega-r3.html 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.
[http://robotic-controls.com/learn/arduino/lcd-sainsmart-hd44780-lcd2004 This site] lists the SDA/SCL pins for a couple of boards, and I've added a few:
{| class="table wikitable"
!|Board Type
!|SDA Pin
!|SCL Pin
!|Reference
|-
|Micro
|1
|2
|[https://www.arduino.cc/en/Main/arduinoBoardMicro Arduino.cc website - Arduino Micro]
|-
|Uno
|A4
|A5
|[http://tronixstuff.com/2010/10/20/tutorial-arduino-and-the-i2c-bus/ An excellent and very thorough I2C example]
|-
|Leonardo
|2
|3
|[http://robotic-controls.com/learn/arduino/lcd-sainsmart-hd44780-lcd2004]
|-
|Mega2560
|20
|21
|[http://robotic-controls.com/learn/arduino/lcd-sainsmart-hd44780-lcd2004]
|-
|Due
|20
|21
|[http://robotic-controls.com/learn/arduino/lcd-sainsmart-hd44780-lcd2004]
|}
=The Circuit=
==Breadboard Diagram==
==Breadboard Photo==
[[Image:photo_Sainsmart1.jpg|500px]]
==Hello World Sainsmart Sketch Code==
To display static information on the display, Sainsmart provides the following "Hello World" app:
<source lang="C">
//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()
{
}
</source>
Note that you'll find a couple of different I2C addresses floating around, like <code>0x20</code> and <code>0x27</code>. I'm not sure where people are getting those from, but the <code>0x3F</code> value comes from [http://www.sainsmart.com/sainsmart-iic-i2c-twi-serial-2004-20x4-lcd-module-shield-for-arduino-uno-mega-r3.html Sainsmart's website], and it works right out of the box.


[[Category:Arduino]]
[[Category:Arduino]]

Revision as of 04:31, 19 July 2015

This page covers how to use a SainSmart LCD 2004 display with an Arduino.

Sainsmart.jpg

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 [1]
Mega2560 20 21 [2]
Due 20 21 [3]

The Circuit

Breadboard Diagram

Breadboard Photo

Photo Sainsmart1.jpg

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.