16x2 LCD

Pin Diagram


Cursor Positions

0,0
1,0
2,0
3,0
4,0
5,0
6,0
7,0
8,0
9,0
10,0
11,0
12,0
13,0
14,0
15,0
0,1
1,1
2,1
3,1
4,1
5,1
6,1
7,1
8,1
9,1
10,1
11,1
12,1
13,1
14,1
15,1

Code

                                   ARDUINO CODE
/*
 *  http://arduspot.blogspot.in/p/16x2-lcd.html
 * 
 *        LCD             ARDUINO UNO
 *        VSS                 GND
 *        VDD                 5V
 *        VEE              Potentiometer
 *        RS                     8
 *        RW                  GND
 *        E                       9
 *        D4                    10
 *        D5                    11
 *        D6                    12
 *        D7                    13
 *        
 *  D0,D1,D2,D3  →  No Connection
 */

#include<LiquidCrystal.h>
LiquidCrystal lcd(8,9,10,11,12,13);

void setup()
{
lcd.begin(16,2);
  lcd.clear();
}

void loop()
{
  lcd.setCursor(0,0);
  lcd.print("Liquid Crystal");
  lcd.setCursor(4,1);
  lcd.print("Display"); 
}
_________________________________________________________________________________

                                  RASPBERRY PI
import time
import RPi.GPIO as GPIO

#OUTPUTS: map GPIO to LCD lines
LCD_RS = 7
LCD_E = 8
LCD_D4 = 25
LCD_D5 = 24
LCD_D6 = 23
LCD_D7 = 18
OUTPUTS = [LCD_RS,LCD_E,LCD_D4,LCD_D5,LCD_D6,LCD_D7]

CLEARDISPLAY = 0x01
SETCURSOR = 0x80
LINE = [0x00,0x40]
def InitIO():
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    for lcdLine in OUTPUTS:
        GPIO.setup(lcdLine, GPIO.OUT)

def PulseEnableLine():
    mSec = 0.0005
    time.sleep(mSec)
    GPIO.output(LCD_E, GPIO.HIGH)
    time.sleep(mSec)
    GPIO.output(LCD_E, GPIO.LOW)
    time.sleep(mSec)

def SendNibble(data):
    GPIO.output(LCD_D4, bool(data & 0x10))
    GPIO.output(LCD_D5, bool(data & 0x20))
    GPIO.output(LCD_D6, bool(data & 0x40))
    GPIO.output(LCD_D7, bool(data & 0x80))

def SendByte(data,charMode=False):
    GPIO.output(LCD_RS,charMode)
    SendNibble(data)
    PulseEnableLine()
    data = (data & 0x0F)<< 4
    SendNibble(data)
    PulseEnableLine()

def InitLCD():
    SendByte(0x33)
    SendByte(0x32)
    SendByte(0x28)
    SendByte(0x0C)
    SendByte(0x06)
    SendByte(CLEARDISPLAY)
def SendChar(ch):
    SendByte(ord(ch),True)
def ShowMessage(string):
    for character in string:
        SendChar(character)
def GotoLine(row):
    addr = LINE[row]
    SendByte(SETCURSOR+addr)
print "Pi LCD2 program starting. Ctrl-C to stop."
InitIO()
InitLCD()
while (True):
    GotoLine(0)
    ShowMessage('   LCD   ')
    GotoLine(1)
    ShowMessage('   Display   ')
    time.sleep(0.2)

No comments:

Post a Comment