TheRealCharlie
Posts: 8
Joined: Mon Jul 14, 2014 1:03 am

LCD shows random characters

Tue Jul 15, 2014 10:51 pm

I have a 512MB model B rasberry PI and I cant seem to get it to work with this LCD I have in the kit I bought.
It just shows a bunch of random characters on the LCD screen when I try to show a message using the python script.
I followed the tutorial here: http://www.raspberrypi-spy.co.uk/2012/0 ... ng-python/
Screenshots of my setup and the LCD here: http://imgur.com/QrGzyud,ZMIGl7V,9ur0T6 ... 67,ghEJFLj

DirkS
Posts: 9961
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: LCD shows random characters

Wed Jul 16, 2014 1:50 pm

I notice that wires are not soldered to the board, so it could be that one or more don't make a proper contact...

Gr.
Dirk.

TheRealCharlie
Posts: 8
Joined: Mon Jul 14, 2014 1:03 am

Re: LCD shows random characters

Wed Jul 16, 2014 4:42 pm

Im not sure, do you really think that could be it? I mean they are all making contact with the LCD and none of them are touching.

DirkS
Posts: 9961
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: LCD shows random characters

Wed Jul 16, 2014 5:05 pm

Well, the pins have so much space in the holes that you really cannot be sure that they make proper contact...

User avatar
David Melara
Posts: 26
Joined: Sun Jul 13, 2014 8:32 pm
Location: El Salvador
Contact: Website

Re: LCD shows random characters

Wed Jul 16, 2014 5:09 pm

Are you sure the tutorial is for the raspberry B model? Because the B cnanges some gpio of site, better go to adafruit and follow that tutorial, they tell you the gpio that have changed site.
If you love doing something, be sure that something will be done right

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12331
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: LCD shows random characters

Wed Jul 16, 2014 5:29 pm

could be a logic level problem, the 3V3 high levels from the PI sometimes do not satisfy the minimum high levels a 5V powered LCD demands.

kshiraly
Posts: 10
Joined: Tue Nov 05, 2013 6:33 pm

Re: LCD shows random characters

Wed Jul 16, 2014 6:25 pm

What make is this LCD? Does it have a model name / number / datasheet?

Many of these LCD controllers differ slightly from the HD44780 controller in things like the initialization sequence, minimum delay between commands and maybe other ways I don't know of.

Assuming that the problem persists even after soldering, try with the following changes:
1. Change lcd_init():

Code: Select all

def lcd_init():
  # Initialise display
  # Intialization step 1: Function Set command
  # 00110000 : bit 6->1 means this is the function set instruction
  #            bit 5->0 means use 4-bit bus
  #            bit 4->0 means 1 line LCD. ->1 means 2 line LCD
  #            bit 3->0 means 5x7 dots  
  lcd_byte(0b00101000,LCD_CMD)
  
  # Intialization Step 2: Display on command
  # 00001111: bit 1->1 means set cursor to blinking. 0->no blink
  #           bit 2->1 means set cursor on. 0->no cursor
  #           bit 3->1 means set display on
  #           bit 4->1 means this is a display control instruction
  # If cursor and blink are set to on, they'll display only after a clear command is issued.  
  lcd_byte(0b00001100,LCD_CMD)
  
  # Step 3: Clear display command
  lcd_byte(0b00000001,LCD_CMD)
2. Increase the pulse and delay durations.

Code: Select all

# Timing constants
E_PULSE = 0.0001
E_DELAY = 0.0001
3. Add a large delay after a command

Code: Select all

def lcd_byte(bits, mode):
  ...
  ...
  # add this extra 1 ms delay after list line of function
  time.sleep(0.001) 
For most practical purposes, larger delays are ok. Once you get it working, you can always gradually reduce them if required.

TheRealCharlie
Posts: 8
Joined: Mon Jul 14, 2014 1:03 am

Re: LCD shows random characters

Fri Jul 18, 2014 8:12 pm

Im using a 220 OHM resistor would that be the correct one to use for this?

TheRealCharlie
Posts: 8
Joined: Mon Jul 14, 2014 1:03 am

Re: LCD shows random characters

Fri Jul 18, 2014 8:19 pm

it shows the random letters and numbers still like this: http://i.imgur.com/9ur0T61.jpg then after like 10 seconds it just shows rectangle boxes like this http://i.imgur.com/ghEJFLj.jpg

TheRealCharlie
Posts: 8
Joined: Mon Jul 14, 2014 1:03 am

Re: LCD shows random characters

Fri Jul 18, 2014 8:19 pm

Thats with changing the code to what kshiraly told me to.

TheRealCharlie
Posts: 8
Joined: Mon Jul 14, 2014 1:03 am

Re: LCD shows random characters

Fri Jul 18, 2014 8:24 pm

its random letters and numbers every time I try to run the script if that helps.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12331
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: LCD shows random characters

Sat Jul 19, 2014 9:04 am

try putting a 1n4148 diode between the 5V supply and the 5V of the LCD, so the LCD will get around 4.5V, that is enough for the LCD, and lowers its logical input levels enough so that it sees 3V3 logic highs as "1" reliably. The garbled letters, and blocks are due to the LCD sometimes seeing a "1" as a zero and that corrupts all communication between the PI and the LCD.

Its a well know problem when trying to drive an LCD with 3V3 levels, it actually needs minimally 3.5V when its powered with 5V (70 % of VCC = 0.7 x 5.0 = 3.5).

User avatar
MattHawkinsUK
Posts: 538
Joined: Tue Jan 10, 2012 8:48 pm
Location: UK
Contact: Website

Re: LCD shows random characters

Sat Jul 19, 2014 9:20 am

Almost certainly the wires not being connected to the LCD. Resting them against the PCB pads is not going to give guaranteed connectivity.

Remember that even solder joints can prevent a circuit working even if it looks like there is metal against metal.

In the photos above the Pi is a Model B Rev 2 so should work fine with my tutorial. Random characters is usually a sign it has not been initialized correctly. Again this could be caused by intermittent connections.
My Raspberry Pi blog and home of the BerryClip Add-on board : http://www.raspberrypi-spy.co.uk/
Follow me on Google+, Facebook, Pinterest and Twitter (@RPiSpy)

TheRealCharlie
Posts: 8
Joined: Mon Jul 14, 2014 1:03 am

Re: LCD shows random characters

Tue Dec 23, 2014 11:42 pm

Yea the problem is using your script, I get a bunch of syntax errors and a bunch of things wrong because of all the invalid spaces you have, and by the time I try to fix everything it still doesn't work. I still have yet to get this to work at all.

itoros
Posts: 1
Joined: Mon Apr 20, 2015 7:46 am

Re: LCD shows random characters

Mon Apr 20, 2015 8:18 am

Hi, I have the same caracters on the LCD.
What was the final solution for the problem?
I manage it via GPIO ports.
I trying the I2C interface now, maybe better.

User avatar
piglet
Posts: 911
Joined: Sat Aug 27, 2011 1:16 pm

Re: LCD shows random characters

Sat Dec 05, 2015 2:22 pm

mahjongg wrote:try putting a 1n4148 diode between the 5V supply and the 5V of the LCD, so the LCD will get around 4.5V,
I'd spent quite a lot if time searching for the solution to this problem before stumbling on this thread.

I was having the same problem as the OP on my current build with an I2C back-packed LCD getting corrupted. I'd tried all kinds of things to fix the problems - changing the delays, trying different libraries, and pulling out hair with no joy in fixing it.

Reading this I went scavenging diodes from old circuit boards and found some 1N4004's. According to the data sheet (I do admit to not being a frequent reader of such things so may have got this wrong...) the average voltage drop is 0.8 V

This with supply @ 5.3v (unloaded), works perfectly for me. Thank you.

User avatar
piglet
Posts: 911
Joined: Sat Aug 27, 2011 1:16 pm

Re: LCD shows random characters

Sat Dec 05, 2015 3:00 pm

ARGH! I spoke too soon. It's not fixed. The display's still getting garbled. :(

User avatar
piglet
Posts: 911
Joined: Sat Aug 27, 2011 1:16 pm

Re: LCD shows random characters

Tue Dec 08, 2015 10:44 pm

I finally had a chance to spend some time looking at this tonight.

For anyone else with this problem, you may have what I have if you're doing event-driven code e.g. from from a switch or rotary encoder. I was getting events triggered while the python code was trying to communicate with the LCD screen - which themselves tried to write to the LCD.

Simple solution - set up a global variable and ignore any interrupt that will do anything screen related until the last one was complete. That's good enough for what I need :

Code: Select all

done = True

def mything_event(event):
    global done
    if done:
        done = False
        handle_event(event,"mything")
        done = True
    return

peterobregozo
Posts: 1
Joined: Sun Jun 24, 2018 5:22 pm

Re: LCD shows random characters

Sun Jun 24, 2018 5:26 pm

My Problem/Solution:
I also had the same problem with scrambled characters on my display. I found that there was a short between the data lines on the expander board where it is soldered to the display board. Once I cleaned up the messy solder, the display worked perfectly.

Return to “Troubleshooting”