buxiaoyang
Posts: 21
Joined: Wed Dec 05, 2012 1:25 pm

Python driving ST7565 12864 LCD

Sat Dec 08, 2012 1:35 pm

Recently i got a lcd which has 128px*64px display and driver chip is ST7565:
lcd12864.jpg
lcd12864.jpg (29.05 KiB) Viewed 13996 times
It's small enough, so i can directly put it in my raspberry pi case to display some information like IP address and RAM or CPU usage when boot up. Here is pictures of my raspberry pi with the lcd built in:
IMG_3003.JPG
IMG_3003.JPG (54.51 KiB) Viewed 13996 times
And i also wrote a python script to drive this lcd display. Currently i just make it display some text message like:
IMG_3001.JPG
IMG_3001.JPG (55.16 KiB) Viewed 13995 times
Here is the python script i used to drive this lcd(thanks RPi.GPIO to make this script works):

Code: Select all

import RPi.GPIO as GPIO

LCD_CS = 2
LCD_RST  = 3
LCD_A0 = 4
LCD_CLK = 27
LCD_SI = 17

def main():
	io_init()
	lcd_init()
	lcd_ascii168_string(0,0,"This is demo of")
	lcd_ascii168_string(0,2,"raspberry pi LCD")
	lcd_ascii168_string(0,4,"0123456789:;<=>?")
	lcd_ascii168_string(0,6,"@ABCDEFGHIJKLMNO")

def io_init():
	GPIO.setmode(GPIO.BCM)
	GPIO.setwarnings(False)
	GPIO.setup(LCD_CS, GPIO.OUT)
	GPIO.setup(LCD_RST, GPIO.OUT)
	GPIO.setup(LCD_A0, GPIO.OUT)
	GPIO.setup(LCD_CLK, GPIO.OUT)
	GPIO.setup(LCD_SI, GPIO.OUT)
	
def lcd_init():
	GPIO.output(LCD_CS, True)
	GPIO.output(LCD_RST, False)		  	           
	GPIO.output(LCD_RST, True)
	lcd_tranfer_data(0xe2,0); 
	lcd_tranfer_data(0xa3,0);
	lcd_tranfer_data(0xa1,0); 
	lcd_tranfer_data(0xc8,0);  
	lcd_tranfer_data(0xa4,0); 
	lcd_tranfer_data(0xa6,0);
	lcd_tranfer_data(0x2f,0);
	lcd_tranfer_data(0x40,0);
	lcd_tranfer_data(0x22,0);
	lcd_tranfer_data(0x81,0);
	lcd_tranfer_data(0x28,0);
	lcd_tranfer_data(0xaf,0);	
	lcd_clear()	                   

def lcd_ascii168_string(xPos, yPos, string):
	stringLen = len(string)
	for i in range(0, stringLen):
		lcd_ascii168(xPos+i*8,yPos,ord(string[i])-32)

def lcd_ascii168(xPos, yPos, char):
	lcd_set_page(yPos,xPos)
	for i in range(0, 8): 
		lcd_tranfer_data(ASCII168[char][i],1)
	lcd_set_page(yPos+1,xPos)	
	for i in range(8, 16): 
		lcd_tranfer_data(ASCII168[char][i],1)

def lcd_clear():
	GPIO.output(LCD_CS, False)
	for i in range(0, 8):            
		lcd_set_page(i,0)
		for j in range(0, 128):          	                              
			lcd_tranfer_data(0x00,1)
	GPIO.output(LCD_CS, True)

def lcd_set_page(page, column):
	lsb = column & 0x0f
	msb = column & 0xf0
	msb = msb>>4
	msb = msb | 0x10                  
	page = page | 0xb0                               
	lcd_tranfer_data(page,0)
	lcd_tranfer_data(msb,0)
	lcd_tranfer_data(lsb,0)
	

def lcd_tranfer_data(value, SI):
	GPIO.output(LCD_CS, False)
	GPIO.output(LCD_CLK, True)
	if(SI):
		GPIO.output(LCD_A0, True)
	else:
		GPIO.output(LCD_A0, False)
	lcd_byte(value)
	GPIO.output(LCD_CS, True)


def lcd_byte(bits):
	tmp = bits;
	for i in range(0, 8): 
		GPIO.output(LCD_CLK, False)
		if(tmp & 0x80):
			GPIO.output(LCD_SI, True)
		else:
			GPIO.output(LCD_SI, False)
		tmp = (tmp<<1)
		GPIO.output(LCD_CLK, True)
		
