LCD (20x4 made in China)

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.
pepijn
Posts: 512
Joined: Friday 12 July 2013 13:19
Target OS: Raspberry Pi
Domoticz version:
Location: The Netherlands
Contact:

Re: LCD (20x4 made in China)

Post by pepijn » Tuesday 16 June 2015 20:27

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.

mariusvanderwerff
Posts: 8
Joined: Friday 03 April 2015 15:36
Target OS: Raspberry Pi
Domoticz version:
Location: Netherlands
Contact:

Re: LCD (20x4 made in China)

Post by mariusvanderwerff » Wednesday 17 June 2015 23:32

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...
Attachments
IMG_20150617_182348.jpg
IMG_20150617_182348.jpg (75.7 KiB) Viewed 4813 times

pepijn
Posts: 512
Joined: Friday 12 July 2013 13:19
Target OS: Raspberry Pi
Domoticz version:
Location: The Netherlands
Contact:

LCD (20x4 made in China)

Post by pepijn » Thursday 18 June 2015 0:33

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

mariusvanderwerff
Posts: 8
Joined: Friday 03 April 2015 15:36
Target OS: Raspberry Pi
Domoticz version:
Location: Netherlands
Contact:

Re: LCD (20x4 made in China)

Post by mariusvanderwerff » Friday 19 June 2015 0:36

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

pepijn
Posts: 512
Joined: Friday 12 July 2013 13:19
Target OS: Raspberry Pi
Domoticz version:
Location: The Netherlands
Contact:

Re: LCD (20x4 made in China)

Post by pepijn » Friday 19 June 2015 0:45

I will try this on my setup tomorrow. Just to make sure, you only get a blue screen? (not black)

mariusvanderwerff
Posts: 8
Joined: Friday 03 April 2015 15:36
Target OS: Raspberry Pi
Domoticz version:
Location: Netherlands
Contact:

Re: LCD (20x4 made in China)

Post by mariusvanderwerff » Friday 19 June 2015 1:03

Jep just blue....

Regards

MikeF
Posts: 242
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi
Domoticz version: V4.9700
Location: UK
Contact:

Re: LCD (20x4 made in China)

Post by MikeF » Saturday 20 June 2015 14:39

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:

Code: Select all

sudo python

>>> from lcd_display import lcd
>>> lcd = lcd()
>>> lcd.display_off()
>>> lcd.display_on()

MikeF
Posts: 242
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi
Domoticz version: V4.9700
Location: UK
Contact:

Re: LCD (20x4 made in China)

Post by MikeF » Saturday 20 June 2015 18:22

Fixed it by adjusting contrast control!!! (blue pot on daughter board)

mariusvanderwerff
Posts: 8
Joined: Friday 03 April 2015 15:36
Target OS: Raspberry Pi
Domoticz version:
Location: Netherlands
Contact:

Re: LCD (20x4 made in China)

Post by mariusvanderwerff » Sunday 21 June 2015 1:28

MikeF you are the man !!!!! :lol:

Works fine now seeing hello world, now let's use the right script....

MikeF
Posts: 242
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi
Domoticz version: V4.9700
Location: UK
Contact:

Re: LCD (20x4 made in China)

Post by MikeF » Sunday 21 June 2015 11:02

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!

pepijn
Posts: 512
Joined: Friday 12 July 2013 13:19
Target OS: Raspberry Pi
Domoticz version:
Location: The Netherlands
Contact:

Re: LCD (20x4 made in China)

Post by pepijn » Sunday 21 June 2015 11:07

Have fun

MikeF
Posts: 242
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi
Domoticz version: V4.9700
Location: UK
Contact:

Re: LCD (20x4 made in China)

Post by MikeF » Sunday 21 June 2015 18:29

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.

pepijn
Posts: 512
Joined: Friday 12 July 2013 13:19
Target OS: Raspberry Pi
Domoticz version:
Location: The Netherlands
Contact:

Re: LCD (20x4 made in China)

Post by pepijn » Sunday 21 June 2015 19:16

Nice addition! Feel free to post a video with your results.

mariusvanderwerff
Posts: 8
Joined: Friday 03 April 2015 15:36
Target OS: Raspberry Pi
Domoticz version:
Location: Netherlands
Contact:

Re: LCD (20x4 made in China)

Post by mariusvanderwerff » Monday 22 June 2015 22:50

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

pepijn
Posts: 512
Joined: Friday 12 July 2013 13:19
Target OS: Raspberry Pi
Domoticz version:
Location: The Netherlands
Contact:

LCD (20x4 made in China)

Post by pepijn » Tuesday 23 June 2015 0:04

Add IP:8080 if using the default port, also change the sensor IDX Numbers, search for get_domoticz_sensor

MikeF
Posts: 242
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi
Domoticz version: V4.9700
Location: UK
Contact:

Re: LCD (20x4 made in China)

Post by MikeF » Tuesday 23 June 2015 10:53

pepijn said:
Feel free to post a video with your results.
Had some problems producing a video, so have attached some stills instead.
Attachments
LCD.zip
(133.44 KiB) Downloaded 174 times

jadijkstra2000
Posts: 135
Joined: Monday 26 May 2014 10:18
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: LCD (20x4 made in China)

Post by jadijkstra2000 » Saturday 08 August 2015 13:03

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?

jadijkstra2000
Posts: 135
Joined: Monday 26 May 2014 10:18
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: LCD (20x4 made in China)

Post by jadijkstra2000 » Tuesday 18 August 2015 14:23

I soldered the connections on top of my PiFace and works perfectly :)

MikeF
Posts: 242
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi
Domoticz version: V4.9700
Location: UK
Contact:

Re: LCD (20x4 made in China)

Post by MikeF » Monday 26 October 2015 0:35

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:

Image

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.

Image

MikeF
Posts: 242
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi
Domoticz version: V4.9700
Location: UK
Contact:

Re: LCD (20x4 made in China)

Post by MikeF » Monday 26 October 2015 0:59

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.
Attachments
lcd.zip
(1.66 KiB) Downloaded 363 times

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests