rpi_lcd16x2 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -0
- data/lib/rpi_lcd16x2.rb +173 -0
- metadata +68 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5833e45304faebe96d020d38da2d916cf83df6e2
|
4
|
+
data.tar.gz: 8ee10fc1802f83bc5658e85ad19e7cd0646a3a41
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 73ec222e574557b8119e83fa71d89d8a5c179a66be3d6a7889b43286f027b13be416bd5d9ac4d22808a36c10c0f442cdcebd29ca7e4761fb6079a470306405ce
|
7
|
+
data.tar.gz: 20c2bc9f07f1813565d27b10791a4d536deb70ed7a8169a05e6b6a9b6e143bc6a4883e04deccd7b549f47c8466c0e7e5aab9f2dc00ec1dc7ec37b285c289e675
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
o�;�����?��dbn?+�s��U��z�R;�dN�OUl#��d�����Ԁ��tF�^�s��5�(�����/�#�C0Aw{m�P�4���W�&�+�Ȝ��b�':ۚU#x��H;Uq��T��"*C� �u�u7]��Uz]��<�4��k�Ҟ������vl�<�DY�vn�zH-���ϋ����}4'C�<׃�s��O���a�> ߺ���'�]F��%�Y��q|�lG�M��vZz��a_���SѢ
|
data/lib/rpi_lcd16x2.rb
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: rpi_lcd16x2.rb
|
4
|
+
|
5
|
+
# code originally copied from https://github.com/RobvanB/Ruby-RaspberryPi-LCD
|
6
|
+
|
7
|
+
require 'wiringpi'
|
8
|
+
|
9
|
+
T_MS = 1.0000000/1000000
|
10
|
+
ON = 1
|
11
|
+
OFF = 0
|
12
|
+
|
13
|
+
class RpiLcd16x2
|
14
|
+
|
15
|
+
def initialize(string='hello world', p_rs: 11, p_en: 10, d4: 6, d5: 5, d6: 4, d7: 1)
|
16
|
+
|
17
|
+
@p_rs, @p_en, @d4, @d5, @d6, @d7 = p_rs, p_en, d4, d5, d6, d7
|
18
|
+
|
19
|
+
@char_count = 0
|
20
|
+
|
21
|
+
Wiringpi.wiringPiSetup
|
22
|
+
|
23
|
+
# Set all pins to output mode
|
24
|
+
[p_rs, p_en, d7, d6, d5, d4].each {|pin,val| Wiringpi.pinMode(pin, 1)}
|
25
|
+
|
26
|
+
init_display()
|
27
|
+
sleep T_MS * 10
|
28
|
+
lcd_display(ON, ON, OFF)
|
29
|
+
set_entry_mode()
|
30
|
+
cls
|
31
|
+
text string
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
# Clear all data from screen
|
36
|
+
#
|
37
|
+
def cls()
|
38
|
+
[0,1].each {|x| write_command d4: x}
|
39
|
+
end
|
40
|
+
|
41
|
+
def text(s)
|
42
|
+
# If the string is longer than 16 char - split it.
|
43
|
+
if (s.length > 16)
|
44
|
+
s.split(" ").each do |x|
|
45
|
+
print_text(x)
|
46
|
+
next_line()
|
47
|
+
sleep 1
|
48
|
+
end
|
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
|
83
|
+
#
|
84
|
+
def set_entry_mode()
|
85
|
+
|
86
|
+
write_command
|
87
|
+
write_command d6: 1, d5: 1
|
88
|
+
sleep T_MS
|
89
|
+
end
|
90
|
+
|
91
|
+
# Write data to CGRAM/DDRAM
|
92
|
+
#
|
93
|
+
def lcd_write(a)
|
94
|
+
|
95
|
+
write_command rs: 1, d7: a[0], d6: a[1], d5: a[2], d4: a[3]
|
96
|
+
write_command rs: 1, d7: a[4], d6: a[5], d5: a[6], d4: a[7]
|
97
|
+
@char_count += 1
|
98
|
+
end
|
99
|
+
|
100
|
+
# Set function to 4 bit operation
|
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
|
110
|
+
|
111
|
+
# D7: N = 0 = 1 line display
|
112
|
+
# D6: F = 0 = 5x8 character font
|
113
|
+
|
114
|
+
write_command d7: 1; sleep T_MS
|
115
|
+
|
116
|
+
# Display Off (2 blocks)
|
117
|
+
write_command; sleep T_MS
|
118
|
+
write_command d7: 1; sleep T_MS
|
119
|
+
|
120
|
+
# Display clear (2 blocks)
|
121
|
+
write_command; sleep T_MS
|
122
|
+
write_command d4: 1; sleep T_MS
|
123
|
+
|
124
|
+
# Entry mode set"
|
125
|
+
write_command; sleep T_MS
|
126
|
+
|
127
|
+
# D5: 1 = Increment by 1
|
128
|
+
# D4: 0 = no shift
|
129
|
+
|
130
|
+
write_command d6: 1, d5: 1, d4: 1
|
131
|
+
end
|
132
|
+
|
133
|
+
def print_text(s)
|
134
|
+
|
135
|
+
# Loop through each character in the string, convert it to binary,
|
136
|
+
# and print it to the LCD
|
137
|
+
|
138
|
+
s.split(//).each do | c |
|
139
|
+
|
140
|
+
bc = c.bytes.first.to_s(2)
|
141
|
+
while bc.length < 8
|
142
|
+
bc = "0" + bc
|
143
|
+
end
|
144
|
+
|
145
|
+
bina = []
|
146
|
+
bc.split().each {}
|
147
|
+
bc.split(//).each{ |x| bina << x.to_i }
|
148
|
+
|
149
|
+
if (bc)
|
150
|
+
lcd_write(bina)
|
151
|
+
bc = nil
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# Display automatically goes to next line when we hit 40 chars
|
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)
|
169
|
+
|
170
|
+
@char_count = 0
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rpi_lcd16x2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
|
14
|
+
YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJom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ej+uSK5iNL8nWVVavfbBFYHTEVHtsULRpFvJ
|
30
|
+
hTrXUYI3FNofnfeYBrK7qXkjpKMJv8UbOvU1mfSB/QiNED4vC+g71RKnNDjhVlrW
|
31
|
+
ZwpzKBOmi7OYBuBy3q1GGg3t+VgVp9Z4Eg2TyGWFT+vrpKHB/+jeP4Rv8827/KDs
|
32
|
+
tlNQqZyiZthqbQ==
|
33
|
+
-----END CERTIFICATE-----
|
34
|
+
date: 2014-08-11 00:00:00.000000000 Z
|
35
|
+
dependencies: []
|
36
|
+
description:
|
37
|
+
email: james@r0bertson.co.uk
|
38
|
+
executables: []
|
39
|
+
extensions: []
|
40
|
+
extra_rdoc_files: []
|
41
|
+
files:
|
42
|
+
- lib/rpi_lcd16x2.rb
|
43
|
+
homepage: https://github.com/jrobertson/rpi_lcd16x2
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.1.0
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.2.2
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Display text on a 16x2 LCD connected to a Raspberry Pi
|
67
|
+
test_files: []
|
68
|
+
has_rdoc:
|
metadata.gz.sig
ADDED
Binary file
|