ASCII168=(
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#" ",0
(0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00),#"!",1
(0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#""",2
(0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00),#"#",3
(0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00),#"$",4
(0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00),#"%",5
(0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10),#"&",6
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00),#",",7
(0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00),#"(",8
(0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00),#")",9
(0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00),#"*",10
(0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00),#"+",11
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00),#",",12
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01),#"-",13
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00),#".",14
(0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00),#"/",15
(0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00),#"0",16
(0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"1",17
(0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00),#"2",18
(0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00),#"3",19
(0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00),#"4",20
(0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00),#"5",21
(0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00),#"6",22
(0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00),#"7",23
(0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00),#"8",24
(0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00),#"9",25
(0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00),#":",26
(0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00),#";",27
(0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00),#"<",28
(0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00),#"=",29
(0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00),#">",30
(0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00),#"?",31
(0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00),#"@",32
(0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20),#"A",33
(0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00),#"B",34
(0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00),#"C",35
(0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00),#"D",36
(0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00),#"E",37
(0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00),#"F",38
(0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00),#"G",39
(0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20),#"H",40
(0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"I",41
(0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00),#"J",42
(0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00),#"K",43
(0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00),#"L",44
(0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00),#"M",45
(0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00),#"N",46
(0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00),#"O",47
(0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00),#"P",48
(0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00),#"Q",49
(0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20),#"R",50
(0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00),#"S",51
(0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00),#"T",52
(0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00),#"U",53
(0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00),#"V",54
(0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00),#"W",55
(0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20),#"X",56
(0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00),#"Y",57
(0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00),#"Z",58
(0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00),#"[",59
(0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00),#"/",60
(0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00),#"]",61
(0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#"^",62
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01),#"-",63
(0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00),#"\",64
(0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20),#"a",65
(0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00),#"b",66
(0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00),#"c",67
(0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20),#"d",68
(0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00),#"e",69
(0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"f",70
(0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00),#"g",71
(0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20),#"h",72
(0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"i",73
(0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00),#"j",74
(0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00),#"k",75
(0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"l",76
(0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F),#"m",77
(0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20),#"n",79
(0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00),#"o",80
(0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00),#"p",81
(0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80),#"q",82
(0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00),#"r",83
(0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00),#"s",84
(0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00),#"t",85
(0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20),#"u",86
(0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00),#"v",87
(0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00),#"w",88
(0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00),#"x",89
(0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00),#"y",90
(0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00),#"z",91
(0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40),#"{",92
(0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00),#"|",93
(0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00),#"}",94
(0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#"~",95
)

main()
I'm still working on get information like CPU and RAM usage and the current temperature of the CPU(not sure it can). Will keep post if i get some progress. :D

buxiaoyang
Posts: 21
Joined: Wed Dec 05, 2012 1:25 pm

Re: Python driving ST7565 12864 LCD

Sat Dec 08, 2012 2:20 pm

I just try to used this lcd to display the logo of raspberry pi here is what it looks:
IMG_3006.JPG
IMG_3006.JPG (40.69 KiB) Viewed 13981 times
Here is the python script:

Code: Select all

import RPi.GPIO as GPIO

LCD_CS = 2
LCD_RST  = 3
LCD_A0 = 4
LCD_CLK = 27
LCD_SI = 17

def main():
	io_init()
	lcd_init()
	#lcd_ascii168_string(0,0,"This is demo of")
	#lcd_ascii168_string(0,2,"raspberry pi LCD")
	#lcd_ascii168_string(0,4,"0123456789:;<=>?")
	#lcd_ascii168_string(0,6,"@ABCDEFGHIJKLMNO")
	lcd_picture(0,0,0)

def io_init():
	GPIO.setmode(GPIO.BCM)
	GPIO.setwarnings(False)
	GPIO.setup(LCD_CS, GPIO.OUT)
	GPIO.setup(LCD_RST, GPIO.OUT)
	GPIO.setup(LCD_A0, GPIO.OUT)
	GPIO.setup(LCD_CLK, GPIO.OUT)
	GPIO.setup(LCD_SI, GPIO.OUT)
	
def lcd_init():
	GPIO.output(LCD_CS, True)
	GPIO.output(LCD_RST, False)		  	           
	GPIO.output(LCD_RST, True)
	lcd_tranfer_data(0xe2,0); 
	lcd_tranfer_data(0xa3,0);
	lcd_tranfer_data(0xa1,0); 
	lcd_tranfer_data(0xc8,0);  
	lcd_tranfer_data(0xa4,0); 
	lcd_tranfer_data(0xa6,0);
	lcd_tranfer_data(0x2f,0);
	lcd_tranfer_data(0x40,0);
	lcd_tranfer_data(0x22,0);
	lcd_tranfer_data(0x81,0);
	lcd_tranfer_data(0x28,0);
	lcd_tranfer_data(0xaf,0);	
	lcd_clear()	                   

def lcd_picture(xPos, yPos, char):
	for i in range(0, 8):
		lcd_set_page(yPos+i,xPos)
		for j in range(128*i, 128*(i+1)): 
			lcd_tranfer_data(PICTURE[char][j],1)

def lcd_ascii168_string(xPos, yPos, string):
	stringLen = len(string)
	for i in range(0, stringLen):
		lcd_ascii168(xPos+i*8,yPos,ord(string[i])-32)

def lcd_ascii168(xPos, yPos, char):
	lcd_set_page(yPos,xPos)
	for i in range(0, 8): 
		lcd_tranfer_data(ASCII168[char][i],1)
	lcd_set_page(yPos+1,xPos)	
	for i in range(8, 16): 
		lcd_tranfer_data(ASCII168[char][i],1)

def lcd_clear():
	GPIO.output(LCD_CS, False)
	for i in range(0, 8):            
		lcd_set_page(i,0)
		for j in range(0, 128):          	                              
			lcd_tranfer_data(0x00,1)
	GPIO.output(LCD_CS, True)

def lcd_set_page(page, column):
	lsb = column & 0x0f
	msb = column & 0xf0
	msb = msb>>4
	msb = msb | 0x10                  
	page = page | 0xb0                               
	lcd_tranfer_data(page,0)
	lcd_tranfer_data(msb,0)
	lcd_tranfer_data(lsb,0)
	

def lcd_tranfer_data(value, SI):
	GPIO.output(LCD_CS, False)
	GPIO.output(LCD_CLK, True)
	if(SI):
		GPIO.output(LCD_A0, True)
	else:
		GPIO.output(LCD_A0, False)
	lcd_byte(value)
	GPIO.output(LCD_CS, True)


def lcd_byte(bits):
	tmp = bits;
	for i in range(0, 8): 
		GPIO.output(LCD_CLK, False)
		if(tmp & 0x80):
			GPIO.output(LCD_SI, True)
		else:
			GPIO.output(LCD_SI, False)
		tmp = (tmp<<1)
		GPIO.output(LCD_CLK, True)
		
ASCII168=(
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#" ",0
(0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00),#"!",1
(0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#""",2
(0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00),#"#",3
(0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00),#"$",4
(0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00),#"%",5
(0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10),#"&",6
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00),#",",7
(0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00),#"(",8
(0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00),#")",9
(0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00),#"*",10
(0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00),#"+",11
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00),#",",12
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01),#"-",13
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00),#".",14
(0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00),#"/",15
(0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00),#"0",16
(0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"1",17
(0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00),#"2",18
(0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00),#"3",19
(0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00),#"4",20
(0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00),#"5",21
(0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00),#"6",22
(0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00),#"7",23
(0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00),#"8",24
(0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00),#"9",25
(0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00),#":",26
(0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00),#";",27
(0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00),#"<",28
(0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00),#"=",29
(0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00),#">",30
(0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00),#"?",31
(0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00),#"@",32
(0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20),#"A",33
(0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00),#"B",34
(0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00),#"C",35
(0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00),#"D",36
(0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00),#"E",37
(0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00),#"F",38
(0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00),#"G",39
(0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20),#"H",40
(0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"I",41
(0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00),#"J",42
(0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00),#"K",43
(0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00),#"L",44
(0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00),#"M",45
(0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00),#"N",46
(0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00),#"O",47
(0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00),#"P",48
(0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00),#"Q",49
(0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20),#"R",50
(0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00),#"S",51
(0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00),#"T",52
(0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00),#"U",53
(0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00),#"V",54
(0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00),#"W",55
(0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20),#"X",56
(0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00),#"Y",57
(0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00),#"Z",58
(0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00),#"[",59
(0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00),#"/",60
(0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00),#"]",61
(0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#"^",62
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01),#"-",63
(0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00),#"\",64
(0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20),#"a",65
(0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00),#"b",66
(0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00),#"c",67
(0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20),#"d",68
(0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00),#"e",69
(0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"f",70
(0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00),#"g",71
(0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20),#"h",72
(0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"i",73
(0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00),#"j",74
(0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00),#"k",75
(0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"l",76
(0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F),#"m",77
(0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20),#"n",79
(0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00),#"o",80
(0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00),#"p",81
(0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80),#"q",82
(0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00),#"r",83
(0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00),#"s",84
(0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00),#"t",85
(0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20),#"u",86
(0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00),#"v",87
(0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00),#"w",88
(0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00),#"x",89
(0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00),#"y",90
(0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00),#"z",91
(0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40),#"{",92
(0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00),#"|",93
(0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00),#"}",94
(0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#"~",95
)

PICTURE=(
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xF0,0xF8,0x58,0x1C,0x1C,0x0C,0x0C,0x06,0x86,0x86,0x86,0x0E,
0x0E,0x06,0x0E,0x1E,0x1C,0x1C,0x0C,0x3C,0x38,0x78,0xF0,0xE0,0xC0,0xC0,0xE0,0x70,
0x38,0x18,0x1C,0x1C,0x0C,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x86,0x86,0x06,0x04,0x0C,
0x0C,0x18,0xF8,0xF8,0xF8,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x03,0x0F,0x3F,0x7C,0xF0,0xC0,0xC0,0xC0,0xC0,0x00,0x01,0x01,
0x03,0x02,0x06,0x04,0x04,0x1C,0xB8,0xF0,0xE0,0x70,0x30,0x1F,0x0F,0x0F,0x3F,0x30,
0xF0,0xE0,0xB0,0x18,0x08,0x0C,0x04,0x06,0x02,0x01,0x01,0x00,0x00,0x00,0x00,0xC0,
0xF0,0xF8,0x7F,0x1F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xE0,0xF3,0x33,0x3F,0x1F,0x1E,0x0E,0x0E,
0x0C,0x0C,0xEC,0xEC,0xEE,0xBE,0x0F,0x0F,0x07,0x06,0x02,0x02,0x02,0x02,0x02,0x06,
0x06,0x0F,0x0F,0xBE,0xEE,0xCC,0x8C,0x0C,0x0C,0x0C,0x0E,0x1E,0x1E,0x3F,0x73,0xE1,
0xC1,0x00,0x36,0x25,0x55,0x5D,0x49,0x6D,0x32,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x80,0xC0,0xE0,0x70,0x7F,0x7F,0x3F,0xFC,0xFC,0xFC,0x3C,0x1C,0x0E,
0x07,0x07,0x03,0x03,0x03,0x03,0x03,0x02,0x06,0x0E,0x1C,0xFC,0xFC,0xFC,0x3C,0x0E,
0x06,0x02,0x03,0x03,0x03,0x03,0x03,0x03,0x07,0x06,0x0C,0x18,0x78,0xF0,0xF0,0x33,
0x7F,0x7F,0x70,0xF0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xFF,0xFF,0x83,0x00,0x00,0x00,0x00,0xC0,0xFF,0xFF,0xF0,0xF0,0xF0,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xC0,0x60,0x78,0x7F,0x7F,0x7F,0x7C,0x70,
0xE0,0xC0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xC0,0xE0,0xFF,0xFF,0xC0,
0x00,0x00,0x00,0x00,0xC3,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x03,0x0F,0x3E,0xFC,0xFC,0x0E,0x03,0x03,0x03,0x03,0x07,0x07,0x0F,
0x1F,0x3F,0x7F,0xFF,0xFF,0x07,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0x03,0xFF,0xFF,0x7F,0x1F,0x0F,0x07,0x07,0x03,0x01,0x01,0x01,0x01,
0x03,0xFE,0xFE,0x7E,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x07,0x1F,0x3C,0x78,0x70,0xE0,0xE0,0xE0,0xC0,
0xC0,0xC0,0xC0,0xE1,0xFF,0x7F,0x7F,0x3C,0x3C,0x3C,0x38,0x30,0x30,0x30,0x30,0x38,
0x38,0x3C,0x3C,0x7F,0xFF,0xE1,0xC0,0xC0,0xC0,0xC0,0xC0,0xE0,0x60,0x70,0x38,0x38,
0x1E,0x0F,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,
0x01,0x03,0x03,0x07,0x07,0x0E,0x18,0x18,0x38,0x30,0x30,0x30,0x30,0x30,0x30,0x30,
0x38,0x18,0x1C,0x1E,0x0F,0x07,0x03,0x03,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),
)

main()

texy
Forum Moderator
Forum Moderator
Posts: 5073
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Python driving ST7565 12864 LCD

Sat Dec 08, 2012 9:26 pm

Good Job. A 128 x 64 LCD is one of the next types I want to tackle. If you are not aware, I currently supply a ready-made solution for the 'Nokia' type 84x48 LCD's (http://www.raspberrypi.org/phpBB3/viewt ... 59&t=14913). Can I ask where you got the display from? The types I have seen have more pins, etc


Also, for measuring cpu temp, etc, see this thread :
http://www.raspberrypi.org/phpBB3/viewt ... re#p209978

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

buxiaoyang
Posts: 21
Joined: Wed Dec 05, 2012 1:25 pm

Re: Python driving ST7565 12864 LCD

Sun Dec 09, 2012 4:09 am

texy wrote:Good Job. A 128 x 64 LCD is one of the next types I want to tackle. If you are not aware, I currently supply a ready-made solution for the 'Nokia' type 84x48 LCD's (http://www.raspberrypi.org/phpBB3/viewt ... 59&t=14913). Can I ask where you got the display from? The types I have seen have more pins, etc


Also, for measuring cpu temp, etc, see this thread :
http://www.raspberrypi.org/phpBB3/viewt ... re#p209978

Texy
Thanks Texy! The thread of measuring cpu temp is actually what I'm look for. :)

I got the display from taobao.com http://item.taobao.com/item.htm?id=14935644902. It cost me only $2.5. But taobao.com seems only support within our country. So I googled and found this site http://www.adafruit.com/products/250 also provide same lcd. I didn't use this lcd but since they based on the same chip ST7565, so i think it can directly replace the one i use.

Dade
Posts: 1
Joined: Thu Dec 20, 2012 6:12 am
Location: Toronto, Ontario

Re: Python driving ST7565 12864 LCD

Thu Dec 20, 2012 6:26 am

Hi! I have tried to get an ST7565 module working with my Raspberry Pi with this code, but haven't had any luck so far either with Raspberry Pi Occidentalis v.2, or with the latest release of Wheezy. Whether I try to send ASCII characters or a picture, the LCD remains blank.

After making a few changes, the code runs without errors:
1. I have a revision 1 Pi, so I can't use the same GPIO pins and used these ones instead:
LCD_CS = 24
LCD_RST = 21
LCD_A0 = 23
LCD_CLK = 22
LCD_SI = 17

2. Module lcd_tranfer_data is spelled without an S, so referring to the module as lcd_transfer_data obviously doesn't work
3. Various GPIO commands caused errors that noted functions were not in module
* Found version 3 of GPIO in /usr/local/lib/python2.7/dist-packages and removed it
* Installed GPIO 4 with apt-get
* Added GPIO.cleanup() to the end of main()

I've added LEDs to each pin, and I can see activity when I run the application, but the LCD remains blank. I've tested the LCD on an Arduino and it works fine, and also tried with another known good LCD and no change.

Here is the code I tried. Any advice would be appreciated.

Code: Select all

import RPi.GPIO as GPIO

LCD_CS = 24
LCD_RST = 21
LCD_A0 = 23
LCD_CLK = 22
LCD_SI = 17

def main():
	io_init()
	print GPIO.RPI_REVISION
	lcd_init()
	#lcd_ascii168_string(0,0,"This is a demo of")
	#lcd_ascii168_string(0,2,"Raspberry Pi LCD")
	#lcd_ascii168_string(0,4,"0123456789")
	#lcd_ascii168_string(0,6,"@ABCDEF")
	#lcd_picture(0,0,0)
	GPIO.cleanup()

def io_init():
	GPIO.setmode(GPIO.BCM)
	GPIO.setwarnings(True)
	GPIO.setup(LCD_CS, GPIO.OUT)
	GPIO.setup(LCD_RST, GPIO.OUT)
	GPIO.setup(LCD_A0, GPIO.OUT)
	GPIO.setup(LCD_CLK, GPIO.OUT)
	GPIO.setup(LCD_SI, GPIO.OUT)

def lcd_init():
	GPIO.output(LCD_CS, True)
	GPIO.output(LCD_RST, False)
	GPIO.output(LCD_RST, True)
	lcd_transfer_data(0xe2,0); 
	lcd_transfer_data(0xa3,0);
	lcd_transfer_data(0xa1,0);
	lcd_transfer_data(0xc8,0);
	lcd_transfer_data(0xa4,0);
	lcd_transfer_data(0xa6,0);
	lcd_transfer_data(0x2f,0);
	lcd_transfer_data(0x40,0);
	lcd_transfer_data(0x22,0);
	lcd_transfer_data(0x81,0);
	lcd_transfer_data(0x28,0);
	lcd_transfer_data(0xaf,0);
	lcd_clear()

def lcd_ascii168_string(xPos, yPos, string):
	stringLen = len(string)
	for i in range(0, stringLen):
		lcd_ascii168(xPos+i*8,yPos,ord(string[i])-32)

def lcd_ascii168(xPos, yPos, char):
	lcd_set_page(yPos,xPos)
	for i in range(0,8):
		lcd_transfer_data(ASCII168[char][i],1)
	lcd_set_page(yPos+1,xPos)
	for i in range (8,16):
		lcd_transfer_data(0x00,1)

def lcd_picture(xPos, yPos, char):
	for i in range (0, 8):
		lcd_set_page(yPos+i,xPos)
	for j in range(128*i, 128*(i+1)):
		lcd_transfer_data(PICTURE[char][j],1)

def lcd_clear():
	GPIO.output(LCD_CS, False)
	for i in range(0, 8):
		lcd_set_page(i, 0)
		for j in range(0, 128):
			lcd_transfer_data(0x00, 1)
	GPIO.output(LCD_CS, True)

def lcd_set_page(page, column):
	lsb = column & 0x0f
	msb = column & 0xf0
	msb = msb>>4
	msb = msb | 0x10
	page = page | 0xb0
	lcd_transfer_data(page,0)
	lcd_transfer_data(msb,0)
	lcd_transfer_data(lsb,0)

def lcd_transfer_data(value, SI):
	GPIO.output(LCD_CS, False)
	GPIO.output(LCD_CLK, True)
	if(SI):
		GPIO.output(LCD_A0, True)
	else:
		GPIO.output(LCD_A0, False)
	lcd_byte(value)
	GPIO.output(LCD_CS, True)

def lcd_byte(bits):
	tmp = bits
	for i in range(0, 8):
		GPIO.output(LCD_CLK, False)
	if(tmp & 0x80):
		GPIO.output(LCD_SI, True)
	else:
		GPIO.output(LCD_SI, False)
	tmp = (tmp<<1)
	GPIO.output(LCD_CLK, True)

ASCII168=(
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#" ",0
(0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00),#"!",1
(0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#""",2
(0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00),#"#",3
(0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00),#"$",4
(0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00),#"%",5
(0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10),#"&",6
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00),#",",7
(0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00),#"(",8
(0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00),#")",9
(0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00),#"*",10
(0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00),#"+",11
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00),#",",12
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01),#"-",13
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00),#".",14
(0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00),#"/",15
(0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00),#"0",16
(0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"1",17
(0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00),#"2",18
(0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00),#"3",19
(0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00),#"4",20
(0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00),#"5",21
(0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00),#"6",22
(0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00),#"7",23
(0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00),#"8",24
(0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00),#"9",25
(0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00),#":",26
(0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00),#";",27
(0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00),#"<",28
(0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00),#"=",29
(0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00),#">",30
(0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00),#"?",31
(0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00),#"@",32
(0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20),#"A",33
(0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00),#"B",34
(0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00),#"C",35
(0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00),#"D",36
(0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00),#"E",37
(0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00),#"F",38
(0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00),#"G",39
(0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20),#"H",40
(0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"I",41
(0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00),#"J",42
(0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00),#"K",43
(0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00),#"L",44
(0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00),#"M",45
(0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00),#"N",46
(0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00),#"O",47
(0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00),#"P",48
(0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00),#"Q",49
(0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20),#"R",50
(0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00),#"S",51
(0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00),#"T",52
(0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00),#"U",53
(0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00),#"V",54
(0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00),#"W",55
(0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20),#"X",56
(0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00),#"Y",57
(0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00),#"Z",58
(0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00),#"[",59
(0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00),#"/",60
(0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00),#"]",61
(0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#"^",62
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01),#"-",63
(0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00),#"\",64
(0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20),#"a",65
(0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00),#"b",66
(0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00),#"c",67
(0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20),#"d",68
(0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00),#"e",69
(0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"f",70
(0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00),#"g",71
(0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20),#"h",72
(0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"i",73
(0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00),#"j",74
(0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00),#"k",75
(0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"l",76
(0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F),#"m",77
(0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20),#"n",79
(0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00),#"o",80
(0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00),#"p",81
(0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80),#"q",82
(0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00),#"r",83
(0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00),#"s",84
(0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00),#"t",85
(0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20),#"u",86
(0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00),#"v",87
(0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00),#"w",88
(0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00),#"x",89
(0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00),#"y",90
(0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00),#"z",91
(0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40),#"{",92
(0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00),#"|",93
(0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00),#"}",94
(0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#"~",95
)

PICTURE=(
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xF0,0xF8,0x58,0x1C,0x1C,0x0C,0x0C,0x06,0x86,0x86,0x86,0x0E,
0x0E,0x06,0x0E,0x1E,0x1C,0x1C,0x0C,0x3C,0x38,0x78,0xF0,0xE0,0xC0,0xC0,0xE0,0x70,
0x38,0x18,0x1C,0x1C,0x0C,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x86,0x86,0x06,0x04,0x0C,
0x0C,0x18,0xF8,0xF8,0xF8,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x03,0x0F,0x3F,0x7C,0xF0,0xC0,0xC0,0xC0,0xC0,0x00,0x01,0x01,
0x03,0x02,0x06,0x04,0x04,0x1C,0xB8,0xF0,0xE0,0x70,0x30,0x1F,0x0F,0x0F,0x3F,0x30,
0xF0,0xE0,0xB0,0x18,0x08,0x0C,0x04,0x06,0x02,0x01,0x01,0x00,0x00,0x00,0x00,0xC0,
0xF0,0xF8,0x7F,0x1F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xE0,0xF3,0x33,0x3F,0x1F,0x1E,0x0E,0x0E,
0x0C,0x0C,0xEC,0xEC,0xEE,0xBE,0x0F,0x0F,0x07,0x06,0x02,0x02,0x02,0x02,0x02,0x06,
0x06,0x0F,0x0F,0xBE,0xEE,0xCC,0x8C,0x0C,0x0C,0x0C,0x0E,0x1E,0x1E,0x3F,0x73,0xE1,
0xC1,0x00,0x36,0x25,0x55,0x5D,0x49,0x6D,0x32,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x80,0xC0,0xE0,0x70,0x7F,0x7F,0x3F,0xFC,0xFC,0xFC,0x3C,0x1C,0x0E,
0x07,0x07,0x03,0x03,0x03,0x03,0x03,0x02,0x06,0x0E,0x1C,0xFC,0xFC,0xFC,0x3C,0x0E,
0x06,0x02,0x03,0x03,0x03,0x03,0x03,0x03,0x07,0x06,0x0C,0x18,0x78,0xF0,0xF0,0x33,
0x7F,0x7F,0x70,0xF0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xFF,0xFF,0x83,0x00,0x00,0x00,0x00,0xC0,0xFF,0xFF,0xF0,0xF0,0xF0,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xC0,0x60,0x78,0x7F,0x7F,0x7F,0x7C,0x70,
0xE0,0xC0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xC0,0xE0,0xFF,0xFF,0xC0,
0x00,0x00,0x00,0x00,0xC3,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x03,0x0F,0x3E,0xFC,0xFC,0x0E,0x03,0x03,0x03,0x03,0x07,0x07,0x0F,
0x1F,0x3F,0x7F,0xFF,0xFF,0x07,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0x03,0xFF,0xFF,0x7F,0x1F,0x0F,0x07,0x07,0x03,0x01,0x01,0x01,0x01,
0x03,0xFE,0xFE,0x7E,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x07,0x1F,0x3C,0x78,0x70,0xE0,0xE0,0xE0,0xC0,
0xC0,0xC0,0xC0,0xE1,0xFF,0x7F,0x7F,0x3C,0x3C,0x3C,0x38,0x30,0x30,0x30,0x30,0x38,
0x38,0x3C,0x3C,0x7F,0xFF,0xE1,0xC0,0xC0,0xC0,0xC0,0xC0,0xE0,0x60,0x70,0x38,0x38,
0x1E,0x0F,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,
0x01,0x03,0x03,0x07,0x07,0x0E,0x18,0x18,0x38,0x30,0x30,0x30,0x30,0x30,0x30,0x30,
0x38,0x18,0x1C,0x1E,0x0F,0x07,0x03,0x03,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),
)

main()

ukgamer
Posts: 11
Joined: Fri Nov 16, 2012 5:50 pm
Location: Coventry, England
Contact: Website

Re: Python driving ST7565 12864 LCD

Thu Dec 20, 2012 7:21 pm

I'm having the same issues as Dade with this code. I hope someone can help us out.

texy
Forum Moderator
Forum Moderator
Posts: 5073
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Python driving ST7565 12864 LCD

Sat Dec 22, 2012 10:43 pm

Are you both sure that the displays used are OK at 3v3? I,ve seen conflicting info on requiring either a 3v3 or 5v supply.
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

ukgamer
Posts: 11
Joined: Fri Nov 16, 2012 5:50 pm
Location: Coventry, England
Contact: Website

Re: Python driving ST7565 12864 LCD

Sun Dec 23, 2012 5:54 am

The display I have is certainly a 3v3 one. http://proto-pic.co.uk/graphic-st7565-p ... backlight/
3.3v power and logic

buxiaoyang
Posts: 21
Joined: Wed Dec 05, 2012 1:25 pm

Re: Python driving ST7565 12864 LCD

Mon Dec 24, 2012 7:55 am

Dade wrote:Hi! I have tried to get an ST7565 module working with my Raspberry Pi with this code, but haven't had any luck so far either with Raspberry Pi Occidentalis v.2, or with the latest release of Wheezy. Whether I try to send ASCII characters or a picture, the LCD remains blank.

After making a few changes, the code runs without errors:
1. I have a revision 1 Pi, so I can't use the same GPIO pins and used these ones instead:
LCD_CS = 24
LCD_RST = 21
LCD_A0 = 23
LCD_CLK = 22
LCD_SI = 17

2. Module lcd_tranfer_data is spelled without an S, so referring to the module as lcd_transfer_data obviously doesn't work
3. Various GPIO commands caused errors that noted functions were not in module
* Found version 3 of GPIO in /usr/local/lib/python2.7/dist-packages and removed it
* Installed GPIO 4 with apt-get
* Added GPIO.cleanup() to the end of main()

I've added LEDs to each pin, and I can see activity when I run the application, but the LCD remains blank. I've tested the LCD on an Arduino and it works fine, and also tried with another known good LCD and no change.

Here is the code I tried. Any advice would be appreciated.

Code: Select all

import RPi.GPIO as GPIO

LCD_CS = 24
LCD_RST = 21
LCD_A0 = 23
LCD_CLK = 22
LCD_SI = 17

def main():
	io_init()
	print GPIO.RPI_REVISION
	lcd_init()
	#lcd_ascii168_string(0,0,"This is a demo of")
	#lcd_ascii168_string(0,2,"Raspberry Pi LCD")
	#lcd_ascii168_string(0,4,"0123456789")
	#lcd_ascii168_string(0,6,"@ABCDEF")
	#lcd_picture(0,0,0)
	GPIO.cleanup()

def io_init():
	GPIO.setmode(GPIO.BCM)
	GPIO.setwarnings(True)
	GPIO.setup(LCD_CS, GPIO.OUT)
	GPIO.setup(LCD_RST, GPIO.OUT)
	GPIO.setup(LCD_A0, GPIO.OUT)
	GPIO.setup(LCD_CLK, GPIO.OUT)
	GPIO.setup(LCD_SI, GPIO.OUT)

def lcd_init():
	GPIO.output(LCD_CS, True)
	GPIO.output(LCD_RST, False)
	GPIO.output(LCD_RST, True)
	lcd_transfer_data(0xe2,0); 
	lcd_transfer_data(0xa3,0);
	lcd_transfer_data(0xa1,0);
	lcd_transfer_data(0xc8,0);
	lcd_transfer_data(0xa4,0);
	lcd_transfer_data(0xa6,0);
	lcd_transfer_data(0x2f,0);
	lcd_transfer_data(0x40,0);
	lcd_transfer_data(0x22,0);
	lcd_transfer_data(0x81,0);
	lcd_transfer_data(0x28,0);
	lcd_transfer_data(0xaf,0);
	lcd_clear()

def lcd_ascii168_string(xPos, yPos, string):
	stringLen = len(string)
	for i in range(0, stringLen):
		lcd_ascii168(xPos+i*8,yPos,ord(string[i])-32)

def lcd_ascii168(xPos, yPos, char):
	lcd_set_page(yPos,xPos)
	for i in range(0,8):
		lcd_transfer_data(ASCII168[char][i],1)
	lcd_set_page(yPos+1,xPos)
	for i in range (8,16):
		lcd_transfer_data(0x00,1)

def lcd_picture(xPos, yPos, char):
	for i in range (0, 8):
		lcd_set_page(yPos+i,xPos)
	for j in range(128*i, 128*(i+1)):
		lcd_transfer_data(PICTURE[char][j],1)

def lcd_clear():
	GPIO.output(LCD_CS, False)
	for i in range(0, 8):
		lcd_set_page(i, 0)
		for j in range(0, 128):
			lcd_transfer_data(0x00, 1)
	GPIO.output(LCD_CS, True)

def lcd_set_page(page, column):
	lsb = column & 0x0f
	msb = column & 0xf0
	msb = msb>>4
	msb = msb | 0x10
	page = page | 0xb0
	lcd_transfer_data(page,0)
	lcd_transfer_data(msb,0)
	lcd_transfer_data(lsb,0)

def lcd_transfer_data(value, SI):
	GPIO.output(LCD_CS, False)
	GPIO.output(LCD_CLK, True)
	if(SI):
		GPIO.output(LCD_A0, True)
	else:
		GPIO.output(LCD_A0, False)
	lcd_byte(value)
	GPIO.output(LCD_CS, True)

def lcd_byte(bits):
	tmp = bits
	for i in range(0, 8):
		GPIO.output(LCD_CLK, False)
	if(tmp & 0x80):
		GPIO.output(LCD_SI, True)
	else:
		GPIO.output(LCD_SI, False)
	tmp = (tmp<<1)
	GPIO.output(LCD_CLK, True)

ASCII168=(
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#" ",0
(0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00),#"!",1
(0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#""",2
(0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00),#"#",3
(0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00),#"$",4
(0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00),#"%",5
(0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10),#"&",6
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00),#",",7
(0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00),#"(",8
(0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00),#")",9
(0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00),#"*",10
(0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00),#"+",11
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00),#",",12
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01),#"-",13
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00),#".",14
(0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00),#"/",15
(0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00),#"0",16
(0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"1",17
(0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00),#"2",18
(0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00),#"3",19
(0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00),#"4",20
(0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00),#"5",21
(0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00),#"6",22
(0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00),#"7",23
(0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00),#"8",24
(0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00),#"9",25
(0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00),#":",26
(0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00),#";",27
(0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00),#"<",28
(0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00),#"=",29
(0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00),#">",30
(0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00),#"?",31
(0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00),#"@",32
(0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20),#"A",33
(0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00),#"B",34
(0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00),#"C",35
(0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00),#"D",36
(0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00),#"E",37
(0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00),#"F",38
(0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00),#"G",39
(0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20),#"H",40
(0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"I",41
(0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00),#"J",42
(0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00),#"K",43
(0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00),#"L",44
(0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00),#"M",45
(0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00),#"N",46
(0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00),#"O",47
(0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00),#"P",48
(0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00),#"Q",49
(0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20),#"R",50
(0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00),#"S",51
(0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00),#"T",52
(0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00),#"U",53
(0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00),#"V",54
(0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00),#"W",55
(0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20),#"X",56
(0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00),#"Y",57
(0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00),#"Z",58
(0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00),#"[",59
(0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00),#"/",60
(0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00),#"]",61
(0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#"^",62
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01),#"-",63
(0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00),#"\",64
(0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20),#"a",65
(0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00),#"b",66
(0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00),#"c",67
(0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20),#"d",68
(0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00),#"e",69
(0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"f",70
(0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00),#"g",71
(0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20),#"h",72
(0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"i",73
(0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00),#"j",74
(0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00),#"k",75
(0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"l",76
(0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F),#"m",77
(0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20),#"n",79
(0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00),#"o",80
(0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00),#"p",81
(0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80),#"q",82
(0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00),#"r",83
(0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00),#"s",84
(0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00),#"t",85
(0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20),#"u",86
(0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00),#"v",87
(0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00),#"w",88
(0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00),#"x",89
(0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00),#"y",90
(0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00),#"z",91
(0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40),#"{",92
(0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00),#"|",93
(0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00),#"}",94
(0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#"~",95
)

PICTURE=(
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xF0,0xF8,0x58,0x1C,0x1C,0x0C,0x0C,0x06,0x86,0x86,0x86,0x0E,
0x0E,0x06,0x0E,0x1E,0x1C,0x1C,0x0C,0x3C,0x38,0x78,0xF0,0xE0,0xC0,0xC0,0xE0,0x70,
0x38,0x18,0x1C,0x1C,0x0C,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x86,0x86,0x06,0x04,0x0C,
0x0C,0x18,0xF8,0xF8,0xF8,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x03,0x0F,0x3F,0x7C,0xF0,0xC0,0xC0,0xC0,0xC0,0x00,0x01,0x01,
0x03,0x02,0x06,0x04,0x04,0x1C,0xB8,0xF0,0xE0,0x70,0x30,0x1F,0x0F,0x0F,0x3F,0x30,
0xF0,0xE0,0xB0,0x18,0x08,0x0C,0x04,0x06,0x02,0x01,0x01,0x00,0x00,0x00,0x00,0xC0,
0xF0,0xF8,0x7F,0x1F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xE0,0xF3,0x33,0x3F,0x1F,0x1E,0x0E,0x0E,
0x0C,0x0C,0xEC,0xEC,0xEE,0xBE,0x0F,0x0F,0x07,0x06,0x02,0x02,0x02,0x02,0x02,0x06,
0x06,0x0F,0x0F,0xBE,0xEE,0xCC,0x8C,0x0C,0x0C,0x0C,0x0E,0x1E,0x1E,0x3F,0x73,0xE1,
0xC1,0x00,0x36,0x25,0x55,0x5D,0x49,0x6D,0x32,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x80,0xC0,0xE0,0x70,0x7F,0x7F,0x3F,0xFC,0xFC,0xFC,0x3C,0x1C,0x0E,
0x07,0x07,0x03,0x03,0x03,0x03,0x03,0x02,0x06,0x0E,0x1C,0xFC,0xFC,0xFC,0x3C,0x0E,
0x06,0x02,0x03,0x03,0x03,0x03,0x03,0x03,0x07,0x06,0x0C,0x18,0x78,0xF0,0xF0,0x33,
0x7F,0x7F,0x70,0xF0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xFF,0xFF,0x83,0x00,0x00,0x00,0x00,0xC0,0xFF,0xFF,0xF0,0xF0,0xF0,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xC0,0x60,0x78,0x7F,0x7F,0x7F,0x7C,0x70,
0xE0,0xC0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xC0,0xE0,0xFF,0xFF,0xC0,
0x00,0x00,0x00,0x00,0xC3,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x03,0x0F,0x3E,0xFC,0xFC,0x0E,0x03,0x03,0x03,0x03,0x07,0x07,0x0F,
0x1F,0x3F,0x7F,0xFF,0xFF,0x07,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0x03,0xFF,0xFF,0x7F,0x1F,0x0F,0x07,0x07,0x03,0x01,0x01,0x01,0x01,
0x03,0xFE,0xFE,0x7E,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x07,0x1F,0x3C,0x78,0x70,0xE0,0xE0,0xE0,0xC0,
0xC0,0xC0,0xC0,0xE1,0xFF,0x7F,0x7F,0x3C,0x3C,0x3C,0x38,0x30,0x30,0x30,0x30,0x38,
0x38,0x3C,0x3C,0x7F,0xFF,0xE1,0xC0,0xC0,0xC0,0xC0,0xC0,0xE0,0x60,0x70,0x38,0x38,
0x1E,0x0F,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,
0x01,0x03,0x03,0x07,0x07,0x0E,0x18,0x18,0x38,0x30,0x30,0x30,0x30,0x30,0x30,0x30,
0x38,0x18,0x1C,0x1E,0x0F,0x07,0x03,0x03,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),
)

main()
hello Dade, please try

Code: Select all

def lcd_byte(bits):
   tmp = bits;
   for i in range(0, 8): 
      GPIO.output(LCD_CLK, False)
      if(tmp & 0x80):
         GPIO.output(LCD_SI, True)
      else:
         GPIO.output(LCD_SI, False)
      tmp = (tmp<<1)
      GPIO.output(LCD_CLK, True)
instead of

Code: Select all

def lcd_byte(bits):
   tmp = bits
   for i in range(0, 8):
      GPIO.output(LCD_CLK, False)
   if(tmp & 0x80):
      GPIO.output(LCD_SI, True)
   else:
      GPIO.output(LCD_SI, False)
   tmp = (tmp<<1)
   GPIO.output(LCD_CLK, True)
in you code.

We need to let the "for" statement include follow statements

Code: Select all

      GPIO.output(LCD_CLK, False)
      if(tmp & 0x80):
         GPIO.output(LCD_SI, True)
      else:
         GPIO.output(LCD_SI, False)
      tmp = (tmp<<1)
      GPIO.output(LCD_CLK, True)
In python, it seems use tab or space to specify the code scope.

And also, you need open a display in your code like:

Code: Select all

def main():
   io_init()
   print GPIO.RPI_REVISION
   lcd_init()
   #lcd_ascii168_string(0,0,"This is a demo of")
   #lcd_ascii168_string(0,2,"Raspberry Pi LCD")
   #lcd_ascii168_string(0,4,"0123456789")
   #lcd_ascii168_string(0,6,"@ABCDEF")
   lcd_picture(0,0,0)
   GPIO.cleanup()
Good luck to you!

ukgamer
Posts: 11
Joined: Fri Nov 16, 2012 5:50 pm
Location: Coventry, England
Contact: Website

Re: Python driving ST7565 12864 LCD

Mon Dec 24, 2012 2:17 pm

With the above code changes I now see some text flash on the screen for a brief moment and then the screen goes blank.

I can see that each character is being drawn flipped horizontally. The first two lines of text are being drawn on the bottom two pages of the screen, with the last two on the top two pages. Towards the end of the first two lines of text there are a bunch of jumbled "pixels". I'm quite sure that my wiring is fine.

texy
Forum Moderator
Forum Moderator
Posts: 5073
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Python driving ST7565 12864 LCD

Tue Dec 25, 2012 4:58 pm

Try adding

Code: Select all

import time
after this line

Code: Select all

import RPi.GPIO as GPIO
and

Code: Select all

   time.sleep(5)
in between these 2 lines :

Code: Select all

   lcd_picture(0,0,0)
   GPIO.cleanup()
This will cause a 5 second delay before the program terminates. Is the display good during these 5 seconds?

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

ukgamer
Posts: 11
Joined: Fri Nov 16, 2012 5:50 pm
Location: Coventry, England
Contact: Website

Re: Python driving ST7565 12864 LCD

Tue Dec 25, 2012 9:27 pm

I took a picture of what I see during the 5 seconds before the program terminates and the screen goes blank.

Image

It's hard to see but you can see the flipped text and garbled pixels. It looks like the contrast is also set too high.

texy
Forum Moderator
Forum Moderator
Posts: 5073
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Python driving ST7565 12864 LCD

Tue Dec 25, 2012 9:32 pm

The main thing is that you've got something you can work on. I suspect that not all of these LCD's are equal.
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

buxiaoyang
Posts: 21
Joined: Wed Dec 05, 2012 1:25 pm

Re: Python driving ST7565 12864 LCD

Wed Dec 26, 2012 8:29 am

ukgamer wrote:I took a picture of what I see during the 5 seconds before the program terminates and the screen goes blank.

Image

It's hard to see but you can see the flipped text and garbled pixels. It looks like the contrast is also set too high.
Hello ukgamer,

Did you driver this LCD well in your android board or other platform?

If yes, i would suggest you refer your android code to adjust this python code. Since you can see the flipped text on the screen the "lcd_transfer_data" function should works now. It means your PI can communicate with this LCD.

Then what you need to is some adjustment like init function or fonts code. In this time, a well running code in other platform would be a help.

For the flipped text, it should be the fonts code problem. My LCD didn't have the build in font, so i use a small tool get the fonts code and put it in python. Actually you can build whatever fonts you like.

Best
Shawn

buxiaoyang
Posts: 21
Joined: Wed Dec 05, 2012 1:25 pm

Re: Python driving ST7565 12864 LCD

Wed Dec 26, 2012 8:45 am

Hello again ukgamer,

A small test, please replace:

Code: Select all

(0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00),#"0",16
(0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"1",17
(0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00),#"2",18
(0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00),#"3",19
(0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00),#"4",20
(0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00),#"5",21
(0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00),#"6",22
(0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00),#"7",23
(0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00),#"8",24
(0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00),#"9",25
with:

Code: Select all

(0x00,0x07,0x08,0x10,0x10,0x08,0x07,0x00,0x00,0xF0,0x08,0x04,0x04,0x08,0xF0,0x00),#"0",16
(0x00,0x08,0x08,0x1F,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0xFC,0x04,0x04,0x00,0x00),#"1",17
(0x00,0x0E,0x10,0x10,0x10,0x11,0x0E,0x00,0x00,0x0C,0x14,0x24,0x44,0x84,0x0C,0x00),#"2",18
(0x00,0x0C,0x10,0x11,0x11,0x12,0x0C,0x00,0x00,0x18,0x04,0x04,0x04,0x88,0x70,0x00),#"3",19
(0x00,0x00,0x03,0x04,0x08,0x1F,0x00,0x00,0x00,0xE0,0x20,0x24,0x24,0xFC,0x24,0x00),#"4",20
(0x00,0x1F,0x10,0x11,0x11,0x10,0x10,0x00,0x00,0x98,0x84,0x04,0x04,0x88,0x70,0x00),#"5",21
(0x00,0x07,0x08,0x11,0x11,0x18,0x00,0x00,0x00,0xF0,0x88,0x04,0x04,0x88,0x70,0x00),#"6",22
(0x00,0x1C,0x10,0x10,0x13,0x1C,0x10,0x00,0x00,0x00,0x00,0xFC,0x00,0x00,0x00,0x00),#"7",23
(0x00,0x0E,0x11,0x10,0x10,0x11,0x0E,0x00,0x00,0x38,0x44,0x84,0x84,0x44,0x38,0x00),#"8",24
(0x00,0x07,0x08,0x10,0x10,0x08,0x07,0x00,0x00,0x00,0x8C,0x44,0x44,0x88,0xF0,0x00),#"9",25
in your code to see if you can get the right "0123456789" in your LCD.

And try to add a resistance in the backlight VCC, to see if it's a little well if the backlight not so strong.

Best,
Shawn

buxiaoyang
Posts: 21
Joined: Wed Dec 05, 2012 1:25 pm

Re: Python driving ST7565 12864 LCD

Wed Dec 26, 2012 9:07 am

For the screen goes blank problem. Please try to remove this code:

Code: Select all

GPIO.cleanup()
to see if it will OK.

The screen shouldn't goes blank even if your code stop. I imagine that it due to in GPIO.cleanup() function the output will do some operation which will cause the LCD reset.

Anyway, we can have some try to see where the problem is.

canibalimao
Posts: 557
Joined: Tue Aug 07, 2012 8:48 pm
Location: Portugal

Re: Python driving ST7565 12864 LCD

Wed Dec 26, 2012 5:21 pm

ukgamer wrote:I took a picture of what I see during the 5 seconds before the program terminates and the screen goes blank.

Image

It's hard to see but you can see the flipped text and garbled pixels. It looks like the contrast is also set too high.
Am I the only one who was thinking on "overcontrast"? The HD44780 LCD's (16x2 and 20x4) need a potentiometer to controll the contraste. This kind of screens don't need it?

texy
Forum Moderator
Forum Moderator
Posts: 5073
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Python driving ST7565 12864 LCD

Wed Dec 26, 2012 5:48 pm

No. The contrast is set by sending a command to the LCD over the serial port.
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

ukgamer
Posts: 11
Joined: Fri Nov 16, 2012 5:50 pm
Location: Coventry, England
Contact: Website

Re: Python driving ST7565 12864 LCD

Wed Dec 26, 2012 10:47 pm

buxiaoyang wrote:Hello again ukgamer,

A small test, please replace:

Code: Select all

in your code to see if you can get the right "0123456789" in your LCD.

And try to add a resistance in the backlight VCC, to see if it's a little well if the backlight not so strong.

Best,
Shawn[/quote]

Looks like those code changes caused the numbers to be shifted downwards and to "wrap" so that half of the number is at the top and half is at the bottom.

I reduced the intensity of the backlight for this picture although the contrast still makes it difficult to see.

[url=http://i6.minus.com/iOjYruiKWnDDv.jpg][img]http://i6.minus.com/iOjYruiKWnDDv.jpg[/img][/url]

I have had success with this LCD on an Arduino with Adafruit's library.

buxiaoyang
Posts: 21
Joined: Wed Dec 05, 2012 1:25 pm

Re: Python driving ST7565 12864 LCD

Thu Dec 27, 2012 3:58 am

ukgamer wrote: Looks like those code changes caused the numbers to be shifted downwards and to "wrap" so that half of the number is at the top and half is at the bottom.

I reduced the intensity of the backlight for this picture although the contrast still makes it difficult to see.

Image

I have had success with this LCD on an Arduino with Adafruit's library.
Then Please try

Code: Select all

(0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00),#"0",16
(0x00,0x00,0x00,0x10,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00),#"1",17
(0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x04,0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00),#"2",18
(0x00,0x00,0x00,0x3C,0x42,0x42,0x04,0x18,0x04,0x02,0x02,0x42,0x44,0x38,0x00,0x00),#"3",19
(0x00,0x00,0x00,0x04,0x0C,0x14,0x24,0x24,0x44,0x44,0x7E,0x04,0x04,0x1E,0x00,0x00),#"4",20
(0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x58,0x64,0x02,0x02,0x42,0x44,0x38,0x00,0x00),#"5",21
(0x00,0x00,0x00,0x1C,0x24,0x40,0x40,0x58,0x64,0x42,0x42,0x42,0x24,0x18,0x00,0x00),#"6",22
(0x00,0x00,0x00,0x7E,0x44,0x44,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00),#"7",23
(0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00),#"8",24
(0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x26,0x1A,0x02,0x02,0x24,0x38,0x00,0x00),#"9",25
or

Code: Select all

(0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00),#"0",16
(0x00,0x00,0x00,0x08,0x0E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00),#"1",17
(0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x20,0x20,0x10,0x08,0x04,0x42,0x7E,0x00,0x00),#"2",18
(0x00,0x00,0x00,0x3C,0x42,0x42,0x20,0x18,0x20,0x40,0x40,0x42,0x22,0x1C,0x00,0x00),#"3",19
(0x00,0x00,0x00,0x20,0x30,0x28,0x24,0x24,0x22,0x22,0x7E,0x20,0x20,0x78,0x00,0x00),#"4",20
(0x00,0x00,0x00,0x7E,0x02,0x02,0x02,0x1A,0x26,0x40,0x40,0x42,0x22,0x1C,0x00,0x00),#"5",21
(0x00,0x00,0x00,0x38,0x24,0x02,0x02,0x1A,0x26,0x42,0x42,0x42,0x24,0x18,0x00,0x00),#"6",22
(0x00,0x00,0x00,0x7E,0x22,0x22,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00),#"7",23
(0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00),#"8",24
(0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x64,0x58,0x40,0x40,0x24,0x1C,0x00,0x00),#"9",25
to see if we are luck to have one works well. These are the total four fonts order i can get from get fonts tool.

I didn't have the experience to use a Adafruit's library, I imagine that we may not able to see the source code of the library right? So we can't know how Arduino drive this LCD actually.

ukgamer
Posts: 11
Joined: Fri Nov 16, 2012 5:50 pm
Location: Coventry, England
Contact: Website

Re: Python driving ST7565 12864 LCD

Thu Dec 27, 2012 5:02 am

Unfortunately neither of those changes work. They are now completely unrecognisable characters with the same "wrapping".

The Adafruit library is open sourced on GitHub at https://github.com/adafruit/ST7565-LCD but I don't have the know-how to port it over.

buxiaoyang
Posts: 21
Joined: Wed Dec 05, 2012 1:25 pm

Re: Python driving ST7565 12864 LCD

Thu Dec 27, 2012 5:20 am

Hello ukgamer,

For the contrast, please change this line of code:

Code: Select all

lcd_tranfer_data(0x22,0);
in the lcd_init function with one of follows lines to set the suitable contrast(small->large):

Code: Select all

lcd_tranfer_data(0x20,0);
lcd_tranfer_data(0x21,0);
lcd_tranfer_data(0x22,0);
lcd_tranfer_data(0x23,0);
lcd_tranfer_data(0x24,0);
lcd_tranfer_data(0x25,0);
lcd_tranfer_data(0x26,0);
lcd_tranfer_data(0x27,0);
And also, change this line:

Code: Select all

lcd_tranfer_data(0xa6,0);
to:

Code: Select all

lcd_tranfer_data(0xa7,0);
to set the display normal or reverse.(0xa6 should be normal display and 0xa7 should be reverse display)

You can refer to datasheet of ST7565 for more control commands. You can get the datasheet by link http://www.digchip.com/datasheets/downl ... ber=ST7565

Good luck
Shawn

buxiaoyang
Posts: 21
Joined: Wed Dec 05, 2012 1:25 pm

Re: Python driving ST7565 12864 LCD

Thu Dec 27, 2012 5:39 am

ukgamer wrote:Unfortunately neither of those changes work. They are now completely unrecognisable characters with the same "wrapping".

The Adafruit library is open sourced on GitHub at https://github.com/adafruit/ST7565-LCD but I don't have the know-how to port it over.
Sorry for that :(. Then it's not the font problem... Maybe we can set some commands to the LCD in init function to set the flipped text display normal. Let me check it and will keep you posted.

buxiaoyang
Posts: 21
Joined: Wed Dec 05, 2012 1:25 pm

Re: Python driving ST7565 12864 LCD

Thu Dec 27, 2012 1:09 pm

ukgamer wrote:Unfortunately neither of those changes work. They are now completely unrecognisable characters with the same "wrapping".

The Adafruit library is open sourced on GitHub at https://github.com/adafruit/ST7565-LCD but I don't have the know-how to port it over.
Hello,

I checked the datasheet of ST7565 and did some modify of the init code. Please try again to see what happens with follow code in your side:

Code: Select all

import RPi.GPIO as GPIO

LCD_CS = 24
LCD_RST = 21
LCD_A0 = 23
LCD_CLK = 22
LCD_SI = 17

def main():
   io_init()
   lcd_init()
   lcd_ascii168_string(0,0,"This is demo of")
   lcd_ascii168_string(0,2,"raspberry pi LCD")
   lcd_ascii168_string(0,4,"0123456789:;<=>?")
   lcd_ascii168_string(0,6,"@ABCDEFGHIJKLMNO")

def io_init():
   GPIO.setmode(GPIO.BCM)
   GPIO.setwarnings(False)
   GPIO.setup(LCD_CS, GPIO.OUT)
   GPIO.setup(LCD_RST, GPIO.OUT)
   GPIO.setup(LCD_A0, GPIO.OUT)
   GPIO.setup(LCD_CLK, GPIO.OUT)
   GPIO.setup(LCD_SI, GPIO.OUT)
   
def lcd_init():
   GPIO.output(LCD_CS, True)
   GPIO.output(LCD_RST, False)                      
   GPIO.output(LCD_RST, True)
   lcd_tranfer_data(0xe2,0); 	#Internal reset
   
   lcd_tranfer_data(0xa3,0); 	#Sets the LCD drive voltage bias ratio
   				##A2: 1/9 bias
   				##A3: 1/7 bias (ST7565V)
   				
   lcd_tranfer_data(0xa0,0);	#Sets the display RAM address SEG output correspondence
   				##A0: normal
   				##A1: reverse
   				
   lcd_tranfer_data(0xc8,0); 	#Select COM output scan direction
   				##C0~C7: normal direction
   				##C8~CF: reverse direction
   				
   lcd_tranfer_data(0xa4,0); 	#Display all points ON/OFF
   				##A4: normal display
   				##A5: all points ON
   				
   lcd_tranfer_data(0xa6,0);	#Sets the LCD display normal/reverse
   				##A6: normal
   				##A7: reverse
   				
   lcd_tranfer_data(0x2F,0);	#elect internal power supply operating mode
   				##28~2F: Operating mode
   				
   lcd_tranfer_data(0x60,0);	#Display start line set
   				##40~7F Display start address
   				
   lcd_tranfer_data(0x22,0); 	#V5 voltage regulator internal resistor ratio set(contrast)
   				##20~27 small~large
   				
   lcd_tranfer_data(0x81,0); 	#Electronic volume mode set
   				##81: Set the V5 output voltage
  				
   lcd_tranfer_data(0x30,0); 	#Electronic volume register set
   				##00~3F: electronic volume register 
   				
   lcd_tranfer_data(0xaf,0);   	#Display ON/OFF
   				##AF: ON
   				##AE: OFF
   lcd_clear()                      

def lcd_ascii168_string(xPos, yPos, string):
   stringLen = len(string)
   for i in range(0, stringLen):
      lcd_ascii168(xPos+i*8,yPos,ord(string[i])-32)

def lcd_ascii168(xPos, yPos, char):
   lcd_set_page(yPos,xPos)
   for i in range(0, 8): 
      lcd_tranfer_data(ASCII168[char][i],1)
   lcd_set_page(yPos+1,xPos)   
   for i in range(8, 16): 
      lcd_tranfer_data(ASCII168[char][i],1)

def lcd_clear():
   GPIO.output(LCD_CS, False)
   for i in range(0, 8):            
      lcd_set_page(i,0)
      for j in range(0, 128):                                           
         lcd_tranfer_data(0x00,1)
   GPIO.output(LCD_CS, True)

def lcd_set_page(page, column):
   lsb = column & 0x0f
   msb = column & 0xf0
   msb = msb>>4
   msb = msb | 0x10                  
   page = page | 0xb0                               
   lcd_tranfer_data(page,0)
   lcd_tranfer_data(msb,0)
   lcd_tranfer_data(lsb,0)
   

def lcd_tranfer_data(value, A0):
   GPIO.output(LCD_CS, False)
   GPIO.output(LCD_CLK, True)
   if(A0):
      GPIO.output(LCD_A0, True)
   else:
      GPIO.output(LCD_A0, False)
   lcd_byte(value)
   GPIO.output(LCD_CS, True)


def lcd_byte(bits):
   tmp = bits;
   for i in range(0, 8): 
      GPIO.output(LCD_CLK, False)
      if(tmp & 0x80):
         GPIO.output(LCD_SI, True)
      else:
         GPIO.output(LCD_SI, False)
      tmp = (tmp<<1)
      GPIO.output(LCD_CLK, True)
      
ASCII168=(
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#" ",0
(0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00),#"!",1
(0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#""",2
(0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00),#"#",3
(0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00),#"$",4
(0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00),#"%",5
(0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10),#"&",6
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00),#",",7
(0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00),#"(",8
(0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00),#")",9
(0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00),#"*",10
(0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00),#"+",11
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00),#",",12
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01),#"-",13
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00),#".",14
(0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00),#"/",15
(0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00),#"0",16
(0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"1",17
(0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00),#"2",18
(0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00),#"3",19
(0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00),#"4",20
(0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00),#"5",21
(0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00),#"6",22
(0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00),#"7",23
(0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00),#"8",24
(0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00),#"9",25
(0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00),#":",26
(0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00),#";",27
(0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00),#"<",28
(0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00),#"=",29
(0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00),#">",30
(0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00),#"?",31
(0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00),#"@",32
(0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20),#"A",33
(0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00),#"B",34
(0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00),#"C",35
(0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00),#"D",36
(0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00),#"E",37
(0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00),#"F",38
(0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00),#"G",39
(0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20),#"H",40
(0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"I",41
(0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00),#"J",42
(0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00),#"K",43
(0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00),#"L",44
(0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00),#"M",45
(0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00),#"N",46
(0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00),#"O",47
(0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00),#"P",48
(0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00),#"Q",49
(0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20),#"R",50
(0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00),#"S",51
(0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00),#"T",52
(0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00),#"U",53
(0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00),#"V",54
(0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00),#"W",55
(0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20),#"X",56
(0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00),#"Y",57
(0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00),#"Z",58
(0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00),#"[",59
(0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00),#"/",60
(0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00),#"]",61
(0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#"^",62
(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01),#"-",63
(0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00),#"\",64
(0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20),#"a",65
(0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00),#"b",66
(0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00),#"c",67
(0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20),#"d",68
(0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00),#"e",69
(0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"f",70
(0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00),#"g",71
(0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20),#"h",72
(0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"i",73
(0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00),#"j",74
(0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00),#"k",75
(0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00),#"l",76
(0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F),#"m",77
(0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20),#"n",79
(0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00),#"o",80
(0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00),#"p",81
(0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80),#"q",82
(0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00),#"r",83
(0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00),#"s",84
(0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00),#"t",85
(0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20),#"u",86
(0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00),#"v",87
(0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00),#"w",88
(0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00),#"x",89
(0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00),#"y",90
(0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00),#"z",91
(0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40),#"{",92
(0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00),#"|",93
(0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00),#"}",94
(0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#"~",95
)

main()
I also add some comments in the lcd_init() function. You also can refer to the comments and the datasheet i post before to adjust your LCD.

They should be some differences in init function between your LCD and my one. So i changed the code to set my LCD the same display as yours before to see if it will cause yours display normal. :D

Now my ones looks like:
Attachments
IMG_3013.jpg
IMG_3013.jpg (63.49 KiB) Viewed 13198 times

buxiaoyang
Posts: 21
Joined: Wed Dec 05, 2012 1:25 pm

Re: Python driving ST7565 12864 LCD

Thu Dec 27, 2012 1:32 pm

This command is to set the display flipped or not:

Code: Select all

lcd_tranfer_data(0xa0,0);   #Sets the display RAM address SEG output correspondence
               ##A0: normal
               ##A1: reverse
This command is to set the display start line:

Code: Select all

lcd_tranfer_data(0x60,0);   #Display start line set
               ##40~7F Display start address
You can change 0x60 to value between 0x40 and 0x7F to see what happens.

This command is to set something like display light:

Code: Select all

lcd_tranfer_data(0x30,0);    #Electronic volume register set
               ##00~3F: electronic volume register 
You can change 0x30 to value between 0x00 and 0x3F to choose a better one for your LCD.

And as i said before this command is to set the contrast:

Code: Select all

lcd_tranfer_data(0x22,0); 
The value of contrast between 0x20 and 0x27 from small to large. You can choose a perfect one for your LCD also.

Good luck!
Shawn

Return to “Python”

Who is online

Users browsing this forum: No registered users and 3 guests