nervlinux
Posts: 4
Joined: Tue Aug 28, 2012 5:19 am

16x2 no contrast help (solved)

Mon Dec 24, 2012 7:41 pm

i can't get my potentiometer to work. all i see is a blue screen and then when i try to turn it nothing happens. heres a picture

Image
does that look right?

i'm using adafruit tutorial

( i never use a breadboard before and never solder , so im a noob at this stuff :D )

User avatar
aTao
Posts: 1089
Joined: Wed Dec 12, 2012 10:41 am
Location: Howlin Eigg

Re: 16x2 no contrast help

Tue Dec 25, 2012 7:50 am

No, that does not look right, an LCD with marks like that is damaged.

Also,one thin I fell foul of was buying the cheap model, the extended temperature range one which needs Vss- some (ie negative voltage) on Vo to show anything at room temperature.
>)))'><'(((<

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: 16x2 no contrast help

Tue Dec 25, 2012 5:59 pm

The power wiring looks correct. Is your power supply capable for driving the Pi, display, and display back light? When connected to the Raspberry Pi, is the back light lit?

With a meter, check pins 15,16 (A,K) for proper voltage (5v for the AdaFruit example). Also confirm 5v is present at pins 1,2 (Vss, Vdd). If you have DC voltage, confirm the polarity is correct: +5v on pins 15,2 and GND on pins 16,1.

If power is wired correctly and the voltage is correct, then check pin 3 (Vo) to pin 1 (Vss). As you turn the potentiometer, the voltage should vary from 0v to 5v.

Note: The AdaFruit example, as well as many others, does have an error in the wiring... The LED back light light should not be wired directly to 5v. LED back lights for LCD displays are typically rated for 4.2v and 120mA. This means you should have a resistor from 5v to pin 15. A 7-10 ohm, 1W, resistor would be sufficient to limit the current and voltage. Some LED back lights only require 20 mA. In this case, you could use a 40 ohm, 1W, resistor. If you are not certain, you can put a 1W potentiometer in place of the resistor and adjust until the brightness is correct. Without the resistor, the LED life will be greatly reduced and the display will be very warm (HOT) to the touch.

Also, in answer to the prior comment... Remove the protective film from the display. It is not necessary and does obscure the display somewhat.

Enjoy!

g4eml
Posts: 56
Joined: Wed Oct 05, 2011 1:50 pm

Re: 16x2 no contrast help

Tue Dec 25, 2012 7:36 pm

Some breadboards have split power supply busses. If you look at the red and blue lines you will see there is a gap between the left and right hand sides. You probably need to fit a link wire between the two red busses and one between the two blue busses. You can check if this is necessary with a meter.
Last edited by g4eml on Tue Dec 25, 2012 7:39 pm, edited 1 time in total.

nervlinux
Posts: 4
Joined: Tue Aug 28, 2012 5:19 am

Re: 16x2 no contrast help

Tue Dec 25, 2012 7:39 pm

It's lights up, but i don't see any white blocks. When i check pin 15,16 i get 4.53v. But for Vss and Vdd nothing, just 0. I don't have a 1W potentiometer or any resistor.

For power supply, i'm using blackberry playbook charger.

nervlinux
Posts: 4
Joined: Tue Aug 28, 2012 5:19 am

Re: 16x2 no contrast help

Tue Dec 25, 2012 8:08 pm

I did what g4eml said and it work. :D Now i see the white blocks and my potentiometer is working.

Now for code, when i try to run the code (sudo ./Adafruit_CharLCD.py)
I get this

Code: Select all

./Adafruit_CharLCD.py:68: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
  self.GPIO.setup(self.pin_e, GPIO.OUT)
./Adafruit_CharLCD.py:69: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
  self.GPIO.setup(self.pin_rs, GPIO.OUT)
./Adafruit_CharLCD.py:72: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
  self.GPIO.setup(pin, GPIO.OUT)
OS: Wheezy (update)


@bgreat

Now i get volt ready for Vss and Vdd 4.54v. For Vo the same 4.54v.

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: 16x2 no contrast help

Tue Dec 25, 2012 8:54 pm

Ah! A split bus on the power definitely explains it. Probably why the red and blue lines have a break. :D
Today is a good day... I have learned something.

The warning messages can be ignored provided you have no other application running using the GPIO. The messages should not be displayed the first time you run the application after booting. They are displayed subsequently because the AdaFruit_CharLCD.py application does not set the GPIO's as unused when it is exited.

When the program exits, there should be a call to GPIO.cleanup() to reset the GPIO's. Not necessary, but will prevent warnings from the next invocation.

If the LCD is still not displaying correctly, confirm that the GPIO pins are set correctly for your model of Raspberry Pi. You can find the GPIO list as pin_rs, pin_e, and pins_db in AdaFruit_CharLCD.py.

For Rev 1:

Code: Select all

    def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, 21, 22], GPIO = None):
For Rev 2:

Code: Select all

    def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, 27, 22], GPIO = None):
