Raspberry-LCD           

von Frank Behlich                

Elektronik-Labor  Projekte  Mikrocontroller  Raspberry     




Der Kapazitätsmesser/Temperaturmesser ist echt einfach und genial. Fehlt nur noch ein kleines Display. Die Ansteuerung ist nicht schwer. Eigentlich ist alles nur zusammengetragen und ein wenig umgeschrieben, damit die Handhabung einfacher wird. Alle Informationen findet man unter diesem Link:

http://ddi.uni-wuppertal.de/material/materialsammlung/mittelstufe/raspberry.html

Hier nach dem Display-PDF suchen, und in diesem gibt es noch einiges mehr an Informationen. Mein Display stammt von einem „Billigmessgerät“ aus dem großen Auktionshaus im Netz. Diese Displays sind Massenware und werden für 3-4 Euros verkauft. Pin 15 und 16 fallen bei mir weg, da bei meinem die Hintergrundbeleuchtung fehlt.

Update 3.10.15: Habe jetzt die Scripte aktualisiert und ein "turn out" eingefügt, damit es sich nach Beendigung des Scriptes ausschaltet.

Script für eine allgemeine Verwendung des Displays als Anzeige:

#gpio_display.py --> allgemeine Verwendung 
#! /usr/bin/env python
# -*- coding: utf-8

import time
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

DISPLAY_RS = 5
DISPLAY_E = 6
DISPLAY_DATA4 = 25
DISPLAY_DATA5 = 24
DISPLAY_DATA6 = 23
DISPLAY_DATA7 = 18

GPIO_OUT = [DISPLAY_DATA4, DISPLAY_DATA5, DISPLAY_DATA6, DISPLAY_DATA7]
GPIO_SETUP = list()
for gpio in GPIO_OUT:
GPIO_SETUP.append(gpio)
for gpio in ((DISPLAY_RS, DISPLAY_E)):
GPIO_SETUP.append(gpio)
DISPLAY_WIDTH = 16 # Zeichen je Zeile
DISPLAY_LINE_1 = 0x80 # Adresse der ersten Display Zeile
DISPLAY_LINE_2 = 0xC0 # Adresse der zweiten Display Zeile
# (bei 4x20-Displays lauten die Adressen der dritten
# und vierten Zeile: 0x94 und 0xD4)
DISPLAY_TURN_OUT = 0x08
RJUST = "r"
LJUST = "l"
CENTER = "c"
WRONG_LINE_TXT = "Zeile {0} nicht vorhanden"
WRONG_JUSTIFICATION_TXT = "Ausrichtung >{0}< nicht moeglich"
FILL_CHARACTER = " "
DISPLAY_INIT = (0x33, 0x32, 0x28, 0x0C, 0x06, 0x01)
HIGH_BITS = (0x10, 0x20, 0x40, 0x80)
LOW_BITS = (0x01, 0x02, 0x04, 0x08)
HIGH_LOW_BITS = (HIGH_BITS, LOW_BITS)
DISPLAY_CHR = True
DISPLAY_CMD = False
E_PULSE = 0.0005
E_DELAY = 0.0005

class Lcd_Writer(object):
def __init__(self):
for gpio in GPIO_SETUP:
GPIO.setup(gpio, GPIO.OUT)
for bits in DISPLAY_INIT:
self.send_byte(bits,DISPLAY_CMD)

def write(self, massage, line, justification = LJUST,
fill = FILL_CHARACTER):

def send_string(message):
if justification == RJUST:
for msg in message.rjust(DISPLAY_WIDTH, fill):
self.send_byte(ord(msg))
elif justification == LJUST:
for msg in message.ljust(DISPLAY_WIDTH, fill):
self.send_byte(ord(msg))
elif justification == CENTER:
for msg in message.center(DISPLAY_WIDTH, fill):
self.send_byte(ord(msg))
else:
print WRONG_JUSTIFICATION_TXT.format(justification)

if line == 1:
self.send_byte(DISPLAY_LINE_1, DISPLAY_CMD)
send_string(massage)
elif line == 2:
self.send_byte(DISPLAY_LINE_2, DISPLAY_CMD)
send_string(massage)
else:
print WRONG_LINE_TXT.format(line)

def send_byte(self, bits, mode=DISPLAY_CHR):
GPIO.output(DISPLAY_RS, mode)
for high_low_bits in HIGH_LOW_BITS:
for gpio in GPIO_OUT:
GPIO.output(gpio, False)
for gpio, bit in zip(GPIO_OUT, high_low_bits):
if bits&bit:
GPIO.output(gpio, True)
time.sleep(E_DELAY)
GPIO.output(DISPLAY_E, True)
time.sleep(E_PULSE)
GPIO.output(DISPLAY_E, False)
time.sleep(E_DELAY)

def turn_out(self):
self.send_byte(DISPLAY_TURN_OUT, DISPLAY_CMD)
GPIO.cleanup()

if __name__ == '__main__':
lcd_writer = Lcd_Writer()
lcd_writer.write("Hallo", 1, "c", fill = "_")
lcd_writer.write("Welt", 2, "r", fill = "_")
time.sleep(5)
lcd_writer.turn_out()


Kapazitätsmesser mit der Ausgabe auf dem Display:

Das Script wurde mit einem Errorhandling erweitert, damit ein GPIO-Cleanup möglich ist.

#gpio_display_c_messung.py --> C-Messung mit LCD-Display
#! /usr/bin/env python
# -*- coding: utf-8

import time
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

C_PORT = 16

DISPLAY_RS = 5
DISPLAY_E = 6
DISPLAY_DATA4 = 25
DISPLAY_DATA5 = 24
DISPLAY_DATA6 = 23
DISPLAY_DATA7 = 18

GPIO_OUT = [DISPLAY_DATA4, DISPLAY_DATA5, DISPLAY_DATA6, DISPLAY_DATA7]
GPIO_SETUP = list()
for gpio in GPIO_OUT:
GPIO_SETUP.append(gpio)
for gpio in ((DISPLAY_RS, DISPLAY_E)):
GPIO_SETUP.append(gpio)
DISPLAY_WIDTH = 16 # Zeichen je Zeile
DISPLAY_LINE_1 = 0x80 # Adresse der ersten Display Zeile
DISPLAY_LINE_2 = 0xC0 # Adresse der zweiten Display Zeile
# (bei 4x20-Displays lauten die Adressen der dritten
# und vierten Zeile: 0x94 und 0xD4
DISPLAY_TURN_OUT = 0x08
RJUST = "r"
LJUST = "l"
CENTER = "c"
WRONG_LINE_TXT = "Zeile {0} nicht vorhanden"
WRONG_JUSTIFICATION_TXT = "Ausrichtung >{0}< nicht moeglich"
FILL_CHARACTER = " "
DISPLAY_INIT = (0x33, 0x32, 0x28, 0x0C, 0x06, 0x01)
HIGH_BITS = (0x10, 0x20, 0x40, 0x80)
LOW_BITS = (0x01, 0x02, 0x04, 0x08)
HIGH_LOW_BITS = (HIGH_BITS, LOW_BITS)
DISPLAY_CHR = True
DISPLAY_CMD = False
E_PULSE = 0.0005
E_DELAY = 0.0005

class Lcd_Writer(object):
def __init__(self):
for gpio in GPIO_SETUP:
GPIO.setup(gpio, GPIO.OUT)
for bits in DISPLAY_INIT:
self.send_byte(bits,DISPLAY_CMD)

def write(self, massage, line, justification = LJUST,
fill = FILL_CHARACTER):

def send_string(message):
if justification == RJUST:
for msg in message.rjust(DISPLAY_WIDTH, fill):
self.send_byte(ord(msg))
elif justification == LJUST:
for msg in message.ljust(DISPLAY_WIDTH, fill):
self.send_byte(ord(msg))
elif justification == CENTER:
for msg in message.center(DISPLAY_WIDTH, fill):
self.send_byte(ord(msg))
else:
print WRONG_JUSTIFICATION_TXT.format(justification)

if line == 1:
self.send_byte(DISPLAY_LINE_1, DISPLAY_CMD)
send_string(massage)
elif line == 2:
self.send_byte(DISPLAY_LINE_2, DISPLAY_CMD)
send_string(massage)
else:
print WRONG_LINE_TXT.format(line)

def send_byte(self, bits, mode=DISPLAY_CHR):
GPIO.output(DISPLAY_RS, mode)
for high_low_bits in HIGH_LOW_BITS:
for gpio in GPIO_OUT:
GPIO.output(gpio, False)
for gpio, bit in zip(GPIO_OUT, high_low_bits):
if bits&bit:
GPIO.output(gpio, True)
time.sleep(E_DELAY)
GPIO.output(DISPLAY_E, True)
time.sleep(E_PULSE)
GPIO.output(DISPLAY_E, False)
time.sleep(E_DELAY)

def turn_out(self):
self.send_byte(DISPLAY_TURN_OUT, DISPLAY_CMD)
GPIO.cleanup()


if __name__ == '__main__':

lcd_writer = Lcd_Writer()
try:
while True:
GPIO.setup(C_PORT, GPIO.OUT)
GPIO.output(C_PORT, 1)
time.sleep(0.1)
GPIO.setup(C_PORT, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
t0=time.time()
while True:
if GPIO.input(C_PORT) == 0:
t1=time.time() -t0
break
lcd_writer.write(">{0}{1}".format(int ((t1)*1000000), "us<"), 1, "c",
fill= "-")
lcd_writer.write(">{0}{1}".format(int ((t1)*19900), "nf<"), 2, "c",
fill = "-")
time.sleep(1)
except KeyboardInterrupt:
lcd_writer.turn_out()
print " C-Messung beendet "



Elektronik-Labor  Projekte  Mikrocontroller  Raspberry