Rezendes
Posts: 12
Joined: Sat May 25, 2013 11:53 pm

Re: Python driving 44870 LCD

Mon May 27, 2013 7:53 pm

So, I grounded all the db0-db3 pins and still nothing... This is so frustrating, every time I run all these python code examples I get nothing and just see that horrible row of black bars that tells me the lcd is working on some level but who knows what the hell I'm doing wrong.

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

Re: Python driving 44870 LCD

Mon May 27, 2013 7:58 pm

I know it is frustrating. The single row of blocks shows as soon as power is applied and unless it gets a valid initialisation sequence, that is all it will show. Show us the complete code and wiring diagram.
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

Rezendes
Posts: 12
Joined: Sat May 25, 2013 11:53 pm

Re: Python driving 44870 LCD

Wed May 29, 2013 5:14 am

I am about to buy another LCD to test and make sure it's not the LCD I have that's the problem. The image here for the wiring of this LCD http://www.amazon.com/microtivity-IM161 ... icrotivity suggests a Diode on pins 15 and 2 pointing towards 15... Do I need that? That seems to be power to the LCD and power to the Backlight, my backlight powers up and my contrast adjustment works with the single row of solid blocks on screen... what exactly is pin 2 providing power for on the LCD?

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

Re: Python driving 44870 LCD

Wed May 29, 2013 6:38 am

Dead amazon link here.
Pin 2 is usally the main (only) power to the LCD. pins 15/16 are for the backlight LED, depending if it is fitted.
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

Rezendes
Posts: 12
Joined: Sat May 25, 2013 11:53 pm

Re: Python driving 44870 LCD

Wed May 29, 2013 6:43 am

yeah, the url was shortened... I just searched for Micortivity 1602 lcd on amazon and it comes with 2 results and one of them if not both as the wiring diagram I was describing with the diode.

pixster
Posts: 12
Joined: Fri Aug 23, 2013 1:03 pm
Location: Cresscent City, CA USA
Contact: Website

Re: Python driving 44870 LCD

Wed Sep 11, 2013 7:15 pm

I'm new to Python. I DON'T understand "import". I know what it does, but I can't seem to find
anything on what the file looks like to "import". Is it a library or include file, and what extension
will it have?? So I DON'T know what to look for!

canibalimao
Posts: 557
Joined: Tue Aug 07, 2012 8:48 pm
Location: Portugal

Re: Python driving 44870 LCD

Thu Sep 12, 2013 9:31 am

pixster wrote:I'm new to Python. I DON'T understand "import". I know what it does, but I can't seem to find
anything on what the file looks like to "import". Is it a library or include file, and what extension
will it have?? So I DON'T know what to look for!
Let me see if I understand your question: you want to know what does each "impor" line do, right?

So lets start, with a very basic language:

Code: Select all

import RPi.GPIO as GPIO
This line imports the GPIO pinout configuration. Basically it let's you use functions like these:

Code: Select all

GPIO.setmode(GPIO.BCM)
GPIO.setup(24, GPIO.OUT)
GPIO.output(4, False)

Code: Select all

import time
This second imports all time-related functions and times for delays (in this particular script):

Code: Select all

time.sleep(0.01)
Hope this helped you.

Rasb_Newbe
Posts: 1
Joined: Fri Apr 11, 2014 3:21 pm

Re: Python driving 44870 LCD

Fri Apr 11, 2014 3:37 pm

Hi,
Please I am new to Raspberry Pi and Python programming. I just wanted to ask a few questions and make some observations. Thanks

1. Do I need the wiringpi to run the program you gave?
2. If yes or no, how do I run this program in raspberry pi?
3. I noticed that the GPIO and LCD pin allocations in the program did not match the one used in the figure above.
i.e # Define GPIO to LCD mapping

LCD_RS = 17
LCD_E = 4
LCD_D4 = 24
LCD_D5 = 22
LCD_D6 = 23
LCD_D7 = 21 # use 27 for v2 rpi, or 21 for v1 rpi
LCD_LED = 18

Thanks

User avatar
dbrgn
Posts: 19
Joined: Sat May 11, 2013 2:49 pm
Location: Switzerland
Contact: Website

