mgardner323
Posts: 8
Joined: Thu Mar 19, 2015 2:21 pm

1602 LCD Issue

Thu Mar 19, 2015 3:37 pm

I have a Pi 2 Model B and I am trying to work with a LCD. It is wired in the following way on my Breadboard:
All I get is Dark Blocks on the top and Light Blocks on the second row. Just wondering if I did something wrong. I am new to this so any help would be appreciated.

LCD Pin outs
1 VSS Ground -
2 VDD Power +
3 V0 Middle Pin Pot
4 RS GPIO 26/ Board Pin 37
5 RW Ground -
6 E GPIO 19/ Board Pin 35
7 D0 Blank
8 D1 Blank
9 D2 Blank
10 D3 Blank
11 D4 GPIO 13 /Board Pin 33
12 D5 GPIO 06/ Board Pin 31
13 D6 GPIO 05/ Board Pin 29
14 D7 GPIO 11/ Board Pin 23
15 D8 Power +
16 D9 Ground -

I have Board Pin 2 Going to Power + / BCM
I have Board Pin 6 Going to Ground - / BCM
Pot Pin 1 Going to Ground
Pot Pin 3 Going to Power +

Code: Select all

#!/usr/bin/python
#
# HD44780 LCD Test Script for
# Raspberry Pi
#
# Author : Matt Hawkins
# Site   : http://www.raspberrypi-spy.co.uk
#
# Date   : 26/07/2012
#
 
# The wiring for the LCD is as follows:
# 1 : GND
# 2 : 5V
# 3 : Contrast (0-5V)*
# 4 : RS (Register Select)
# 5 : R/W (Read Write)       - GROUND THIS PIN
# 6 : Enable or Strobe
# 7 : Data Bit 0             - NOT USED
# 8 : Data Bit 1             - NOT USED
# 9 : Data Bit 2             - NOT USED
# 10: Data Bit 3             - NOT USED
# 11: Data Bit 4
# 12: Data Bit 5
# 13: Data Bit 6
# 14: Data Bit 7
# 15: LCD Backlight +5V**
# 16: LCD Backlight GND
 
#import
import RPi.GPIO as GPIO
import time
 
# Define GPIO to LCD mapping
LCD_RS = 37
LCD_E  = 35
LCD_D4 = 33
LCD_D5 = 31
LCD_D6 = 29
LCD_D7 = 23
 
# Define some device constants
LCD_WIDTH = 16    # Maximum characters per line
LCD_CHR = True
LCD_CMD = False
 
LCD_LINE_1 = 0x80 # LCD RAM address for the 1st line
LCD_LINE_2 = 0xC0 # LCD RAM address for the 2nd line 
 
# Timing constants
E_PULSE = 0.00005
E_DELAY = 0.00005
 
def main():
  # Main program block
 
  GPIO.setmode(GPIO.BOARD)       # Use BOARD GPIO Pin numbers
  GPIO.setup(LCD_E, GPIO.OUT)  # E
  GPIO.setup(LCD_RS, GPIO.OUT) # RS
  GPIO.setup(LCD_D4, GPIO.OUT) # DB4
  GPIO.setup(LCD_D5, GPIO.OUT) # DB5
  GPIO.setup(LCD_D6, GPIO.OUT) # DB6
  GPIO.setup(LCD_D7, GPIO.OUT) # DB7
 
  # Initialise display
  lcd_init()
 
  # Send some test
  lcd_byte(LCD_LINE_1, LCD_CMD)
  lcd_string("Rasbperry Pi")
  lcd_byte(LCD_LINE_2, LCD_CMD)
  lcd_string("Model B")
 
  time.sleep(3) # 3 second delay
 
  # Send some text
  lcd_byte(LCD_LINE_1, LCD_CMD)
  lcd_string("Raspberrypi-spy")
  lcd_byte(LCD_LINE_2, LCD_CMD)
  lcd_string(".co.uk")
 
  time.sleep(20)
 
def lcd_init():
  # Initialise display
  lcd_byte(0x33,LCD_CMD)
  lcd_byte(0x32,LCD_CMD)
  lcd_byte(0x28,LCD_CMD)
  lcd_byte(0x0C,LCD_CMD)
  lcd_byte(0x06,LCD_CMD)
  lcd_byte(0x01,LCD_CMD)  
 
def lcd_string(message):
  # Send string to display
 
  message = message.ljust(LCD_WIDTH," ")  
 
  for i in range(LCD_WIDTH):
    lcd_byte(ord(message[i]),LCD_CHR)
 
