rpi_lcd16x2 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/rpi_lcd16x2.rb +56 -122
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c42a54f9093e60f9d28777f8d97f3a11fcdd05d2
|
4
|
+
data.tar.gz: f7b0d6555f0f94972257bf9a45292bf35a7a4363
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2e66aa61980af0dc958efa218d06f18789dcd300630667d28a25906e6848191c8e4f120652be37bf4634740d7033cba6187e18aae52b344965215298395a1ee
|
7
|
+
data.tar.gz: fcf61fcfc4582de9dc606921a5c076273098a1e9eaf43b72fc02ec218dc7475e1a11692903f0913945f98678a6e942e0a1ff360e0625d3a956c8bf5c3644ad64
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/rpi_lcd16x2.rb
CHANGED
@@ -3,89 +3,47 @@
|
|
3
3
|
# file: rpi_lcd16x2.rb
|
4
4
|
|
5
5
|
# code originally copied from https://github.com/RobvanB/Ruby-RaspberryPi-LCD
|
6
|
+
# instruction set reference https://en.wikipedia.org/wiki/HD44780_Character_LCD
|
6
7
|
|
7
8
|
require 'wiringpi'
|
8
9
|
|
9
|
-
T_MS =
|
10
|
-
|
11
|
-
OFF = 0
|
10
|
+
T_MS = 0.000001
|
11
|
+
|
12
12
|
|
13
13
|
class RpiLcd16x2
|
14
14
|
|
15
|
-
def initialize(string='
|
15
|
+
def initialize(string='', p_rs: 11, p_en: 10, d4: 6, d5: 5, d6: 4, d7: 1)
|
16
16
|
|
17
17
|
@p_rs, @p_en, @d4, @d5, @d6, @d7 = p_rs, p_en, d4, d5, d6, d7
|
18
18
|
|
19
|
-
@char_count = 0
|
20
|
-
|
21
19
|
Wiringpi.wiringPiSetup
|
22
20
|
|
23
21
|
# Set all pins to output mode
|
24
22
|
[p_rs, p_en, d7, d6, d5, d4].each {|pin,val| Wiringpi.pinMode(pin, 1)}
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
set_entry_mode()
|
30
|
-
cls
|
31
|
-
text string
|
32
|
-
|
24
|
+
function_set # sets the display to use 4-bit instructions
|
25
|
+
cursor_off
|
26
|
+
print string unless string.empty?
|
33
27
|
end
|
34
28
|
|
35
29
|
# Clear all data from screen
|
36
30
|
#
|
37
|
-
def cls()
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
def
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
else
|
50
|
-
print_text(s)
|
51
|
-
end
|
52
|
-
next_line()
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
# Indicate to LCD that command should be 'executed'
|
58
|
-
#
|
59
|
-
def pulse_enable()
|
60
|
-
[0,1,0].each {|x| Wiringpi.digitalWrite(@p_en, x); sleep T_MS * 10}
|
61
|
-
end
|
62
|
-
|
63
|
-
# Turn on display and cursor
|
64
|
-
#
|
65
|
-
# 1 = 0n
|
66
|
-
# 1 = Cursor on, 0 = Cursor off
|
67
|
-
# 1 = Block, 0 = Underline cursor
|
68
|
-
#
|
69
|
-
def lcd_display(display, cursor, block)
|
70
|
-
|
71
|
-
write_command
|
72
|
-
write_command d7: 1, d6: display, d5: cursor, d4: block
|
73
|
-
end
|
74
|
-
|
75
|
-
def write_command(rs: 0, d7: 0, d6: 0, d5: 0, d4: 0)
|
76
|
-
|
77
|
-
[@p_rs, @d7, @d6, @d5, @d4,].zip([rs,d7,d6,d5,d4])\
|
78
|
-
.each {|pin,val| Wiringpi.digitalWrite(pin, val)}
|
79
|
-
pulse_enable()
|
80
|
-
end
|
81
|
-
|
82
|
-
# Entry mode set: move cursor to right after each DD/CGRAM write
|
31
|
+
def cls() cmd d4: 1 end
|
32
|
+
|
33
|
+
def cursor(direction=1) cmd d7: 1, d6: direction, d5: nil, d4: nil end
|
34
|
+
def cursor_off() cmd d7: 1, d6: 1, d5: 0 end
|
35
|
+
def cursor_on() cmd d7: 1, d6: 1, d5: 1 end
|
36
|
+
def display_off() cmd d7: 1 end
|
37
|
+
def display_on() cmd d7: 1, d6: 1 end
|
38
|
+
|
39
|
+
# Sets cursor move direction (I/D); specifies to shift the display (S).
|
40
|
+
# I/D - increment = 1 or decrement = 0
|
41
|
+
# S - 0 = no display shift, 1 = display shift
|
42
|
+
# e.g. 0 0 0 0 1 D C B
|
83
43
|
#
|
84
|
-
def
|
85
|
-
|
86
|
-
write_command
|
87
|
-
write_command d6: 1, d5: 1
|
88
|
-
sleep T_MS
|
44
|
+
def entry(direction=1)
|
45
|
+
write_command rs: 1, d7: 0, d6: 0, d5: 0, d4: 1
|
46
|
+
write_command rs: 1, d7: 0, d6: direction, d5: nil, d4: nil
|
89
47
|
end
|
90
48
|
|
91
49
|
# Write data to CGRAM/DDRAM
|
@@ -94,80 +52,56 @@ class RpiLcd16x2
|
|
94
52
|
|
95
53
|
write_command rs: 1, d7: a[0], d6: a[1], d5: a[2], d4: a[3]
|
96
54
|
write_command rs: 1, d7: a[4], d6: a[5], d5: a[6], d4: a[7]
|
97
|
-
@char_count += 1
|
98
55
|
end
|
99
56
|
|
100
|
-
|
101
|
-
#
|
102
|
-
def init_display()
|
103
|
-
|
104
|
-
3.times { sleep 42 * T_MS; write_command d5: 1, d4: 1 }
|
105
|
-
|
106
|
-
# Function set to 4 bit
|
107
|
-
2.times { write_command d5: 1}
|
108
|
-
|
109
|
-
# Set number of display lines
|
57
|
+
def home() cmd d5: 1 end
|
110
58
|
|
111
|
-
# D7: N = 0 = 1 line display
|
112
|
-
# D6: F = 0 = 5x8 character font
|
113
59
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
# Display clear (2 blocks)
|
121
|
-
write_command; sleep T_MS
|
122
|
-
write_command d4: 1; sleep T_MS
|
60
|
+
def print(raw_s)
|
61
|
+
cls
|
62
|
+
s = raw_s.split(/\n/).map {|x| x.ljust(40)}.join
|
63
|
+
print_text s
|
64
|
+
end
|
123
65
|
|
124
|
-
|
125
|
-
write_command; sleep T_MS
|
66
|
+
alias text print
|
126
67
|
|
127
|
-
|
128
|
-
# D4: 0 = no shift
|
68
|
+
def print_text(s)
|
129
69
|
|
130
|
-
|
70
|
+
s.each_byte.to_a.each do |x|
|
71
|
+
lcd_write ("%08b" % x).each_char.to_a.map(&:to_i)
|
72
|
+
end
|
131
73
|
end
|
132
74
|
|
133
|
-
|
75
|
+
protected
|
134
76
|
|
135
|
-
|
136
|
-
# and print it to the LCD
|
137
|
-
|
138
|
-
s.split(//).each do | c |
|
77
|
+
def cmd(h) write_command; write_command h; sleep 0.01 end
|
139
78
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
79
|
+
# Sets interface data length (DL), number of display line (N),
|
80
|
+
# and character font (F).
|
81
|
+
# DL - 0 = 4-bit interface, 1 = 8-bit interface
|
82
|
+
# N - 0 = 1/8 or 1/11 duty (1 line), 1 = 1/16 duty (2 lines)
|
83
|
+
# F - 0 = 5×8 dots, 1 = 5×10 dots
|
84
|
+
# e.g. 0 0 1 DL N F * *
|
85
|
+
# d7 d6 d5 d4 d7 d6 d5 d4
|
86
|
+
def function_set()
|
87
|
+
write_command rs: 1, d7: 0, d6: 0, d5: 1, d4: 0
|
88
|
+
write_command rs: 1, d7: 1, d6: 0, d5: nil, d4: nil
|
89
|
+
end
|
144
90
|
|
145
|
-
|
146
|
-
bc.split().each {}
|
147
|
-
bc.split(//).each{ |x| bina << x.to_i }
|
91
|
+
def write_command(rs: 0, d7: 0, d6: 0, d5: 0, d4: 0)
|
148
92
|
|
149
|
-
|
150
|
-
|
151
|
-
bc = nil
|
152
|
-
end
|
93
|
+
[@p_rs, @d7, @d6, @d5, @d4,].zip([rs,d7,d6,d5,d4]).each do |pin,val|
|
94
|
+
Wiringpi.digitalWrite(pin, val) if val
|
153
95
|
end
|
96
|
+
pulse_enable()
|
154
97
|
end
|
155
98
|
|
156
|
-
|
157
|
-
#
|
158
|
-
def next_line()
|
159
|
-
|
160
|
-
fill_str = " "
|
161
|
-
fill_cntr = 1
|
162
|
-
|
163
|
-
while (@char_count + fill_cntr < 40)
|
164
|
-
fill_str += " "
|
165
|
-
fill_cntr += 1
|
166
|
-
end
|
167
|
-
|
168
|
-
print_text(fill_str)
|
99
|
+
private
|
169
100
|
|
170
|
-
|
101
|
+
# Indicate to LCD that command should be 'executed'
|
102
|
+
#
|
103
|
+
def pulse_enable()
|
104
|
+
[0,1,0].each {|x| Wiringpi.digitalWrite(@p_en, x); sleep T_MS * 10}
|
171
105
|
end
|
172
106
|
|
173
|
-
end
|
107
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rpi_lcd16x2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
ZwpzKBOmi7OYBuBy3q1GGg3t+VgVp9Z4Eg2TyGWFT+vrpKHB/+jeP4Rv8827/KDs
|
32
32
|
tlNQqZyiZthqbQ==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2014-08-
|
34
|
+
date: 2014-08-12 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: wiringpi
|
metadata.gz.sig
CHANGED
Binary file
|