Moin zusammen,
ich versuche gerade mein neues 4x20 HD44780 Display sauber zum laufen zu bekommen.
Ich verwende diese Display: http://www.amazon.de/gp/product/B00L8VCHJC?psc=1&redirect=true&ref_=oh_aui_detailpage_o07_s00&tag=psblog-21 [Anzeige]
Erste gehversuche habe ich mit dem folgenden Tuturial gemacht:
http://www.schnatterente.net/technik/raspbe…hd44780-display
bzw http://www.schnatterente.net/technik/raspbe…hd44780-display
zuvor hatte ich ein 2x16 Display, dort funktionierte das tut aus dem ersten link einwandfrei.
Beim 4x20 Display gibt es aber das ein oder andere Problemchen...
Das Display / die Zeilen spreche ich mit
DISPLAY_WIDTH = 20 # Zeichen je Zeile
DISPLAY_LINE_1 = 0x80 # Adresse der ersten Display Zeile
DISPLAY_LINE_2 = 0xC0 # Adresse der zweiten Display Zeile
DISPLAY_LINE_3 = 0x94 # Adresse der dritte Display Zeile
DISPLAY_LINE_4 = 0xD4 # Adresse der vierte Display Zeile
an.
"Der gesamte Code"
#!/usr/bin/python
import time, datetime
import RPi.GPIO as GPIO
import re
import subprocess
import os
def bytestomb(b):
mb = round(float(b) / (1024*1024),2)
return mb
def get_ram():
"Returns a tuple (total ram, available ram) in megabytes. See www.linuxatemyram.com"
try:
s = subprocess.check_output(["free","-m"])
lines = s.split('\n')
return ( int(lines[1].split()[1]), int(lines[2].split()[3]) )
except:
return 0
def get_up_stats():
"Returns a tuple (uptime, 5 min load average)"
try:
s = subprocess.check_output(["uptime"])
load_split = s.split('load average: ')
load_five = float(load_split[1].split(',')[1])
up = load_split[0]
up_pos = up.rfind(',',0,len(up)-4)
up = up[:up_pos].split('up ')[1]
return ( up , load_five )
except:
return ( "" , 0 )
def get_sysload():
s = os.getloadavg()
def get_network_bytes(interface):
output = subprocess.Popen(['ifconfig', interface], stdout=subprocess.PIPE).communicate()[0]
rx_bytes = re.findall('RX bytes:([0-9]*) ', output)[0]
tx_bytes = re.findall('TX bytes:([0-9]*) ', output)[0]
return (bytestomb(rx_bytes), bytestomb(tx_bytes))
def get_CPU_temp():
"Returns the temperature in degrees C"
try:
s = subprocess.check_output(["/opt/vc/bin/vcgencmd","measure_temp"])
return float(s.split('=')[1][:-3])
except:
return 0
def get_IP():
"Returns the current IP address"
arg='ip route list'
p=subprocess.Popen(arg,shell=True,stdout=subprocess.PIPE)
data = p.communicate()
split_data = data[0].split()
ipaddr = split_data[split_data.index('src')+1]
return ipaddr
def get_cpu_speed():
"Returns the current CPU speed"
f = os.popen('/opt/vc/bin/vcgencmd get_config arm_freq')
cpu = f.read()
return cpu.split('=')[1]
def getCPUuse():
return(str(os.popen("top -n1 | awk '/Cpu\(s\):/ {print $2}'").readline().strip(\
)))
# Zuordnung der GPIO Pins (ggf. anpassen)
DISPLAY_RS = 7
DISPLAY_E = 8
DISPLAY_DATA4 = 25
DISPLAY_DATA5 = 24
DISPLAY_DATA6 = 23
DISPLAY_DATA7 = 18
DISPLAY_WIDTH = 20 # Zeichen je Zeile
DISPLAY_LINE_1 = 0x80 # Adresse der ersten Display Zeile
DISPLAY_LINE_2 = 0xC0 # Adresse der zweiten Display Zeile
DISPLAY_LINE_3 = 0x94 # Adresse der dritte Display Zeile
DISPLAY_LINE_4 = 0xD4 # Adresse der vierte Display Zeile
DISPLAY_CHR = True
DISPLAY_CMD = False
E_PULSE = 0.00005
E_DELAY = 0.00005
def main():
while True:
GPIO.setmode(GPIO.BCM)
GPIO.setup(DISPLAY_E, GPIO.OUT)
GPIO.setup(DISPLAY_RS, GPIO.OUT)
GPIO.setup(DISPLAY_DATA4, GPIO.OUT)
GPIO.setup(DISPLAY_DATA5, GPIO.OUT)
GPIO.setup(DISPLAY_DATA6, GPIO.OUT)
GPIO.setup(DISPLAY_DATA7, GPIO.OUT)
display_init()
lcd_byte(DISPLAY_LINE_1, DISPLAY_CMD)
lcd_string(datetime.datetime.now().strftime('%H:%M:%S %d.%m.%Y'))
lcd_byte(DISPLAY_LINE_2, DISPLAY_CMD)
lcd_string('Laufzeit: ' + get_up_stats()[0])
lcd_byte(DISPLAY_LINE_3, DISPLAY_CMD)
lcd_string('CPU: '+ str(get_CPU_temp()) + chr(223)+'C @' + str(get_cpu_speed()[:4]) + 'MHz')
lcd_byte(DISPLAY_LINE_4, DISPLAY_CMD)
lcd_string('RAM Frei: ' + str(get_ram()[1]) + '/' + str(get_ram()[0]) + 'MB')
lcd_byte(DISPLAY_LINE_1, DISPLAY_CMD)
for x in range(0,5):
lcd_byte(DISPLAY_LINE_1, DISPLAY_CMD)
lcd_string(datetime.datetime.now().strftime('%H:%M:%S %d.%m.%Y'))
time.sleep(1)
lcd_byte(DISPLAY_LINE_1, DISPLAY_CMD)
lcd_string('Host: RealPi')
lcd_byte(DISPLAY_LINE_2, DISPLAY_CMD)
lcd_string(str(get_IP()))
lcd_byte(DISPLAY_LINE_3, DISPLAY_CMD)
lcd_string('')
lcd_byte(DISPLAY_LINE_4, DISPLAY_CMD)
lcd_string('')
time.sleep(5)
def display_init():
lcd_byte(0x33,DISPLAY_CMD)
lcd_byte(0x32,DISPLAY_CMD)
lcd_byte(0x28,DISPLAY_CMD)
lcd_byte(0x0C,DISPLAY_CMD)
lcd_byte(0x06,DISPLAY_CMD)
lcd_byte(0x01,DISPLAY_CMD)
def lcd_string(message):
message = message.ljust(DISPLAY_WIDTH," ")
for i in range(DISPLAY_WIDTH):
lcd_byte(ord(message[i]),DISPLAY_CHR)
def lcd_byte(bits, mode):
GPIO.output(DISPLAY_RS, mode)
GPIO.output(DISPLAY_DATA4, False)
GPIO.output(DISPLAY_DATA5, False)
GPIO.output(DISPLAY_DATA6, False)
GPIO.output(DISPLAY_DATA7, False)
if bits&0x10==0x10:
GPIO.output(DISPLAY_DATA4, True)
if bits&0x20==0x20:
GPIO.output(DISPLAY_DATA5, True)
if bits&0x40==0x40:
GPIO.output(DISPLAY_DATA6, True)
if bits&0x80==0x80:
GPIO.output(DISPLAY_DATA7, True)
time.sleep(E_DELAY)
GPIO.output(DISPLAY_E, True)
time.sleep(E_PULSE)
GPIO.output(DISPLAY_E, False)
time.sleep(E_DELAY)
GPIO.output(DISPLAY_DATA4, False)
GPIO.output(DISPLAY_DATA5, False)
GPIO.output(DISPLAY_DATA6, False)
GPIO.output(DISPLAY_DATA7, False)
if bits&0x01==0x01:
GPIO.output(DISPLAY_DATA4, True)
if bits&0x02==0x02:
GPIO.output(DISPLAY_DATA5, True)
if bits&0x04==0x04:
GPIO.output(DISPLAY_DATA6, True)
if bits&0x08==0x08:
GPIO.output(DISPLAY_DATA7, True)
time.sleep(E_DELAY)
GPIO.output(DISPLAY_E, True)
time.sleep(E_PULSE)
GPIO.output(DISPLAY_E, False)
time.sleep(E_DELAY)
try:
if __name__ == '__main__':
main()
except (KeyboardInterrupt, SystemExit):
GPIO.cleanup()
Alles anzeigen
Die Ausgabe funktioniert soweit auch, allerdings gibt ein ein paar schönheitsprobleme.
Aus mir unerklärlichen Gründen kommt die Ausgabe auf dem Display erst verzögert und mit (und unterschiedlich lang angezeigten) seltsamen Zeichen.
Ich hab es mal auf einem Video festgehalten.. Aber wie es der Vorführeffekt will, kommen die Zeichen im Video nur sehr kurz (blinken kurz auf). die Verzögerung ist aber trotzdem da...:
Hat jemand eine Idee warum die Ausgabe nur verzögert erscheint und die komischen Zeichen vorher mehr oder weniger kurz aufblinken?
Mit dem zweizeiligen Display lief es mit dem identischen code einwandfrei...!?
Danke schon mal im voraus und viele Grüße
Nap