Hi,
ich habe nun ein LCD-Display mit den Maßen 4x20 an meinen Raspberry angeschlossen und kann es auch ansteuern.
Nun funktionieren leider die Umlaute nicht.
Ich weiß wie ich sie richtig darstellen kann, möchte aber nicht immer beim eintippen des Textes umdenken müssen.
Kann ich in die Bibliothek desd Displays nicht folgendes mit aufnehmen?
ä = \xe1
ß = \xe2
ö = \xef
ü = \xf5
Wie schreibe ich es in die Bibliothek und wo?
Meine Scripte:
Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------
# Sensorik mit dem Raspberry Pi
# E.F.Engelhardt, Franzis Verlag, 2014
# -----------------------------------------------------------------------
# text2lcd.py
#
import mjkdz
from time import *
import os
os.system('clear')
lcd = mjkdz.lcd()
#maximal 20 zeichen pro zeile!
zeile1="\xe1"
zeile2="a o u"
zeile3="Sind wir"
zeile4="nicht toll"
lcd.lcd_display_string(zeile1, 1)
lcd.lcd_display_string(zeile2, 2)
lcd.lcd_display_string(zeile3, 3)
lcd.lcd_display_string(zeile4, 4)
print "|"
print "| Es wird Zeile 1 ", zeile1, " und Zeile 2 ", zeile2 , " auf dem LCD angezeigt"
print "| ...nach 10 Sekunden.. wird der Inhalt wieder gelöscht.."
print "|"
sleep(5)
#lcd.display_clear()
print "| ...nach weiteren 10 Sekunden.. wird Display ausgeschaltett.."
print "|"
print "| ...und nach weiteren 10 Sekunden das Display wieder eingeschaltet Zeile 2-> 1"
print "| dargestellt"
sleep(5)
print "|"
zeile1="Wir sind"
zeile2="die BESTEN"
zeile3="und fiel tollera"
zeile4="alz Duh"
lcd.lcd_clear() #
lcd.lcd_display_string(zeile1, 1)
lcd.lcd_display_string(zeile2, 2)
lcd.lcd_display_string(zeile3, 3)
lcd.lcd_display_string(zeile4, 4)
print "|"
Display More
Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------
# Sensorik mit dem Raspberry Pi
# E.F.Engelhardt, Franzis Verlag, 2014
# -----------------------------------------------------------------------
# Bibliothek fuer China-LED / 1602 Hitachi kompatibel i2c-Schnittstelle
# YwRobot Arduino LCM1602 IIC V1 16/2
# Hitachi 20/4 an Eigenbauschaltung
#
# mjkdz.py
#
import i2c_lib
import time
from time import *
# LCD Addresse LED Bildschirm
#I2C_LCD_ADDRESS = 0x27 # 16x2
I2C_LCD_ADDRESS = 0x20 # 20x4
# -----------------------------------------------------------------------
# LCD-Befehle
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 display entry mode
LCD_ENTRYRIGHT = 0x00
LCD_ENTRYLEFT = 0x02
LCD_ENTRYSHIFTINCREMENT = 0x01
LCD_ENTRYSHIFTDECREMENT = 0x00
#
# flags display on/off control
LCD_DISPLAYON = 0x04
LCD_DISPLAYOFF = 0x00
LCD_CURSORON = 0x02
LCD_CURSOROFF = 0x00
LCD_BLINKON = 0x01
LCD_BLINKOFF = 0x00
#
# flags 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 backlight control
LCD_BACKLIGHT = 0x08
LCD_NOBACKLIGHT = 0x00
#
En = 0b00000100 # Enable bit
Rw = 0b00000010 # Read/Write bit
Rs = 0b00000001 # Register select bit
# -----------------------------------------------------------------------
class lcd:
#initializes lcd
def __init__(self):
self.lcd_device = i2c_lib.i2c_device(I2C_LCD_ADDRESS)
for i in range(3):
self.lcd_write(0x03) # Prepare switch to 4 bit mode
sleep(.004599)
self.lcd_write(0x02) # Set 4 bit mode
# init
self.displayfunction = LCD_4BITMODE | LCD_2LINE | LCD_5x8DOTS
self.displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF
self.lcd_write(LCD_FUNCTIONSET | self.displayfunction) # Set 4 bit, 2 line mode (Multi-line) = Wert 28
# self.lcd_write(self.displaycontrol) # Turn on display
self.display_on() # Turn on display
self.display_clear()
self.lcd_write(LCD_ENTRYMODESET | LCD_ENTRYLEFT) # cursor to home
sleep(.2)
#clear display
def display_clear(self):
self.lcd_write(LCD_CLEARDISPLAY) # Clear display, move cursor home
#means backlight off
def display_off(self, data=0):
self.lcd_device.write_cmd(data | LCD_NOBACKLIGHT)
def display_on_no(self):
self.displaycontrol &= ~LCD_DISPLAYON
self.lcd_write(LCD_DISPLAYCONTROL | self.displaycontrol)
#display on
def display_on(self):
self.displaycontrol |= LCD_DISPLAYON
self.lcd_write(LCD_DISPLAYCONTROL | self.displaycontrol)
# clocks EN to latch command
def lcd_strobe(self, data):
self.lcd_device.write_cmd(data | En | LCD_BACKLIGHT)
sleep(.0005)
self.lcd_device.write_cmd(((data & ~En) | LCD_BACKLIGHT))
sleep(.0001)
def lcd_write_four_bits(self, data):
#print "data =" , data
self.lcd_device.write_cmd(data | LCD_BACKLIGHT)
self.lcd_strobe(data)
# write a command to lcd
def lcd_write(self, cmd, mode=0):
self.lcd_write_four_bits(mode | (cmd & 0xF0))
self.lcd_write_four_bits(mode | ((cmd << 4) & 0xF0))
# put string function
def lcd_display_string(self, string, line):
if line == 1:
self.lcd_write(0x80)
if line == 2:
self.lcd_write(0xC0)
if line == 3:
self.lcd_write(0x94)
if line == 4:
self.lcd_write(0xD4)
for char in string:
self.lcd_write(ord(char), Rs)
# clear lcd and set to home
def lcd_clear(self):
self.lcd_write(LCD_CLEARDISPLAY)
self.lcd_write(LCD_RETURNHOME)
# -------------------------------------------------------------------------------------
Display More
Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------
# Sensorik mit dem Raspberry Pi
# E.F.Engelhardt, Franzis Verlag, 2014
# -----------------------------------------------------------------------
# i2c_lib.py
# Schnellzugriffsfunktionen auf i2c-Bus
#
import smbus, os
from time import *
class i2c_device:
@staticmethod
def getPiRevision():
try:
f = open('/proc/cpuinfo','r')
for line in f:
if line.startswith('Revision'):
return 1 if line.rstrip()[-1] in ['1','2'] else 2
f.close()
except:
return 0
@staticmethod
def getPiI2CBusNumber():
# Gets the I2C bus number /dev/i2c#
return 1 if i2c_device.getPiRevision() > 1 else 0
def __init__(self, addr, port=-1):
self.addr = addr
print "i2c-Adresse-Geraet= ", hex(self.addr)
print "i2c-Busnummer= ", i2c_device.getPiI2CBusNumber()
print "Raspberry-Pi Revision=", i2c_device.getPiRevision()
self.bus = smbus.SMBus(port if port >= 0 else i2c_device.getPiI2CBusNumber())
# Befehl an Adresse
def write_cmd(self, cmd):
self.bus.write_byte(self.addr, cmd)
sleep(0.0001)
# Befehl und Wert an Adresse
def write_cmd_arg(self, cmd, data):
self.bus.write_byte_data(self.addr, cmd, data)
sleep(0.0001)
# Datenblock schreiben
def write_block_data(self, cmd, data):
self.bus.write_block_data(self.addr, cmd, data)
sleep(0.0001)
# Byte lesen
def read(self):
return self.bus.read_byte(self.addr)
# Inhalt lesen
def read_data(self, cmd):
return self.bus.read_byte_data(self.addr, cmd)
# Datenblock auslesen
def read_block_data(self, cmd):
return self.bus.read_block_data(self.addr, cmd)
# --------------------------------------------------------------------------
Display More
wo füge ich es in welchem Script hinzu?
Gruß Timo