Re: Python driving 44870 LCD

Sun Apr 20, 2014 12:09 am

Rasb_Newbe wrote:1. Do I need the wiringpi to run the program you gave?
On current versions of Raspbian, the RPi.GPIO library is already built-in, so you don't need to install anything.

Generally related to this topic, I also attempted to build a HD44780 Python library for the Raspberry Pi. Here's my result: https://github.com/dbrgn/RPLCD It supports various display sizes (16x2 and 20x4 are tested), features a clean, Pythonic API and supports both Python 2 and 3. It also provides test scripts to verify your wiring.

And here's how you can use it:

Code: Select all

$ sudo pip install RPLCD
$ python
Python 2.7.3 (default, Jan 2013, 11:20:46)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from RPLCD import CharLCD
>>> lcd = CharLCD()
>>> lcd.write_string(u'Raspberry Pi HD44780')
>>> lcd.cursor_pos = (2, 0)
>>> lcd.write_string(u'http://github.com/\n\rdbrgn/RPLCD')
Result:

Image

You could also write the Python code into a file with the extension .py and run it directly.

And here's a writeup on how to create scrolling text: https://blog.dbrgn.ch/2014/4/20/scrolli ... ith-rplcd/

canibalimao
Posts: 557
Joined: Tue Aug 07, 2012 8:48 pm
Location: Portugal

Re: Python driving 44870 LCD

Sun Apr 20, 2014 8:24 am

Excellent job! This will help a lot of newbies!

But there is two things I'm not figuring out and I think you can change that: where do we define the pins that we are using and the num of row the screen have? We need to go to the library and define that?
This is just one thing that you can improve, that's not an "error".

User avatar
dbrgn
Posts: 19
Joined: Sat May 11, 2013 2:49 pm
Location: Switzerland
Contact: Website

Re: Python driving 44870 LCD

Sun Apr 20, 2014 12:13 pm

canibalimao wrote:Excellent job! This will help a lot of newbies!
Thanks, I hope so :)
canibalimao wrote:But there is two things I'm not figuring out and I think you can change that: where do we define the pins that we are using and the num of row the screen have? We need to go to the library and define that?
This is just one thing that you can improve, that's not an "error".
That's very easy, simply pass them to the constructor, as documented in the README:

Code: Select all

import RPi.GPIO as GPIO
from RPLCD import CharLCD

# Initialize display. All values have default values and are therefore
# optional.
lcd = CharLCD(pin_rs=15, pin_rw=18, pin_e=16, pins_data=[21, 22, 23, 24],
              numbering_mode=GPIO.BOARD,
              cols=20, rows=4, dotsize=8)

...

# If desired, reset the GPIO configuration and optionally clear the screen.
# Note that this can lead to undesired effects on the LCD, because the GPIO
# pins are not configured as input or output anymore.
lcd.close(clear=True)
All the parameters are optional, the values in this example are the default values.

canibalimao
Posts: 557
Joined: Tue Aug 07, 2012 8:48 pm
Location: Portugal

Re: Python driving 44870 LCD

Sun Apr 20, 2014 1:45 pm

Oh sorry for the mistake. I haven't read the README file :oops: Being so, that's a perfect job! :mrgreen:

TwinyTwice
Posts: 24
Joined: Mon Sep 15, 2014 7:08 am
Location: France

Re: Python driving 44780 LCD

Wed Sep 24, 2014 2:26 am

Is it possible to set a standby for LCD (HD44780), if the RPi is not used for a while time (10 minutes for example)?

User avatar
DougieLawson
Posts: 35602
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Python driving 44780 LCD

Thu Sep 25, 2014 12:48 am

TwinyTwice wrote:Is it possible to set a standby for LCD (HD44780), if the RPi is not used for a while time (10 minutes for example)?
Not without adding some complex threaded code to your program. You'd need to set a ten minute timer thread running that would disable the backlight and reset the HD44780. You'd then need to change your code that writes new text on the screen to assume that the HD44780 is ALWAYS reset and the backlight is disabled (so it would need to run the initialisation and reset the ten minute counter every time you write something new).

