Skip to content

Commit 4e0efdf

Browse files
'gem version 0.0.1
1 parent db1a80f commit 4e0efdf

File tree

7 files changed

+83
-38
lines changed

7 files changed

+83
-38
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.gem

Gemfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source "https://rubygems.org"
2+
3+
gem "pi_piper"
4+
5+
gemspec

Gemfile.lock

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
PATH
2+
remote: .
3+
specs:
4+
charlcd (0.0.1)
5+
6+
GEM
7+
remote: https://rubygems.org/
8+
specs:
9+
ffi (1.9.3)
10+
pi_piper (1.3.2)
11+
ffi
12+
13+
PLATFORMS
14+
ruby
15+
16+
DEPENDENCIES
17+
charlcd!
18+
pi_piper

README.md

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
Ruby library for lcd display compatible with the hd44780 controller on the raspberrypi.
1+
CharLcd
2+
=======
23

3-
code based on:
4-
https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code/blob/master/Adafruit_CharLCD/Adafruit_CharLCD.py
4+
Lcd display library compatible with the hd44780 controller on the raspberrypi.
55

66
wiring instructions:
77
http://learn.adafruit.com/drive-a-16x2-lcd-directly-with-a-raspberry-pi/overview
88

9-
pi_piper install instructions:
10-
https://github.com/jwhitehorn/pi_piper
11-
12-
example:
13-
```
14-
sudo ruby CharLcd_matrix_example.rb
15-
```
16-
179
usage:
1810
``` ruby
1911
char_lcd = CharLcd.new
2012
char_lcd.begin(16, 2)
2113
char_lcd.message("First Line\nSecond Line")
2214
```
15+
16+
License
17+
=======
18+
(The MIT License)
19+
20+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
21+
22+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
23+
24+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

charlcd.gemspec

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Gem::Specification.new do |s|
2+
s.name = 'charlcd'
3+
s.version = '0.0.1'
4+
s.date = '2014-11-25'
5+
s.summary = "Lcd display raspberrypi library!"
6+
s.description = "A lcd display library compatible with the hd44780 controller on the raspberrypi"
7+
s.authors = ["Fernando Fussuma"]
8+
s.email = '[email protected]'
9+
s.files = [
10+
"README.md",
11+
"lib/charlcd.rb",
12+
"examples/charlcd_matrix_example.rb"
13+
]
14+
s.homepage = 'https://github.com/fernandofussuma/CharLcd-ruby-raspberry-pi'
15+
s.license = 'MIT'
16+
end

CharLcd_matrix_example.rb renamed to examples/charlcd_matrix_example.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require_relative 'CharLcd'
1+
require 'charLcd'
22

33
SLEEP_TIME = 0.005
44
COLUMNS = 16
@@ -18,7 +18,7 @@ def rand_matrix(prng)
1818
(0..100).each do
1919
c = prng.rand(COLUMNS)
2020
for l in 0...LINES
21-
21+
2222
count = prng.rand(5)
2323
i = 0
2424
while i < count
@@ -28,14 +28,14 @@ def rand_matrix(prng)
2828
sleep(SLEEP_TIME)
2929
i += 1
3030
end
31-
31+
3232
if prng.rand(10).zero?
3333
count = prng.rand(5)
3434
i = 0
35-
35+
3636
c1 = prng.rand(COLUMNS)
3737
l1 = prng.rand(LINES)
38-
38+
3939
while i < count do
4040
lcd.set_cursor(c1, l1)
4141
lcd.write_4_bits(rand_matrix(prng), true)
@@ -44,7 +44,7 @@ def rand_matrix(prng)
4444
i += 1
4545
end
4646
end
47-
47+
4848
end
4949
end
5050

CharLcd.rb renamed to lib/charlcd.rb

+24-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
require 'pi_piper'
22

