blob: 4251a8070098cd7b022adc535154f07a73c5e74e [file] [log] [blame]
Philip Howardfa09d182013-04-01 21:11:00 +00001# Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander )
Phil Howard6577b7e2016-03-09 12:19:22 +00002import wiringpi
Philip Howardfa09d182013-04-01 21:11:00 +00003
4PIN_BACKLIGHT = 67 # LED
5PIN_SCLK = 68 # Clock SCLK
6PIN_SDIN = 69 # DN(MOSI)
7PIN_DC = 70 # D/C
8PIN_RESET = 71 # RST Reset
9PIN_SCE = 72 # SCE
10
11#PIN_BACKLIGHT = 5
12#PIN_SCLK = 4
13#PIN_SDIN = 3
14#PIN_DC = 2
15#PIN_RESET = 1
16#PIN_SCE = 0
17
18OUTPUT = 1
19INPUT = 0
20HIGH = 1
21LOW = 0
22
23LCD_C = 0
24LCD_D = 1
25
26LCD_X = 84
27LCD_Y = 48
28LCD_SEGS = 504
29
30MSBFIRST = 1
31LSBFIRST = 0
32
33SLOW_DOWN = 400
34
35pin_base = 65
36i2c_addr = 0x21
37
38wiringpi.wiringPiSetup()
39wiringpi.mcp23017Setup(pin_base,i2c_addr)
40
41def slow_shift_out(data_pin, clock_pin, data):
42 for bit in bin(data).replace('0b','').rjust(8,'0'):
43 wiringpi.digitalWrite(clock_pin,LOW)
44 wiringpi.delay(SLOW_DOWN)
45 wiringpi.digitalWrite(data_pin,int(bit))
46 wiringpi.delay(SLOW_DOWN)
47 wiringpi.digitalWrite(clock_pin,HIGH)
48 wiringpi.delay(SLOW_DOWN)
49
50def lcd_write(dc, data):
51 wiringpi.digitalWrite(PIN_DC, dc)
52 wiringpi.digitalWrite(PIN_SCE, LOW)
53 wiringpi.delay(SLOW_DOWN)
54 #wiringpi.shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data)
55 slow_shift_out(PIN_SDIN, PIN_SCLK, data)
56 wiringpi.digitalWrite(PIN_SCE, HIGH)
57 wiringpi.delay(SLOW_DOWN)
58 #wiringpi.delay(2)
59
60def lcd_initialise():
61 wiringpi.pinMode(PIN_BACKLIGHT,OUTPUT)
62 wiringpi.digitalWrite(PIN_BACKLIGHT, HIGH)
63 wiringpi.pinMode(PIN_SCE, OUTPUT)
64 wiringpi.pinMode(PIN_RESET, OUTPUT)
65 wiringpi.pinMode(PIN_DC, OUTPUT)
66 wiringpi.pinMode(PIN_SDIN, OUTPUT)
67 wiringpi.pinMode(PIN_SCLK, OUTPUT)
68 wiringpi.digitalWrite(PIN_RESET, LOW)
69 wiringpi.delay(SLOW_DOWN)
70 wiringpi.digitalWrite(PIN_RESET, HIGH)
71 wiringpi.delay(SLOW_DOWN)
72 lcd_write(LCD_C, 0x21 ) # LCD Extended Commands.
73 lcd_write(LCD_C, 0xCC ) # Set LCD Vop (Contrast).
74 lcd_write(LCD_C, 0x04 ) # Set Temp coefficent. //0x04
75 lcd_write(LCD_C, 0x14 ) # LCD bias mode 1:48. //0x13
76 lcd_write(LCD_C, 0x0C ) # LCD in normal mode.
77 lcd_write(LCD_C, 0x20 )
78 lcd_write(LCD_C, 0x0C )
79
80def lcd_clear():
81 for time in range(0, LCD_SEGS):
82 lcd_write(LCD_D, 0x00)
83
84def lcd_fill():
85 for time in range(0, LCD_SEGS):
86 lcd_write(LCD_D, 0xFF)
87
88
89lcd_initialise()
90
91for time in range(0,4):
92 lcd_clear()
93 wiringpi.delay(1000)
94 lcd_fill()
Phil Howard6577b7e2016-03-09 12:19:22 +000095 wiringpi.delay(1000)