-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLCD_basic.py
More file actions
executable file
·43 lines (33 loc) · 1015 Bytes
/
LCD_basic.py
File metadata and controls
executable file
·43 lines (33 loc) · 1015 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python3
# Distributed with a free-will license.
#
#This is basic functions for the LCD display
import time
import smbus
LCD_Addr = 0x3E
# Get I2C bus
bus0 = smbus.SMBus(0)
def LCD_home():
buf = [0x00,0x02];
bus0.write_i2c_block_data(LCD_Addr,0,buf) #Set to Home
def LCD_print(str):
buf1=[0x00,0x80]
bus0.write_i2c_block_data(LCD_Addr,0,buf1)
bus0.write_i2c_block_data(LCD_Addr,0x40,[ord(c) for c in str])
def LCD_init():
init1 = [0x00,0x38]
init2 = [0x00, 0x39, 0x14,0x74,0x54,0x6f,0x0c,0x01]
# 2 lines 8 bit 3.3V Version
bus0.write_i2c_block_data(LCD_Addr,0,init1)
bus0.write_i2c_block_data(LCD_Addr,0,init2)
def LCD_clear():#!/usr/bin/python3
buf = [0x00,0x01];
bus0.write_i2c_block_data(LCD_Addr,0,buf) #Clear LCD
LCD_init() # Initialize the LCD
while True:
instr = raw_input(" Input Text for display >")
LCD_clear()
if len(instr) <= 20:
LCD_print(instr)
else:
LCD_print(instr[:20])