3+
# code based on:
4+
# https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code/blob/master/Adafruit_CharLCD/Adafruit_CharLCD.py
5+
36
class CharLcd
47
# commands
58
LCD_CLEARDISPLAY = 0x01
@@ -38,67 +41,67 @@ class CharLcd
3841
LCD_1LINE = 0x00
3942
LCD_5x10DOTS = 0x04
4043
LCD_5x8DOTS = 0x00
41-
44+
4245
def initialize(pin_rs = 25, pin_e = 24, pins_db = [23, 17, 27, 22])
4346
@pin_rs = PiPiper::Pin.new(:pin => pin_rs, :direction => :out)
4447
@pin_e = PiPiper::Pin.new(:pin => pin_e, :direction => :out)
4548
@pins_db = []
46-
49+
4750
pins_db.each { |pin_db| @pins_db.push(PiPiper::Pin.new(:pin => pin_db, :direction => :out)) }
48-
51+
4952
write_4_bits(0x33) # initialization
5053
write_4_bits(0x32) # initialization
5154
write_4_bits(0x28) # 2 line 5x7 matrix
5255
write_4_bits(0x0C) # turn cursor off 0x0E to enable cursor
5356
write_4_bits(0x06) # shift cursor right
54-
57+
5558
@display_control = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF
5659

57-
@display_function = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS
60+
@display_function = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS
5861
@display_function |= LCD_2LINE
5962

6063
# Initialize to default text direction (for romance languages)
6164
@display_mode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT
6265
write_4_bits(LCD_ENTRYMODESET | @display_mode) # set the entry mode
63-
66+
6467
clear
6568
end
66-
69+
6770
def begin(cols, lines)
6871
if lines > 1
6972
@number_lines = lines
7073
@display_function |= LCD_2LINE
7174
end
7275
end
73-
76+
7477
def home
7578
write_4_bits(LCD_RETURNHOME)
7679
delay_microseconds(3000)
7780
end
78-
81+
7982
def clear
8083
write_4_bits(LCD_CLEARDISPLAY) # command to clear display
8184
delay_microseconds(3000) # 3000 microsecond sleep, clearing the display takes a long time
8285
end
83-
86+
8487
def set_cursor(col, row)
8588
row_offsets = [0x00, 0x40, 0x14, 0x54]
86-
89+
8790
row = @number_lines - 1 if (row > @number_lines)
88-
91+
8992
write_4_bits(LCD_SETDDRAMADDR | col + row_offsets[row])
9093
end
91-
94+
9295
def no_display
9396
@display_control &= ~LCD_DISPLAYON
9497
write_4_bits(LCD_DISPLAYCONTROL | @display_control)
9598
end
96-
99+
97100
def display
98101
@display_control |= LCD_DISPLAYON
99102
write_4_bits(LCD_DISPLAYCONTROL | @display_control)
100103
end
101-
104+
102105
def no_cursor
103106
@display_control &= ~LCD_CURSORON
104107
write_4_bits(LCD_DISPLAYCONTROL | @display_control)
@@ -146,7 +149,7 @@ def no_autoscroll
146149
@display_mode &= ~LCD_ENTRYSHIFTINCREMENT
147150
write_4_bits(LCD_ENTRYMODESET | @display_mode)
148151
end
149-
152+
150153
def message(text)
151154
text.each_char do |char|
152155
if char.eql?("\n")
@@ -156,7 +159,7 @@ def message(text)
156159
end
157160
end
158161
end
159-
162+
160163
def write_4_bits(bits, char_mode = false)
161164
delay_microseconds(1000)
162165

@@ -174,18 +177,18 @@ def write_4_bits(bits, char_mode = false)
174177

175178
pulse_enable
176179
end
177-
180+
178181
def pulse_enable
179182
@pin_e.off
180183
delay_microseconds(1)
181184
@pin_e.on
182185
delay_microseconds(1)
183186
@pin_e.off
184187
end
185-
188+
186189
def delay_microseconds(microseconds)
187190
seconds = microseconds/1_000_000.0
188191
sleep(seconds)
189192
end
190-
191-
end
193+
194+
end

0 commit comments

Comments
 (0)