LCD (20x4 made in China)
Moderator: leecollings
-
- Posts: 251
- Joined: Friday 12 July 2013 13:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: The Netherlands
- Contact:
Re: LCD (20x4 made in China)
If you followed the instruction on Ge Janssen's website make sure you change the port address in lcd_display.py to 0x27.
The scripts attached to this post already have these modifications.
The scripts attached to this post already have these modifications.
-
- Posts: 8
- Joined: Friday 03 April 2015 15:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Netherlands
- Contact:
Re: LCD (20x4 made in China)
Hi there,
I have checked my wiring, changing then causes me an error, so the wiring is correct.
Maybe my lcd is different....
I tried the standard settings and also your script...
regards...
I have checked my wiring, changing then causes me an error, so the wiring is correct.
Maybe my lcd is different....
I tried the standard settings and also your script...
regards...
- Attachments
-
- IMG_20150617_182348.jpg (75.7 KiB) Viewed 7611 times
-
- Posts: 251
- Joined: Friday 12 July 2013 13:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: The Netherlands
- Contact:
LCD (20x4 made in China)
Did you use the 5v of 3,3v wireing diagram.? Please post a picture. Also please post the output of all steps AD described in Ge's howto and post your code
-
- Posts: 8
- Joined: Friday 03 April 2015 15:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Netherlands
- Contact:
Re: LCD (20x4 made in China)
Hi pepijn,
here's my py script:
from lcd_display import lcd
my_lcd = lcd()
my_lcd.display_string("Hello World", 1)
lcd.py:
import i2c_lib
from time import sleep
# LCD Address
ADDRESS = 0x27
# 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:
"""
Class to control the 16x2 I2C LCD display from sainsmart from the Raspberry Pi
"""
def __init__(self):
"""Setup the display, turn on backlight and text display + ...?"""
self.device = i2c_lib.i2c_device(ADDRESS,1)
self.write(0x03)
self.write(0x03)
self.write(0x03)
self.write(0x02)
self.write(LCD_FUNCTIONSET | LCD_2LINE | LCD_5x8DOTS | LCD_4BITMODE)
self.write(LCD_DISPLAYCONTROL | LCD_DISPLAYON)
self.write(LCD_CLEARDISPLAY)
self.write(LCD_ENTRYMODESET | LCD_ENTRYLEFT)
sleep(0.2)
def strobe(self, data):
"""clocks EN to latch command"""
self.device.write_cmd(data | En | LCD_BACKLIGHT)
sleep(0.0005)
self.device.write_cmd(((data & ~En) | LCD_BACKLIGHT))
sleep(0.001)
def write_four_bits(self, data):
self.device.write_cmd(data | LCD_BACKLIGHT)
self.strobe(data)
def write(self, cmd, mode=0):
"""write a command to lcd"""
self.write_four_bits(mode | (cmd & 0xF0))
self.write_four_bits(mode | ((cmd << 4) & 0xF0))
def display_string(self, string, line):
"""display a string on the given line of the display, 1 or 2, string is truncated to 16 chars and centred"""
centered_string = string.center(16)
if line == 1:
self.write(0x80)
if line == 2:
self.write(0xC0)
if line == 3:
self.write(0x94)
if line == 4:
self.write(0xD4)
for char in centered_string:
self.write(ord(char), Rs)
def clear(self):
"""clear lcd and set to home"""
self.write(LCD_CLEARDISPLAY)
self.write(LCD_RETURNHOME)
def backlight_off(self):
"""turn off backlight, anything that calls write turns it on again"""
self.device.write_cmd(LCD_NOBACKLIGHT)
def display_off(self):
"""turn off the text display"""
self.write(LCD_DISPLAYCONTROL | LCD_DISPLAYOFF)
def display_on(self):
"""turn on the text display"""
self.write(LCD_DISPLAYCONTROL | LCD_DISPLAYON)
wired like AD told with the 5 volt diagram
output on putty:
pi@raspberrypi ~/domoticz/scripts/lcd $ sudo 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: -- -- -- -- -- -- -- --
changing the sda an scl gives me this:
pi@raspberrypi ~/domoticz/scripts/lcd $ sudo python lcd_test.py
Traceback (most recent call last):
File "lcd_test.py", line 3, in <module>
my_lcd = lcd()
File "/home/pi/domoticz/scripts/lcd/lcd_display.py", line 62, in __init__
self.write(0x03)
File "/home/pi/domoticz/scripts/lcd/lcd_display.py", line 86, in write
self.write_four_bits(mode | (cmd & 0xF0))
File "/home/pi/domoticz/scripts/lcd/lcd_display.py", line 81, in write_four_bits
self.device.write_cmd(data | LCD_BACKLIGHT)
File "/home/pi/domoticz/scripts/lcd/i2c_lib.py", line 11, in write_cmd
self.bus.write_byte(self.addr, cmd)
IOError: [Errno 5] Input/output error
pi@raspberrypi ~/domoticz/scripts/lcd $
changing them back gives me this:
pi@raspberrypi ~/domoticz/scripts/lcd $ sudo python lcd_test.py
pi@raspberrypi ~/domoticz/scripts/lcd $
but no text on the screen.......
regards
here's my py script:
from lcd_display import lcd
my_lcd = lcd()
my_lcd.display_string("Hello World", 1)
lcd.py:
import i2c_lib
from time import sleep
# LCD Address
ADDRESS = 0x27
# 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:
"""
Class to control the 16x2 I2C LCD display from sainsmart from the Raspberry Pi
"""
def __init__(self):
"""Setup the display, turn on backlight and text display + ...?"""
self.device = i2c_lib.i2c_device(ADDRESS,1)
self.write(0x03)
self.write(0x03)
self.write(0x03)
self.write(0x02)
self.write(LCD_FUNCTIONSET | LCD_2LINE | LCD_5x8DOTS | LCD_4BITMODE)
self.write(LCD_DISPLAYCONTROL | LCD_DISPLAYON)
self.write(LCD_CLEARDISPLAY)
self.write(LCD_ENTRYMODESET | LCD_ENTRYLEFT)
sleep(0.2)
def strobe(self, data):
"""clocks EN to latch command"""
self.device.write_cmd(data | En | LCD_BACKLIGHT)
sleep(0.0005)
self.device.write_cmd(((data & ~En) | LCD_BACKLIGHT))
sleep(0.001)
def write_four_bits(self, data):
self.device.write_cmd(data | LCD_BACKLIGHT)
self.strobe(data)
def write(self, cmd, mode=0):
"""write a command to lcd"""
self.write_four_bits(mode | (cmd & 0xF0))
self.write_four_bits(mode | ((cmd << 4) & 0xF0))
def display_string(self, string, line):
"""display a string on the given line of the display, 1 or 2, string is truncated to 16 chars and centred"""
centered_string = string.center(16)
if line == 1:
self.write(0x80)
if line == 2:
self.write(0xC0)
if line == 3:
self.write(0x94)
if line == 4:
self.write(0xD4)
for char in centered_string:
self.write(ord(char), Rs)
def clear(self):
"""clear lcd and set to home"""
self.write(LCD_CLEARDISPLAY)
self.write(LCD_RETURNHOME)
def backlight_off(self):
"""turn off backlight, anything that calls write turns it on again"""
self.device.write_cmd(LCD_NOBACKLIGHT)
def display_off(self):
"""turn off the text display"""
self.write(LCD_DISPLAYCONTROL | LCD_DISPLAYOFF)
def display_on(self):
"""turn on the text display"""
self.write(LCD_DISPLAYCONTROL | LCD_DISPLAYON)
wired like AD told with the 5 volt diagram
output on putty:
pi@raspberrypi ~/domoticz/scripts/lcd $ sudo 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: -- -- -- -- -- -- -- --
changing the sda an scl gives me this:
pi@raspberrypi ~/domoticz/scripts/lcd $ sudo python lcd_test.py
Traceback (most recent call last):
File "lcd_test.py", line 3, in <module>
my_lcd = lcd()
File "/home/pi/domoticz/scripts/lcd/lcd_display.py", line 62, in __init__
self.write(0x03)
File "/home/pi/domoticz/scripts/lcd/lcd_display.py", line 86, in write
self.write_four_bits(mode | (cmd & 0xF0))
File "/home/pi/domoticz/scripts/lcd/lcd_display.py", line 81, in write_four_bits
self.device.write_cmd(data | LCD_BACKLIGHT)
File "/home/pi/domoticz/scripts/lcd/i2c_lib.py", line 11, in write_cmd
self.bus.write_byte(self.addr, cmd)
IOError: [Errno 5] Input/output error
pi@raspberrypi ~/domoticz/scripts/lcd $
changing them back gives me this:
pi@raspberrypi ~/domoticz/scripts/lcd $ sudo python lcd_test.py
pi@raspberrypi ~/domoticz/scripts/lcd $
but no text on the screen.......
regards
-
- Posts: 251
- Joined: Friday 12 July 2013 13:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: The Netherlands
- Contact:
Re: LCD (20x4 made in China)
I will try this on my setup tomorrow. Just to make sure, you only get a blue screen? (not black)
-
- Posts: 8
- Joined: Friday 03 April 2015 15:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Netherlands
- Contact:
Re: LCD (20x4 made in China)
Jep just blue....
Regards
Regards
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: LCD (20x4 made in China)
I'm getting the same problem. I've wired in an i2c level converter, so that the i2c signals are at 5V.
I'm confident that the display is interfaced OK, as I can turn the display off and on with the following:
I'm confident that the display is interfaced OK, as I can turn the display off and on with the following:
Code: Select all
sudo python
>>> from lcd_display import lcd
>>> lcd = lcd()
>>> lcd.display_off()
>>> lcd.display_on()
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: LCD (20x4 made in China)
Fixed it by adjusting contrast control!!! (blue pot on daughter board)
-
- Posts: 8
- Joined: Friday 03 April 2015 15:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Netherlands
- Contact:
Re: LCD (20x4 made in China)
MikeF you are the man !!!!!
Works fine now seeing hello world, now let's use the right script....
Works fine now seeing hello world, now let's use the right script....
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: LCD (20x4 made in China)
Good luck!
I've adapted pepijn's 'lcd' script for my own Domoticz devices, added a fifth screen for internal temperature sensors, and translated some of the display strings!
I've adapted pepijn's 'lcd' script for my own Domoticz devices, added a fifth screen for internal temperature sensors, and translated some of the display strings!
-
- Posts: 251
- Joined: Friday 12 July 2013 13:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: The Netherlands
- Contact:
Re: LCD (20x4 made in China)
Have fun
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: LCD (20x4 made in China)
For anyone else considering this, it's worth pointing out that there are 2 main versions of this display available on eBay: one with the 'daughterboard' on the back (as in the photo in Marius' earlier post), and one without - look carefully at the eBay photos. To follow this thread, you need the one with the daughterboard: it provides the i2c connection, as well as a contrast control (which enabled Marius and me to see the display!).
Also, the address (as used on line 5 of lcd_display.py) may be either 0x27 or 0x3F, depending on the chip used. Just type 'sudo i2detect -y 1' (or 'sudo i2cdetect -y 0' for a RPi B Rev1), and see what address is displayed (assuming you have no other i2c devices connected).
I followed the tutorial here: http://www.gejanssen.com/howto/i2c_disp ... index.html (translated!), and connected in a level converter as shown in the second wiring diagram - this brings the SCL & SDA signals up to 5V from the 3.3V level on the RPi. You may not need this, but I haven't tried without.
Hope this helps.
Also, the address (as used on line 5 of lcd_display.py) may be either 0x27 or 0x3F, depending on the chip used. Just type 'sudo i2detect -y 1' (or 'sudo i2cdetect -y 0' for a RPi B Rev1), and see what address is displayed (assuming you have no other i2c devices connected).
I followed the tutorial here: http://www.gejanssen.com/howto/i2c_disp ... index.html (translated!), and connected in a level converter as shown in the second wiring diagram - this brings the SCL & SDA signals up to 5V from the 3.3V level on the RPi. You may not need this, but I haven't tried without.
Hope this helps.
-
- Posts: 251
- Joined: Friday 12 July 2013 13:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: The Netherlands
- Contact:
Re: LCD (20x4 made in China)
Nice addition! Feel free to post a video with your results.
-
- Posts: 8
- Joined: Friday 03 April 2015 15:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Netherlands
- Contact:
Re: LCD (20x4 made in China)
Alright,
insert the python code made by pepijn, all I see is two white lines,
question:
# Configuratie
cfgDomoticzHost = ""
cfgSpeed = 4
what to enter by cfgDomoticzHost ? just the IP adres or Ipadres:8080?
Regards
insert the python code made by pepijn, all I see is two white lines,
question:
# Configuratie
cfgDomoticzHost = ""
cfgSpeed = 4
what to enter by cfgDomoticzHost ? just the IP adres or Ipadres:8080?
Regards
-
- Posts: 251
- Joined: Friday 12 July 2013 13:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: The Netherlands
- Contact:
LCD (20x4 made in China)
Add IP:8080 if using the default port, also change the sensor IDX Numbers, search for get_domoticz_sensor
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: LCD (20x4 made in China)
pepijn said:
Had some problems producing a video, so have attached some stills instead.Feel free to post a video with your results.
- Attachments
-
- LCD.zip
- (133.44 KiB) Downloaded 258 times
-
- Posts: 58
- Joined: Monday 26 May 2014 10:18
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: LCD (20x4 made in China)
Very cool
I ordered a display and I received it. But, I have also A Piface on top of the Raspberry and a PicoUPS, how should I connect it? Just the cabling to the I2C Connector and that's it?
I ordered a display and I received it. But, I have also A Piface on top of the Raspberry and a PicoUPS, how should I connect it? Just the cabling to the I2C Connector and that's it?
-
- Posts: 58
- Joined: Monday 26 May 2014 10:18
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: LCD (20x4 made in China)
I soldered the connections on top of my PiFace and works perfectly
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: LCD (20x4 made in China)
I've modified my Python script, so that I am now pulling in data from a range of devices via Domoticz. Below are some screenshots:
I've also mounted the display and the RPi driving it inside a (Hammond translucent) box; with a WiFi dongle plugged in, the only external wiring is the USB power cable.
I've also mounted the display and the RPi driving it inside a (Hammond translucent) box; with a WiFi dongle plugged in, the only external wiring is the USB power cable.
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: LCD (20x4 made in China)
I've attached my code below.
The values in the get_domoticz_sensor() calls are the idx's of my various Domoticz devices (I know, I should have parameterised these!).
Obviously this can be customised / simplified, to have fewer / more devices and screens.
The values in the get_domoticz_sensor() calls are the idx's of my various Domoticz devices (I know, I should have parameterised these!).
Obviously this can be customised / simplified, to have fewer / more devices and screens.
- Attachments
-
- lcd.zip
- (1.66 KiB) Downloaded 585 times
Who is online
Users browsing this forum: Google [Bot] and 1 guest