RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    What am i doing wrong with my hd44780 16x2 lcd?

    Scheduled Pinned Locked Moved Help and Support
    hd44780 16x2 lc
    52 Posts 3 Posters 15.2k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • cyperghostC
      cyperghost
      last edited by cyperghost

      @Boz
      No No! Please don't directly wire 5V to SDA/SCL! This will damage the Input GPIO! You rather should use Pin 1 for power... with much much luck it works!

      If you prefer easy wiring then use a I2S designed for RPi with 3,3V TTL but most LCDs need at least 5V.

      Annother method could this one
      You power it up with 5V to ground and the PIC "could" interpret 3,3V signals from UART of Pi.... I said "could". Usually the signal of high is 2,5-2,7V to 3,3V could work!

      What the difference between the UART and the I2C? The UART is a one way communication so no signal reaches the Pi and so overvoltage is no risk!

      The cleanest way imho is the direct wiring! The Breadboard is just for testing. If it works you can solder it directly

      BozB 1 Reply Last reply Reply Quote 0
      • cyperghostC
        cyperghost @future.child
        last edited by

        @future-child said in What am i doing wrong with my hd44780 16x2 lcd?:

        @boz The pi can output 5V as well as 3v3 but the gpio ports are only 3v3 tolerant, therefore you need a level shifter. The 5V produced by the backpack is simply to high and possibly could damage the ports.

        right!

        1 Reply Last reply Reply Quote 0
        • BozB
          Boz @cyperghost
          last edited by

          @cyperghost So there is already a chance that the SDA/SCL pin is damaged? If so would it have damaged the Dac+light or the pi itself?
          I'm grateful that people write tutorials such as the one I followed for the display but there seems to be a lot of conflicting information out there.
          So i can either go with the level shifter or the direct wiring without the backpack, I'm gonna read back through your posts and see what pins need to be connected to directly wire this.
          Hopefully there has been no damage and i can carry on with my troubleshooting or better still the damn thing just works lol!

          1 Reply Last reply Reply Quote 0
          • cyperghostC
            cyperghost
            last edited by cyperghost

            Well I have an I2S backpack here, without LCD and I can detect it with i2cdetect -y 1 on 27h.
            Try to wire the whole thing on 3,3V and take a look to the red LED. Then check with i2cdetect -y 1

            There are tons of "how to" connect a HD44780 on google, the poti isn't needed - it's for contrast setting

            EDIT: Easier setup without resistors! This one is for Pi B, but the GPIOs are backwards compatible. This graphic is only for example! How a wiring should work! I've tested it for several years and it worked so far!
            img

            1 Reply Last reply Reply Quote 0
            • BozB
              Boz
              last edited by

              So i just swap pin 4 for pin 1?

              cyperghostC 1 Reply Last reply Reply Quote 0
              • BozB
                Boz
                last edited by

                I feel which ever method i choose i should remove the dac and connect directly to the pi. Even though the lcd was connected without a level shifter it still had power...so the reason why i get no address from i2cdetect -y 1 must be because either the gpio input was damaged or the header on the dac isn't soldered very well.
                Removing the dac narrows it down i reckon.

                1 Reply Last reply Reply Quote 0
                • cyperghostC
                  cyperghost @Boz
                  last edited by cyperghost

                  @boz said in What am i doing wrong with my hd44780 16x2 lcd?:

                  So i just swap pin 4 for pin 1?

                  Yes this will not overvoltage SDL/SDA ... If the red LED is on then the backpack could work and may be detected. With much much luck your display will also run!

                  With this config my I2S device results this

                  pi@raspberrypi:~ $ i2cdetect -y 1
                       0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
                  00:          -- -- -- -- -- -- -- -- -- -- -- -- --
                  10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
                  20: -- -- -- -- -- -- -- 27 -- -- -- -- -- -- -- --
                  30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
                  40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
                  50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
                  60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
                  70: -- -- -- -- -- -- -- --
                  
                  1 Reply Last reply Reply Quote 0
                  • BozB
                    Boz
                    last edited by

                    Ha ha we'll see!

                    1 Reply Last reply Reply Quote 0
                    • BozB
                      Boz
                      last edited by

                      Tried with 3.3v pin, backpack gets power but still no address. Will try this again over the weekend but connected directly to the pi.

                      1 Reply Last reply Reply Quote 0
                      • cyperghostC
                        cyperghost
                        last edited by

                        @Boz Maybe you remove your I2S devices, too and look to the posting @future-child gave you. This is a nice instruction as well

                        1 Reply Last reply Reply Quote 0
                        • BozB
                          Boz
                          last edited by

                          Thanks, I'll spend some time fault finding/process of elimination. I'll try all the things you guy's have suggested and see how i get on.

                          1 Reply Last reply Reply Quote 0
                          • BozB
                            Boz
                            last edited by

                            Success!!
                            I dug out an old rpi2 and tried the display on that using i2c (3.3v). I got an address from i2cdetect -y 1.... (3f) and changed a few test scripts to suit all of which worked.
                            I want on to change the script I was going to use in my build (retropie_clcd.py) and then altered all the text to what I wanted.
                            Tried everything that I'd just done exactly the same on my rpi3 with dac etc and still no address. So it has to be the dac for whatever reason, I'll connect the lcd directly to the rpi3 with no dac attached see if that works.

                            1 Reply Last reply Reply Quote 1
                            • cyperghostC
                              cyperghost
                              last edited by

                              @Boz - Don't give up!
                              I was in luck, on my work we used former HD44780 display for giving text messages to consumer, so I soldered my I2S-backbag to this and it works like a charm. Anyway the characters don't look good

                              Hello RetroPie!
                              Greetings from
                                cyperghost
                                & crcerror
                              

                              It's an 16x4 display and it worked fine with level shifter!

                              img

                              1 Reply Last reply Reply Quote 0
                              • BozB
                                Boz
                                last edited by Boz

                                No I won't give up, I used the sd card from the rpi2 (where the lcd was working) and stuck it in the rpi3 with no dac attached and bingo!!
                                So now I'm going to reconnect the dac and try that. If that works also I know it's not a hardware issue :)
                                I'll start with a fresh image then add the ATXraspi and test lcd, add the DAC then test lcd.....and so on until either I find out the problem or it just works (and I never find out what the problem was)
                                Level shifter getting delivered this week hopefully.

                                1 Reply Last reply Reply Quote 0
                                • cyperghostC
                                  cyperghost
                                  last edited by cyperghost

                                  @Boz
                                  I used the python libary posted here - it worked flawless with my setup. Keep care of upper and lower cases. Just use the same filenames as posted in the thread.

                                  Good luck mate

                                  EDIT:

                                  Just for conserving (INTERNET IS FLUID!)
                                  Testing python sniplet retropie.py

                                  import I2C_LCD_driver
                                  from time import *
                                  
                                  mylcd = I2C_LCD_driver.lcd()
                                  
                                  mylcd.lcd_display_string("Hello RetroPie!", 1)
                                  mylcd.lcd_display_string("Column 3!", 2, 3)
                                  

                                  LCD driverlibary I2C_LCD_driver.py - change adress in driver for ex 0x27h
                                  Please check with i2cdetect -y 1 (or i2cdetect -y 0 on Raspberry v1 B)

                                  # -*- coding: utf-8 -*-
                                  # Original code found at:
                                  # https://gist.github.com/DenisFromHR/cc863375a6e19dce359d
                                  
                                  """
                                  Compiled, mashed and generally mutilated 2014-2015 by Denis Pleic
                                  Made available under GNU GENERAL PUBLIC LICENSE
                                  
                                  # Modified Python I2C library for Raspberry Pi
                                  # as found on http://www.recantha.co.uk/blog/?p=4849
                                  # Joined existing 'i2c_lib.py' and 'lcddriver.py' into a single library
                                  # added bits and pieces from various sources
                                  # By DenisFromHR (Denis Pleic)
                                  # 2015-02-10, ver 0.1
                                  
                                  """
                                  
                                  # i2c bus (0 -- original Pi, 1 -- Rev 2 Pi)
                                  I2CBUS = 1
                                  
                                  # LCD Address
                                  ADDRESS = 0x27
                                  
                                  import smbus
                                  from time import sleep
                                  
                                  class i2c_device:
                                     def __init__(self, addr, port=I2CBUS):
                                        self.addr = addr
                                        self.bus = smbus.SMBus(port)
                                  
                                  # Write a single command
                                     def write_cmd(self, cmd):
                                        self.bus.write_byte(self.addr, cmd)
                                        sleep(0.0001)
                                  
                                  # Write a command and argument
                                     def write_cmd_arg(self, cmd, data):
                                        self.bus.write_byte_data(self.addr, cmd, data)
                                        sleep(0.0001)
                                  
                                  # Write a block of data
                                     def write_block_data(self, cmd, data):
                                        self.bus.write_block_data(self.addr, cmd, data)
                                        sleep(0.0001)
                                  
                                  # Read a single byte
                                     def read(self):
                                        return self.bus.read_byte(self.addr)
                                  
                                  # Read
                                     def read_data(self, cmd):
                                        return self.bus.read_byte_data(self.addr, cmd)
                                  
                                  # Read a block of data
                                     def read_block_data(self, cmd):
                                        return self.bus.read_block_data(self.addr, cmd)
                                  
                                  
                                  # commands
                                  LCD_CLEARDISPLAY = 0x01
                                  LCD_RETURNHOME = 0x02
                                  LCD_ENTRYMODESET = 0x04
                                  LCD_DISPLAYCONTROL = 0x08
                                  LCD_CURSORSHIFT = 0x10
                                  LCD_FUNCTIONSET = 0x20
                                  LCD_SETCGRAMADDR = 0x40
                                  LCD_SETDDRAMADDR = 0x80
                                  
                                  # flags for display entry mode
                                  LCD_ENTRYRIGHT = 0x00
                                  LCD_ENTRYLEFT = 0x02
                                  LCD_ENTRYSHIFTINCREMENT = 0x01
                                  LCD_ENTRYSHIFTDECREMENT = 0x00
                                  
                                  # flags for display on/off control
                                  LCD_DISPLAYON = 0x04
                                  LCD_DISPLAYOFF = 0x00
                                  LCD_CURSORON = 0x02
                                  LCD_CURSOROFF = 0x00
                                  LCD_BLINKON = 0x01
                                  LCD_BLINKOFF = 0x00
                                  
                                  # flags for display/cursor shift
                                  LCD_DISPLAYMOVE = 0x08
                                  LCD_CURSORMOVE = 0x00
                                  LCD_MOVERIGHT = 0x04
                                  LCD_MOVELEFT = 0x00
                                  
                                  # flags for function set
                                  LCD_8BITMODE = 0x10
                                  LCD_4BITMODE = 0x00
                                  LCD_2LINE = 0x08
                                  LCD_1LINE = 0x00
                                  LCD_5x10DOTS = 0x04
                                  LCD_5x8DOTS = 0x00
                                  
                                  # flags for backlight control
                                  LCD_BACKLIGHT = 0x08
                                  LCD_NOBACKLIGHT = 0x00
                                  
                                  En = 0b00000100 # Enable bit
                                  Rw = 0b00000010 # Read/Write bit
                                  Rs = 0b00000001 # Register select bit
                                  
                                  class lcd:
                                     #initializes objects and lcd
                                     def __init__(self):
                                        self.lcd_device = i2c_device(ADDRESS)
                                  
                                        self.lcd_write(0x03)
                                        self.lcd_write(0x03)
                                        self.lcd_write(0x03)
                                        self.lcd_write(0x02)
                                  
                                        self.lcd_write(LCD_FUNCTIONSET | LCD_2LINE | LCD_5x8DOTS | LCD_4BITMODE)
                                        self.lcd_write(LCD_DISPLAYCONTROL | LCD_DISPLAYON)
                                        self.lcd_write(LCD_CLEARDISPLAY)
                                        self.lcd_write(LCD_ENTRYMODESET | LCD_ENTRYLEFT)
                                        sleep(0.2)
                                  
                                  
                                     # clocks EN to latch command
                                     def lcd_strobe(self, data):
                                        self.lcd_device.write_cmd(data | En | LCD_BACKLIGHT)
                                        sleep(.0005)
                                        self.lcd_device.write_cmd(((data & ~En) | LCD_BACKLIGHT))
                                        sleep(.0001)
                                  
                                     def lcd_write_four_bits(self, data):
                                        self.lcd_device.write_cmd(data | LCD_BACKLIGHT)
                                        self.lcd_strobe(data)
                                  
                                     # write a command to lcd
                                     def lcd_write(self, cmd, mode=0):
                                        self.lcd_write_four_bits(mode | (cmd & 0xF0))
                                        self.lcd_write_four_bits(mode | ((cmd << 4) & 0xF0))
                                  
                                     # write a character to lcd (or character rom) 0x09: backlight | RS=DR<
                                     # works!
                                     def lcd_write_char(self, charvalue, mode=1):
                                        self.lcd_write_four_bits(mode | (charvalue & 0xF0))
                                        self.lcd_write_four_bits(mode | ((charvalue << 4) & 0xF0))
                                    
                                     # put string function with optional char positioning
                                     def lcd_display_string(self, string, line=1, pos=0):
                                      if line == 1:
                                        pos_new = pos
                                      elif line == 2:
                                        pos_new = 0x40 + pos
                                      elif line == 3:
                                        pos_new = 0x14 + pos
                                      elif line == 4:
                                        pos_new = 0x54 + pos
                                  
                                      self.lcd_write(0x80 + pos_new)
                                  
                                      for char in string:
                                        self.lcd_write(ord(char), Rs)
                                  
                                     # clear lcd and set to home
                                     def lcd_clear(self):
                                        self.lcd_write(LCD_CLEARDISPLAY)
                                        self.lcd_write(LCD_RETURNHOME)
                                  
                                     # define backlight on/off (lcd.backlight(1); off= lcd.backlight(0)
                                     def backlight(self, state): # for state, 1 = on, 0 = off
                                        if state == 1:
                                           self.lcd_device.write_cmd(LCD_BACKLIGHT)
                                        elif state == 0:
                                           self.lcd_device.write_cmd(LCD_NOBACKLIGHT)
                                  
                                     # add custom characters (0 - 7)
                                     def lcd_load_custom_chars(self, fontdata):
                                        self.lcd_write(0x40);
                                        for char in fontdata:
                                           for line in char:
                                              self.lcd_write_char(line)
                                  
                                  1 Reply Last reply Reply Quote 1
                                  • BozB
                                    Boz
                                    last edited by

                                    Thanks m8,
                                    i'll try that script when my level shifter comes, my displays a little dull at the minute on 3.3v.
                                    Now I know the display can work, I'll implement it into the facia design. The lcd wasn't essential but damn it looks good!!

                                    1 Reply Last reply Reply Quote 1
                                    • cyperghostC
                                      cyperghost
                                      last edited by cyperghost

                                      @Boz Post pictures if you're ready with your build :)

                                      BozB 1 Reply Last reply Reply Quote 0
                                      • BozB
                                        Boz @cyperghost
                                        last edited by Boz

                                        @cyperghost will do m8, the level shifter came today so I'm gonna wire it up tomorrow if I get time. I'll post pics of the display working but it might be a while for the finished product.
                                        I need a day when my boss isn't in so I can mill the facia.
                                        Thanks for your time aswell m8, it's been much appreciated. You and future.child.

                                        1 Reply Last reply Reply Quote 0
                                        • BozB
                                          Boz
                                          last edited by Boz

                                          Hi, I'm about to wire up this level shifter but I'm a bit confused on the wiring.
                                          Is this right so far?

                                          Level Shifter/ Pi / LCD
                                          LV / pin 1 (LV from level shifter to pin 1 on pi)
                                          LV1 / pin 3 (LV1 from level shifter to pin 3 on pi)
                                          LV2 / pin 5 (LV2 from level shifter to pin 5 on pi)
                                          GND / pin 6 / GND (gnd from level shifter to pin6 on pi, opposite gnd on level
                                          shifter to gnd on LCD?)
                                          HV / pin 2 / VCC (HV from level shifter to pin 2 on pi, then?)
                                          HV1 / SDA (HV1 from level shifter to SDA on i2c?)
                                          HV2 / SCL (HV2 from level shifter to SCL on i2c?)

                                          1 Reply Last reply Reply Quote 0
                                          • cyperghostC
                                            cyperghost
                                            last edited by cyperghost

                                            @Boz You are 100% on the right track :)

                                            L means Low
                                            H means High

                                            L1 = 3,3V and is connected to your Pi power Pin 1
                                            H1 = 5,0V and is connected to your Pi power Pin 2
                                            G = Ground connected to your Pi (3,3V and 5,0V and of course also LCD via Levelshifter)

                                            LV1 = SDA Pin 3 from your Pi
                                            LV2 = SDL Pin 5 from your Pi

                                            HV1 = SDA to your I2C LCD
                                            HV2 = SDL to your I2C LCD

                                            GND is GND and doesn't matter were you connect to your Pi because voltage potential is equal!

                                            You connect Ground from LCD to your Pi, also the 3,3V and 5,0V are connected to your Pi. You can see picture in my posting

                                            Usually you can connect all grounds together. But at first try I would use 3,3V/Ground and 5,0V/Ground seperate because they are needed to reference voltage level.

                                            1 Reply Last reply Reply Quote 1
                                            • First post
                                              Last post

                                            Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

                                            Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.