Z-0235

From 52Pi Wiki
Jump to navigation Jump to search

2004 Serial LCD Module Display

Description

The LCD has always been a device that acts as a window in human-computer interaction.
For example, the prompt window on some instrument devices, the temperature and humidity prompt box,
the device running status monitor, and the prompt screen of the counting device all have LCD figures.
The common LCD1602, LCD2004, and LCD12864 are fabricated using liquid crystal materials and communicated using the I2C bus.
It is a high-performance serial bus with bus rules and high-speed or low-speed device synchronization required for multi-master systems.
The I2C bus has only two bidirectional signal lines, a serial data line (SDA) and a serial clock line (SCL).
Compatible with all devices with I2C interfaces, such as Arduino, raspberry pi, beagle bone black, tinker board, stm32, esp32 and more.

Features

  • 20 Characters * 4 Lines, Character LCD module
  • Blue Backlight
  • 5V for Logic Circuit
  • Low power consumption
  • Support I2C protocol
  • Easy to use
  • Compatible with Raspberry Pi, banana Pi, Tinker Board, STM32, ESP32 etc.
  • Type: Chip On Board
  • Number of Data line: 8-bit parallel

How to assemble it to Raspberry Pi

  • LCD2004 communicates with Raspberry Pi via I2C protocol.
  • Connect LCD2004 module to Raspberry Pi as following picture:
I2C LCD2004 Raspberry Pi
GND GND
VCC 5V
SDA SDA
SCL SCL
LCDGPIO.png


Demo code

  • Raspberry Pi

Open a terminal and typing following command:
sudo apt-get update
sudo apt-get upgrade
sudo raspi-config
Navigate to "Interface Option" and select "i2c" and enable it.
And then download python-liquidcrystal_i2c/archive/master.zip and install it to Raspberry Pi as following command:
python -m easy_install --user https://github.com/pl31/python-liquidcrystal_i2c/archive/master.zip
Copy and paste following code to a file named lcd2004.py:

#!/usr/bin/env python
"""first please add python library via this command: python -m easy_install --user https://github.com/pl31/python-liquidcrystal_i2c/archive/master.zip """
import socket
import os.path
import sys
import struct
import fcntl
import os
import time
import liquidcrystal_i2c
efg = "0"
wfg = "0"
lcd = liquidcrystal_i2c.LiquidCrystal_I2C(0x27, 1, numlines=4)
PATH1="/sys/class/net/eth0/carrier"
PATH2 = "/sys/class/net/wlan0/carrier"
def getserial():
    snm = "0000000000000000"
    try:
        f = open('/proc/cpuinfo','r')
        for line in f:
            if line[0:6]=='Serial':
                snm = line[10:26]
        f.close()
    except:
        snm = "ERROR"
    return snm

def getip(ifname):
    tt=0
    while tt<100:
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            return socket.inet_ntoa(fcntl.ioctl(s.fileno(),0x8915,struct.pack('256s',ifname[:15]))[20:24])
        except:
            tt+=1
            time.sleep(1)
            if(tt>99):
                return('ERROR')
time.sleep(15)
pstr= 'SN:'+getserial()
lcd.printline(0,pstr)
pstr = 'HN:'+socket.gethostname()
lcd.printline(1,pstr)
if os.path.isfile(PATH1) and os.access(PATH1, os.R_OK):
    efg = open(PATH1).read()
    pstr = 'EM:'+open('/sys/class/net/eth0/address').read()
    pstr = pstr.strip('\n')
    lcd.printline(2,pstr)
    if efg[0]=="1":
        pstr='EIP:'+str(getip('eth0'))
        lcd.printline(3,pstr)
    elif os.path.isfile(PATH2) and os.access(PATH2, os.R_OK):
        wfg = open(PATH2).read()
        pstr="WM:"+open('/sys/class/net/wlan0/address').read()
        pstr = pstr.strip('\n')
        lcd.printline(2,pstr)
        if wfg[0]=="1":
            pstr="WIP:"+str(getip('wlan0'))
            lcd.printline(3,pstr)

save it and run it.
python lcd2004.py

Lcd2004 demo1.jpg


  • Arduino

Keywords

LCD2004, liquid crystal Display, Raspberry Pi display, i2c protocol display, LCD