Enjoy!
Bill

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: 16x2 no contrast help

Tue Dec 25, 2012 9:21 pm

If you want to catch the program exit and call GPIO.cleanup() automatically, the following can be added to the program file:

Code: Select all

import atexit

def exit_handler():
    print 'Exiting. Calling GPIO.cleanup().'
    GPIO.cleanup()

atexit.register(exit_handler)
Enjoy!
Bill

nervlinux
Posts: 4
Joined: Tue Aug 28, 2012 5:19 am

Re: 16x2 no contrast help

Tue Dec 25, 2012 11:09 pm

thats why its not working, my raspberry pi is a rev1. so i just change 27 back to 21 and it works :lol:

thanks guys for help!!! :D :D :D

Image

SteveL89
Posts: 32
Joined: Sun Dec 30, 2012 3:20 pm

Re: 16x2 no contrast help

Sun Dec 30, 2012 3:26 pm

Bill,

I tried to add the code to force a GPIO.cleanup() at the end of the Adafruit_CharLCD.py program. No joy.

I get the same "channel in use" warnings (whether the cobbler is connected or not) and in addition I get error warnings for your code as follows:

NameError: global name 'GPIO' is not defined

Also, if I disable the warnings, the LCD still does not display a message. I have checked and rechecked the wiring and I have a v2 Pi so I changed the 21 to a 27. Any help would be appreciated.

Best,

Steve

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: 16x2 no contrast help

Sun Dec 30, 2012 5:56 pm

Steve,

The GPIO library needs to be available, otherwise the code can not be run. Add the following import line:

Code: Select all

import RPi.GPIO as GPIO
That will correct the NameError you are receiving and then you should not have the in use warnings either.


Enjoy!
Bill

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: 16x2 no contrast help

Sun Dec 30, 2012 6:17 pm

Steve,

If you do 'cat /proc/cpuinfo' what is shown for "Revision" ? Just to confirm the hardware version.

Enjoy!
Bill

SteveL89
Posts: 32
Joined: Sun Dec 30, 2012 3:20 pm

Re: 16x2 no contrast help

Sun Dec 30, 2012 9:03 pm

bgreat wrote:Steve,

If you do 'cat /proc/cpuinfo' what is shown for "Revision" ? Just to confirm the hardware version.

Enjoy!
Bill
Revision says 000f

Steve

SteveL89
Posts: 32
Joined: Sun Dec 30, 2012 3:20 pm

Re: 16x2 no contrast help

Sun Dec 30, 2012 9:15 pm

bgreat wrote:Steve,

The GPIO library needs to be available, otherwise the code can not be run. Add the following import line:

Code: Select all

import RPi.GPIO as GPIO
That will correct the NameError you are receiving and then you should not have the in use warnings either.




Enjoy!
Bill


That corrected the warning messages, but I am still not getting text on the LCD. Here is the code that came with the tutorial:

Code: Select all

#!/usr/bin/python

