I'm not too adventurous, in the meantime I found a couple of nice examples. In this piece of code, depending of the status of MPD (if there's a song currently played), the code print 'system' info (e.g. IP Address, Temperature, other stuff) or song info (retrieving them from MPD, including timing and other stuff).
The only problem that I have to check, is that the example is made for a 4 lines LCD Display. I'm not sure if the LCD_Init function below is valid also for 16x2 Display ...
.......
import smbus
import time
# Define some device parameters
I2C_ADDR = 0x27 # I2C device address #this must be checked...
LCD_WIDTH = 16 # 20 Maximum characters per line (MODIFIED BY ME)
# Define some device constants
LCD_CHR = 1 # Mode - Sending data
LCD_CMD = 0 # Mode - Sending command
LCD_LINE_1 = 0x80 # LCD RAM address for the 1st line
LCD_LINE_2 = 0xC0 # LCD RAM address for the 2nd line
# LCD_LINE_3 = 0x94 # LCD RAM address for the 3rd line COMMENTED BY ME
# LCD_LINE_4 = 0xD4 # LCD RAM address for the 4th line COMMENTED BY ME
LCD_BACKLIGHT = 0x08 # On
#LCD_BACKLIGHT = 0x00 # Off
ENABLE = 0b00000100 # Enable bit
# Timing constants
E_PULSE = 0.0005
E_DELAY = 0.0005
#Open I2C interface
#bus = smbus.SMBus(0) # Rev 1 Pi uses 0
bus = smbus.SMBus(1) # Rev 2 Pi uses 1
def lcd_init():
# Initialise display
lcd_byte(0x33,LCD_CMD) # 110011 Initialise
lcd_byte(0x32,LCD_CMD) # 110010 Initialise
lcd_byte(0x06,LCD_CMD) # 000110 Cursor move direction
lcd_byte(0x0C,LCD_CMD) # 001100 Display On,Cursor Off, Blink Off
lcd_byte(0x28,LCD_CMD) # 101000 Data length, number of lines, font size
lcd_byte(0x01,LCD_CMD) # 000001 Clear display
time.sleep(E_DELAY)
.....
The only problem that I have to check, is that the example is made for a 4 lines LCD Display. I'm not sure if the LCD_Init function below is valid also for 16x2 Display ...
.......
import smbus
import time
# Define some device parameters
I2C_ADDR = 0x27 # I2C device address #this must be checked...
LCD_WIDTH = 16 # 20 Maximum characters per line (MODIFIED BY ME)
# Define some device constants
LCD_CHR = 1 # Mode - Sending data
LCD_CMD = 0 # Mode - Sending command
LCD_LINE_1 = 0x80 # LCD RAM address for the 1st line
LCD_LINE_2 = 0xC0 # LCD RAM address for the 2nd line
# LCD_LINE_3 = 0x94 # LCD RAM address for the 3rd line COMMENTED BY ME
# LCD_LINE_4 = 0xD4 # LCD RAM address for the 4th line COMMENTED BY ME
LCD_BACKLIGHT = 0x08 # On
#LCD_BACKLIGHT = 0x00 # Off
ENABLE = 0b00000100 # Enable bit
# Timing constants
E_PULSE = 0.0005
E_DELAY = 0.0005
#Open I2C interface
#bus = smbus.SMBus(0) # Rev 1 Pi uses 0
bus = smbus.SMBus(1) # Rev 2 Pi uses 1
def lcd_init():
# Initialise display
lcd_byte(0x33,LCD_CMD) # 110011 Initialise
lcd_byte(0x32,LCD_CMD) # 110010 Initialise
lcd_byte(0x06,LCD_CMD) # 000110 Cursor move direction
lcd_byte(0x0C,LCD_CMD) # 001100 Display On,Cursor Off, Blink Off
lcd_byte(0x28,LCD_CMD) # 101000 Data length, number of lines, font size
lcd_byte(0x01,LCD_CMD) # 000001 Clear display
time.sleep(E_DELAY)
.....