Not easy.

And I can't see any other way to detect that the display has gone idle (unless you do some external magic with a 555 timer triggered from the clock/enable pin).
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

TwinyTwice
Posts: 24
Joined: Mon Sep 15, 2014 7:08 am
Location: France

Re: Python driving 44780 LCD

Thu Sep 25, 2014 1:07 am

Ok @DougieDawson, Hummmmm, and (forgive the newbie that i am) just by toggle the backlight ON/OFF !?

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

Re: Python driving 44780 LCD

Thu Sep 25, 2014 6:22 am

Depends on what you want by 'standby' - yes you can just toggle the backlight off, but that's all it will do - the LCD will still have TXT on it that can be seen, in daylight anyway.
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

ecotec
Posts: 64
Joined: Mon Jul 01, 2013 1:10 pm
Location: Norfolk

Re: Python driving 44780 LCD

Sun Dec 14, 2014 10:17 am

I looking to get one of these LCD screens to experiment with over xmas, will this shopping list include everything I need?

LCD HD44780 16x2
16 pin header socket
Breadboard
Male to female jumper wires
hook up wire
10k Ohm potentiometer
560 Ohm carbon resistor (0.25w)

Thanks,
b raspbian running get-iplayer and mini dlna server
b+ running volumio
pi 2 - dietpi - pihole, ssh and a few other bits

ecotec
Posts: 64
Joined: Mon Jul 01, 2013 1:10 pm
Location: Norfolk

Re: Python driving 44780 LCD

Mon Dec 15, 2014 7:20 pm

^
all ordered so we shall see, just one thing:

Seems to be a bit of discussion between the need for a 10k Ohm potentiometer and that a
560 Ohm carbon resistor (0.25w) is all that's needed - is this correct?

thanks,
b raspbian running get-iplayer and mini dlna server
b+ running volumio
pi 2 - dietpi - pihole, ssh and a few other bits

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

Re: Python driving 44780 LCD

Mon Dec 15, 2014 7:53 pm

What's the 570 ohm for? You will need the pot however.
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

ecotec
Posts: 64
Joined: Mon Jul 01, 2013 1:10 pm
Location: Norfolk

Re: Python driving 44780 LCD

Mon Dec 15, 2014 8:30 pm

Hi texy, apparently to prevent more than 5v getting to the back light, i'm guessing by your reply its not really needed?

also re the 10k pot, do I need to worry about the nominal power watt rating - will the 0.5w one i've ordered be OK?
b raspbian running get-iplayer and mini dlna server
b+ running volumio
pi 2 - dietpi - pihole, ssh and a few other bits

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

Re: Python driving 44780 LCD

Mon Dec 15, 2014 8:33 pm

The LCD will probbaly already have current limiting resistor onboard for the backlight - at least it has in my experience.
Any old pot will do for the contrast as well - the smallest trimpot has worked fine for me in the past.
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

ecotec
Posts: 64
Joined: Mon Jul 01, 2013 1:10 pm
Location: Norfolk

Re: Python driving 44780 LCD

Mon Dec 15, 2014 8:45 pm

Hi Texy
thanks very much for that
b raspbian running get-iplayer and mini dlna server
b+ running volumio
pi 2 - dietpi - pihole, ssh and a few other bits

hoatienii
Posts: 14
Joined: Fri Aug 09, 2013 9:04 am

Re: Python driving 44780 LCD

Thu Apr 23, 2015 1:31 am

Hi!
My Raspberry run Openwrt with python, I follows this http://www.raspberrypi-spy.co.uk/2012/0 ... ng-python/ and modify but can not display text on LCD :-)

Code: Select all

import sys
import time

# Define GPIO to LCD mapping
LCD_RS = 17
LCD_E  = 21
LCD_D4 = 22
LCD_D5 = 23
LCD_D6 = 24
LCD_D7 = 25

# Define some device constants
LCD_WIDTH = 16    # Maximum characters per line
LCD_CHR = 1
LCD_CMD = 0

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.0005
E_DELAY = 0.0005