#
# based on code from lrvick and LiquidCrystal
# lrvic - https://github.com/lrvick/raspi-hd44780/blob/master/hd44780.py
# LiquidCrystal - https://github.com/arduino/Arduino/blob/master/libraries/LiquidCrystal/LiquidCrystal.cpp
#



from time import sleep



class Adafruit_CharLCD:

    # 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

    # 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


    
    def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, 27, 22], GPIO = None):
	# Emulate the old behavior of using RPi.GPIO if we haven't been given
	# an explicit GPIO interface to use
	if not GPIO:
	    import RPi.GPIO as GPIO
	   
        GPIO.setwarnings(False)
   	self.GPIO = GPIO
        self.pin_rs = pin_rs
        self.pin_e = pin_e
        self.pins_db = pins_db

        self.GPIO.setmode(GPIO.BCM)
        self.GPIO.setup(self.pin_e, GPIO.OUT)
        self.GPIO.setup(self.pin_rs, GPIO.OUT)

        for pin in self.pins_db:
            self.GPIO.setup(pin, GPIO.OUT)

	self.write4bits(0x33) # initialization
	self.write4bits(0x32) # initialization
	self.write4bits(0x28) # 2 line 5x7 matrix
	self.write4bits(0x0C) # turn cursor off 0x0E to enable cursor
	self.write4bits(0x06) # shift cursor right

	self.displaycontrol = self.LCD_DISPLAYON | self.LCD_CURSOROFF | self.LCD_BLINKOFF

	self.displayfunction = self.LCD_4BITMODE | self.LCD_1LINE | self.LCD_5x8DOTS
	self.displayfunction |= self.LCD_2LINE

	""" Initialize to default text direction (for romance languages) """
	self.displaymode =  self.LCD_ENTRYLEFT | self.LCD_ENTRYSHIFTDECREMENT
	self.write4bits(self.LCD_ENTRYMODESET | self.displaymode) #  set the entry mode

        self.clear()


    def begin(self, cols, lines):

	if (lines > 1):
		self.numlines = lines
    		self.displayfunction |= self.LCD_2LINE
		self.currline = 0


    def home(self):

	self.write4bits(self.LCD_RETURNHOME) # set cursor position to zero
	self.delayMicroseconds(3000) # this command takes a long time!
	

    def clear(self):

	self.write4bits(self.LCD_CLEARDISPLAY) # command to clear display
	self.delayMicroseconds(3000)	# 3000 microsecond sleep, clearing the display takes a long time


    def setCursor(self, col, row):

	self.row_offsets = [ 0x00, 0x40, 0x14, 0x54 ]

	if ( row > self.numlines ): 
		row = self.numlines - 1 # we count rows starting w/0

	self.write4bits(self.LCD_SETDDRAMADDR | (col + self.row_offsets[row]))


    def noDisplay(self): 
	""" Turn the display off (quickly) """

	self.displaycontrol &= ~self.LCD_DISPLAYON
	self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol)


    def display(self):
	""" Turn the display on (quickly) """

	self.displaycontrol |= self.LCD_DISPLAYON
	self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol)


    def noCursor(self):
	""" Turns the underline cursor on/off """

	self.displaycontrol &= ~self.LCD_CURSORON
	self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol)


    def cursor(self):
	""" Cursor On """

	self.displaycontrol |= self.LCD_CURSORON
	self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol)


    def noBlink(self):
	""" Turn on and off the blinking cursor """

	self.displaycontrol &= ~self.LCD_BLINKON
	self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol)


    def noBlink(self):
	""" Turn on and off the blinking cursor """

	self.displaycontrol &= ~self.LCD_BLINKON
	self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol)


    def DisplayLeft(self):
	""" These commands scroll the display without changing the RAM """

	self.write4bits(self.LCD_CURSORSHIFT | self.LCD_DISPLAYMOVE | self.LCD_MOVELEFT)


    def scrollDisplayRight(self):
	""" These commands scroll the display without changing the RAM """

	self.write4bits(self.LCD_CURSORSHIFT | self.LCD_DISPLAYMOVE | self.LCD_MOVERIGHT);


    def leftToRight(self):
	""" This is for text that flows Left to Right """

	self.displaymode |= self.LCD_ENTRYLEFT
	self.write4bits(self.LCD_ENTRYMODESET | self.displaymode);


    def rightToLeft(self):
	""" This is for text that flows Right to Left """
	self.displaymode &= ~self.LCD_ENTRYLEFT
	self.write4bits(self.LCD_ENTRYMODESET | self.displaymode)


    def autoscroll(self):
	""" This will 'right justify' text from the cursor """

	self.displaymode |= self.LCD_ENTRYSHIFTINCREMENT
	self.write4bits(self.LCD_ENTRYMODESET | self.displaymode)


    def noAutoscroll(self): 
	""" This will 'left justify' text from the cursor """

	self.displaymode &= ~self.LCD_ENTRYSHIFTINCREMENT
	self.write4bits(self.LCD_ENTRYMODESET | self.displaymode)


    def write4bits(self, bits, char_mode=False):
        """ Send command to LCD """

	self.delayMicroseconds(1000) # 1000 microsecond sleep

        bits=bin(bits)[2:].zfill(8)

        self.GPIO.output(self.pin_rs, char_mode)

        for pin in self.pins_db:
            self.GPIO.output(pin, False)

        for i in range(4):
            if bits[i] == "1":
                self.GPIO.output(self.pins_db[::-1][i], True)

	self.pulseEnable()

        for pin in self.pins_db:
            self.GPIO.output(pin, False)

        for i in range(4,8):
            if bits[i] == "1":
                self.GPIO.output(self.pins_db[::-1][i-4], True)

	self.pulseEnable()


    def delayMicroseconds(self, microseconds):
	seconds = microseconds / float(1000000)	# divide microseconds by 1 million for seconds
	sleep(seconds)


    def pulseEnable(self):
	self.GPIO.output(self.pin_e, False)
	self.delayMicroseconds(1)		# 1 microsecond pause - enable pulse must be > 450ns 
	self.GPIO.output(self.pin_e, True)
	self.delayMicroseconds(1)		# 1 microsecond pause - enable pulse must be > 450ns 
	self.GPIO.output(self.pin_e, False)
	self.delayMicroseconds(1)		# commands need > 37us to settle


    def message(self, text):
        """ Send string to LCD. Newline wraps to second line"""

        for char in text:
            if char == '\n':
                self.write4bits(0xC0) # next line
            else:
                self.write4bits(ord(char),True)