def lcd_byte(bits, mode):
  # Send byte to data pins
  # bits = data
  # mode = True  for character
  #        False for command
 
  GPIO.output(LCD_RS, mode) # RS
 
  # High bits
  GPIO.output(LCD_D4, False)
  GPIO.output(LCD_D5, False)
  GPIO.output(LCD_D6, False)
  GPIO.output(LCD_D7, False)
  if bits&0x10==0x10:
    GPIO.output(LCD_D4, True)
  if bits&0x20==0x20:
    GPIO.output(LCD_D5, True)
  if bits&0x40==0x40:
    GPIO.output(LCD_D6, True)
  if bits&0x80==0x80:
    GPIO.output(LCD_D7, True)
 
  # Toggle 'Enable' pin
  time.sleep(E_DELAY)
  GPIO.output(LCD_E, True)
  time.sleep(E_PULSE)
  GPIO.output(LCD_E, False)
  time.sleep(E_DELAY)      
 
  # Low bits
  GPIO.output(LCD_D4, False)
  GPIO.output(LCD_D5, False)
  GPIO.output(LCD_D6, False)
  GPIO.output(LCD_D7, False)
  if bits&0x01==0x01:
    GPIO.output(LCD_D4, True)
  if bits&0x02==0x02:
    GPIO.output(LCD_D5, True)
  if bits&0x04==0x04:
    GPIO.output(LCD_D6, True)
  if bits&0x08==0x08:
    GPIO.output(LCD_D7, True)
 
  # Toggle 'Enable' pin
  time.sleep(E_DELAY)
  GPIO.output(LCD_E, True)
  time.sleep(E_PULSE)
  GPIO.output(LCD_E, False)
  time.sleep(E_DELAY)   
 
if __name__ == '__name__':
  main()

texy
Forum Moderator
Forum Moderator
Posts: 5171
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 1602 LCD Issue

Thu Mar 19, 2015 3:49 pm

Hi and welcome to the forum,
some LCD's required those unused data bits to be tied low. Also make sure the RW line is also.
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

mgardner323
Posts: 8
Joined: Thu Mar 19, 2015 2:21 pm

Re: 1602 LCD Issue

Thu Mar 19, 2015 3:56 pm

When you say tied low do you mean Grounded.

Sorry really new to this but it is exciting. Its not so much the programming that is new as much as the electronic part of it all.

User avatar
DougieLawson
Posts: 41958
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: 1602 LCD Issue

Thu Mar 19, 2015 3:57 pm

You need to get a 10K variable resistor (aka a 10K pot). Tie one end to 5V0, tie the other to GND and tie the wiper to "3 V0 Middle Pin Pot".

Vary the resistance on that 10K pot until the blocks fade and the text appears.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

texy
Forum Moderator
Forum Moderator
Posts: 5171
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 1602 LCD Issue

Thu Mar 19, 2015 4:04 pm

DougieLawson wrote:You need to get a 10K variable resistor (aka a 10K pot). Tie one end to 5V0, tie the other to GND and tie the wiper to "3 V0 Middle Pin Pot".

Vary the resistance on that 10K pot until the blocks fade and the text appears.
Not in this case Dougie. The fact that the blocks are appearing on one line only indicates that the LCD is not initialised, not that there is a contrast issue. If it was contrast he would see both lines either blank or full.
IMHO,
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

mgardner323
Posts: 8
Joined: Thu Mar 19, 2015 2:21 pm

Re: 1602 LCD Issue

Thu Mar 19, 2015 4:18 pm

I can say when i turn the knob on the pot it does faid the blocks and brings them back.

How do I initialise the LCD?

User avatar
DougieLawson
Posts: 41958
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: 1602 LCD Issue

Thu Mar 19, 2015 4:26 pm

Is your python program running?

Have you got D4,D5,D6 & D7 in the right order? Have you got the RS and E pins wired right.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

mgardner323
Posts: 8
Joined: Thu Mar 19, 2015 2:21 pm

Re: 1602 LCD Issue

Thu Mar 19, 2015 4:33 pm

Douge,

I think so I have the pin outs that I am using at the top of the page.

If you see something wrong please let me know

And yes from what I can tell the python program is running
Last edited by mgardner323 on Thu Mar 19, 2015 5:24 pm, edited 1 time in total.

mgardner323
Posts: 8
Joined: Thu Mar 19, 2015 2:21 pm

Re: 1602 LCD Issue

Thu Mar 19, 2015 5:13 pm

So I have white blocks on the top and black on the bottom

texy
Forum Moderator
Forum Moderator
Posts: 5171
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 1602 LCD Issue

Thu Mar 19, 2015 5:55 pm

Have you updated your os recently? The initial version of RPi.GPIO may not work with the Pi 2. What does this show when you run it :

Code: Select all

import RPi.GPIO as GPIO
print GPIO.VERSION
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

mgardner323
Posts: 8
Joined: Thu Mar 19, 2015 2:21 pm

Re: 1602 LCD Issue

Thu Mar 19, 2015 6:02 pm

It is showing 0.5.11

texy
Forum Moderator
Forum Moderator
Posts: 5171
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 1602 LCD Issue

Thu Mar 19, 2015 6:11 pm

That is correct. Do you have use of a voltmeter?
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

mgardner323
Posts: 8
Joined: Thu Mar 19, 2015 2:21 pm

Re: 1602 LCD Issue

Thu Mar 19, 2015 6:39 pm

Yes I do what would you like me to test

texy
Forum Moderator
Forum Moderator
Posts: 5171
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 1602 LCD Issue

Thu Mar 19, 2015 6:47 pm

I would suggest that you create a new python program using the same method as the main program to determine that the GPIO pins you believe are setting high or low are actually doing it.
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

User avatar
DougieLawson
Posts: 41958
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: 1602 LCD Issue

Thu Mar 19, 2015 7:59 pm

Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

mgardner323
Posts: 8
Joined: Thu Mar 19, 2015 2:21 pm

Re: 1602 LCD Issue

Thu Mar 19, 2015 8:20 pm

Guys,

Thanks for all the help. After reviewing a few things i noticed I had not run the idle as admin and I was getting an error. Thank you everyone

Return to “Beginners”