Python LCD-Display HD44780/ ST7066

145 views
Skip to first unread message

El Smiedro

unread,
Jul 5, 2016, 10:29:54 AM7/5/16
to BeagleBoard
Hi everyone,

I tried to run a lcd-display ST7066 (probably similar to the hd44870) with the folowing code:

------------------------------------------------------------------------------------
import Adafruit_BBIO.GPIO as GPIO
import time
 
# Define GPIO to LCD mapping
LCD_RS="P9_15"
LCD_E="P9_16"
LCD_D4="P9_21"
LCD_D5="P9_22"
LCD_D6="P9_23"
LCD_D7="P9_24"

OUT=GPIO.OUT
LOW=GPIO.LOW
HIGH=GPIO.HIGH

# Define some device constants
LCD_WIDTH = 16    # Maximum characters per line
LCD_CHR = True
LCD_CMD = False
 
LCD_LINE_1 = 0x00 # LCD RAM address for the 1st line
LCD_LINE_2 = 0x28 # LCD RAM address for the 2nd line
 
# Timing constants
E_PULSE = 0.00005 
E_DELAY = 0.00005
 
def main():
  # Main program block
  GPIO.setup(LCD_E,OUT)  # E
  GPIO.setup(LCD_RS,OUT) # RS
  GPIO.setup(LCD_D4,OUT) # DB4
  GPIO.setup(LCD_D5,OUT) # DB5
  GPIO.setup(LCD_D6,OUT) # DB6
  GPIO.setup(LCD_D7,OUT) # DB7
 
  # Initialise display
  lcd_init()

def lcd_init():
  # Initialise display
  lcd_byte(0x30,LCD_CMD) # 110011 Initialise
  time.sleep(0.01)
  lcd_byte(0x30,LCD_CMD) # 110010 Initialise
  time.sleep(0.01)
  lcd_byte(0x30,LCD_CMD) # 000110 Cursor move direction
  time.sleep(0.01)
  lcd_byte(0x20,LCD_CMD) # 001100 Display On,Cursor Off, Blink Off
  time.sleep(0.01)
  #lcd_byte(0x1C,LCD_CMD) # 101000 Data length, number of lines, font size
  #  time.sleep(0.01)
  lcd_byte(0x0C,LCD_CMD)
  time.sleep(0.01)
  lcd_byte(0x01,LCD_CMD)
  time.sleep(0.01)
  #lcd_byte(0x06,LCD_CMD) # 000001 Clear display
 
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
  GPIO.output(LCD_D4, False)     # High bits
  GPIO.output(LCD_D5, False)
  GPIO.output(LCD_D6, False)
  GPIO.output(LCD_D7, False)
  time.sleep(0.001)
  lcd_toggle_enable()
  if bits&0x10:
    GPIO.output(LCD_D4, True)
  if bits&0x20:
    GPIO.output(LCD_D5, True)
  if bits&0x40:
    GPIO.output(LCD_D6, True)
  if bits&0x80:
    GPIO.output(LCD_D7, True)
  time.sleep(E_PULSE)
  GPIO.output(LCD_E, True)
  time.sleep(E_DELAY)
  GPIO.output(LCD_E, False)
  time.sleep(E_PULSE)

# lcd_toggle_enable()
  GPIO.output(LCD_D4, False)
  GPIO.output(LCD_D5, False)
  GPIO.output(LCD_D6, False)
  GPIO.output(LCD_D7, False)
 
  if bits&0x01:
    GPIO.output(LCD_D4, True)
  if bits&0x02:
    GPIO.output(LCD_D5, True)
  if bits&0x04:
    GPIO.output(LCD_D6, True)
  if bits&0x08:
    GPIO.output(LCD_D7, True)
  lcd_toggle_enable()
   
def lcd_toggle_enable():
  time.sleep(0.005)
  GPIO.output(LCD_E, False)
  time.sleep(E_PULSE)
  GPIO.output(LCD_E, True)
  time.sleep(E_DELAY)
  GPIO.output(LCD_E, False)
  time.sleep(0.005)

def lcd_string(zeile,text):
  if zeile == 1:
      lcd_byte(LCD_LINE_1, LCD_CMD) 
  if zeile == 2:
      lcd_byte(LCD_LINE_1, LCD_CMD)
  message=text.ljust(LCD_WIDTH,'_')
  for i in range(LCD_WIDTH):      
    lcd_byte(ord(message[i]),LCD_CHR)
   
main()
lcd_string(1,'abc')
------------------------------------------------------------

but there is no correct output on the display:














I think that there is something wrong with the toggle or the waittime of the toggle, but I cant find any error.
Can anybody see an error in the sourcecode?
Thanks for your help.

best regards eyk


Reply all
Reply to author
Forward
0 new messages