if __name__ == '__main__':
        
        lcd = Adafruit_CharLCD()

        lcd.clear()
        lcd.message("  Adafruit 16x2\n  Standard LCD")

import atexit
import RPi.GPIO as GPIO
def exit_handler():
    print 'Exiting.  Calling GPIO.cleanup().'
    GPIO.cleanup()

atexit.register(exit_handler)

again thanks for your help!!

Steve

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: 16x2 no contrast help

Mon Dec 31, 2012 4:13 am

Steve,

The "atexit" code should be at the top of the file to be fully effective. You want the handler to be set up before any other code.

Also... I made an error on the Rev. 2 change. :oops: It is not necessary. The GPIO module is using the physical pin numbers of the header. So the "27" needs changed back to "21". Sorry...
Should be the original:

Code: Select all

    def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, 21, 22], GPIO = None):
I was thinking in terms of the Raspberry PI physical change with the hardware update and overlooked the GPIO code use of the physical pin reference mode. Change this back and it should be working for you. If not, I can only think to confirm that pin 5 (R/W) of the display is connected to ground.

Enjoy!
Bill

SteveL89
Posts: 32
Joined: Sun Dec 30, 2012 3:20 pm

Re: 16x2 no contrast help

Mon Dec 31, 2012 5:25 am

IMG_0508.JPG
IMG_0508.JPG (55.89 KiB) Viewed 6990 times
Bill,

Thanks again for your help. I changed 27 back to 21 and moved the atexit routine to the top of the file. I also made sure pin 5 on the LCD was wired to ground. Still no message appears on the LCD. Attached are two photos, one of the wired circuit and the other the screen lighting up.