def GPIO(gp, value):
        base = '/sys/class/gpio/'
        raw = str(gp)
        gpio_file = base + 'gpio' + raw + '/value'
        f = open(gpio_file, 'w')
        f.write(str(value))
        f.close()

def lcd_init():
  # Initialise display
  lcd_byte(0x33,LCD_CMD) # 110011 Initialise
  lcd_byte(0x32,LCD_CMD) # 110010 Initialise
  lcd_byte(0x06,LCD_CMD) # 000110 Cursor move direction
  lcd_byte(0x0C,LCD_CMD) # 001100 Display On,Cursor Off, Blink Off
  lcd_byte(0x28,LCD_CMD) # 101000 Data length, number of lines, font size
  lcd_byte(0x01,LCD_CMD) # 000001 Clear display
  time.sleep(E_DELAY)

def lcd_byte(bits, mode):
  # Send byte to data pins
  # bits = data
  # mode = True  for character
  #        False for command
 
  GPIO(LCD_RS, mode) # RS
 
  # High bits
  GPIO(LCD_D4, 0)
  GPIO(LCD_D5, 0)
  GPIO(LCD_D6, 0)
  GPIO(LCD_D7, 0)
  if bits&0x10==0x10:
    GPIO(LCD_D4, 1)
  if bits&0x20==0x20:
    GPIO(LCD_D5, 1)
  if bits&0x40==0x40:
    GPIO(LCD_D6, 1)
  if bits&0x80==0x80:
    GPIO(LCD_D7, 1)
 
  # Toggle 'Enable' pin
  lcd_toggle_enable()
 
  # Low bits
  GPIO(LCD_D4, 0)
  GPIO(LCD_D5, 0)
  GPIO(LCD_D6, 0)
  GPIO(LCD_D7, 0)
  if bits&0x01==0x01:
    GPIO(LCD_D4, 1)
  if bits&0x02==0x02:
    GPIO(LCD_D5, 1)
  if bits&0x04==0x04:
    GPIO(LCD_D6, 1)
  if bits&0x08==0x08:
    GPIO(LCD_D7, 1)
 
  # Toggle 'Enable' pin
  lcd_toggle_enable()
 
def lcd_toggle_enable():
  # Toggle enable
  time.sleep(E_DELAY)
  GPIO(LCD_E, 1)
  time.sleep(E_PULSE)
  GPIO(LCD_E, 0)
  time.sleep(E_DELAY)
 
def lcd_string(message,line):
  # Send string to display
 
  message = message.ljust(LCD_WIDTH," ")
 
  lcd_byte(line, LCD_CMD)
 
  for i in range(LCD_WIDTH):
    lcd_byte(ord(message[i]),LCD_CHR)

def main():
   
  # Initialise display
  lcd_init()
 
  while True:
 
    # Send some test
    lcd_string("Rasbperry Pi",LCD_LINE_1)
    lcd_string("16x2 LCD Test",LCD_LINE_2)
 
    time.sleep(3) # 3 second delay
 
    # Send some text
    lcd_string("1234567890123456",LCD_LINE_1)
    lcd_string("abcdefghijklmnop",LCD_LINE_2)
 
    time.sleep(3) # 3 second delay 

if __name__ == '__main__':
    main()
    

canibalimao
Posts: 557
Joined: Tue Aug 07, 2012 8:48 pm
Location: Portugal

Re: Python driving 44780 LCD

Thu Apr 23, 2015 8:35 am

Do you see the first line fill with black "characters" (16 vertical rectangles) when you power the LCD?
If not, thet's your problem. You must add a potentiometer to adjust the contrast on the screen.

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

Re: Python driving 44780 LCD

Thu Apr 23, 2015 12:33 pm

hoatienii wrote:Hi!
My Raspberry run Openwrt with python, I follows this http://www.raspberrypi-spy.co.uk/2012/0 ... ng-python/ and modify but can not display text on LCD :-)
Try increasing the timing constant values. Some screens are more sensitive to the values used :

For example :

Code: Select all

# Timing constants
E_PULSE = 0.001
E_DELAY = 0.001
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)

Return to “Python”