At least I am no longer getting the channel busy error.

Steve
Attachments
IMG_0509.JPG
IMG_0509.JPG (48.51 KiB) Viewed 6990 times

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: 16x2 no contrast help

Mon Dec 31, 2012 11:54 am

Steve,

The photos are a little small to accurately trace the wires, but the wiring appears to match the AdaFruit example. And the 21/27 issue has been tried in both modes.

When you adjust the variable resistor, does the contrast change for the row of solid blocks on the first line? Just to confirm your LCD is a standard configuration.

Are you running the latest Raspbian? Just to make certain it is not an issue addressed by a code update.

Enjoy!
Bill

SteveL89
Posts: 32
Joined: Sun Dec 30, 2012 3:20 pm

Re: 16x2 no contrast help

Mon Dec 31, 2012 2:28 pm

bgreat wrote:Steve,

The photos are a little small to accurately trace the wires, but the wiring appears to match the AdaFruit example. And the 21/27 issue has been tried in both modes.

When you adjust the variable resistor, does the contrast change for the row of solid blocks on the first line? Just to confirm your LCD is a standard configuration.

Are you running the latest Raspbian? Just to make certain it is not an issue addressed by a code update.

Enjoy!
Bill

Bill,

Yes, the contrast for the first line changes when I adjust the variable resistor. I am running a Raspbian build from October because I was have Bluetooth issues with the December build. I will prepare an SD with the most recent build just to rule that in or out and report back.

Thanks again for your advice.

Steve

SteveL89
Posts: 32
Joined: Sun Dec 30, 2012 3:20 pm

Re: 16x2 no contrast help (solved)

Mon Dec 31, 2012 4:52 pm

Bill,

I did a fresh install of the 12-16-2012 Distro of Raspberry Wheezy and reinstalled all programs for GPIO as per the tutorial. I even tried a second Pi (I have one set up as a media center).

Still no words printed out on the LCD.

Steve

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: 16x2 no contrast help (solved)

Tue Jan 01, 2013 2:50 am

Steve,

I'm out for New Year. I'll post a simple test you can do to confirm the GPIO is working correctly. Since hour wiring appears correct, you either have a bad interconnect or display.

Happy New Year!

Enjoy!
Bill

SteveL89
Posts: 32
Joined: Sun Dec 30, 2012 3:20 pm

Re: 16x2 no contrast help (solved)

Tue Jan 01, 2013 2:17 pm

bgreat wrote:Steve,

I'm out for New Year. I'll post a simple test you can do to confirm the GPIO is working correctly. Since hour wiring appears correct, you either have a bad interconnect or display.

Happy New Year!

Enjoy!
Bill

Thanks Bill. Happy New Year.

Steve

SteveL89
Posts: 32
Joined: Sun Dec 30, 2012 3:20 pm

Re: 16x2 no contrast help (solved)

Tue Jan 01, 2013 5:36 pm

Bill,

Happy New Year, it works!!

I made an LED board and tested the wiring to the LEDs using the python script and I was able to light the LEDs so I knew the GPIO leads and the program itself were working. That left the LCD. I checked the solder connections for the pins and redid some of them and low and behold it works. Chalk it up to my questionable soldering technique.

Anyway, thanks for your advice. You enabled me to eliminate the channel busy errors and got me thinking in a systematic troubleshooting frame of mind.

Best for the New Year.

Steve

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: 16x2 no contrast help (solved)

Tue Jan 01, 2013 8:18 pm

Steve,

Great to know it is working. Cold solder joints can be problematic. Good job tracking it down. I was going to suggest the resistor and LED route for testing, but was not certain if you would have the hardware. I tested an alternative using the contrast input pin as a test pin. Toggling a GPIO line connected to the contrast input between low and high makes an easily visible indicator. I even wrote some python code to take the pin number from the command line and toggle the GPIO line to test. :) . I'll save it for future use.

Enjoy!
Bill

Return to “Other projects”