Skip to content

Commit 8229936

Browse files
Merge pull request #3 from jvlobo/master
Changed GPIO library from pi_piper to rpi_gpio
2 parents 90039f0 + e431981 commit 8229936

File tree

5 files changed

+31
-15
lines changed

5 files changed

+31
-15
lines changed

Diff for: Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
source "https://rubygems.org"
22

3-
gem "pi_piper"
3+
gem “rpi_gpio”
44

55
gemspec

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ require 'charlcd'
1818
char_lcd = CharLcd.new
1919
char_lcd.begin(16, 2)
2020
char_lcd.message("First Line\nSecond Line")
21+
char_lcd.clean_pins()
2122
```
2223

2324
License

Diff for: charlcd.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'charlcd'
3-
s.version = '0.0.1'
3+
s.version = '0.0.2'
44
s.date = '2014-11-25'
55
s.summary = "Lcd display raspberrypi library!"
66
s.description = "A lcd display library compatible with the hd44780 controller on the raspberrypi"

Diff for: examples/charlcd_matrix_example.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'charLcd'
1+
require 'rpi_gpio'
22

33
SLEEP_TIME = 0.005
44
COLUMNS = 16

Diff for: lib/charlcd.rb

+27-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'pi_piper'
1+
require 'rpi_gpio'
22

33
# code based on:
44
# https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code/blob/master/Adafruit_CharLCD/Adafruit_CharLCD.py
@@ -43,11 +43,19 @@ class CharLcd
4343
LCD_5x8DOTS = 0x00
4444

4545
def initialize(pin_rs = 25, pin_e = 24, pins_db = [23, 17, 27, 22])
46-
@pin_rs = PiPiper::Pin.new(:pin => pin_rs, :direction => :out)
47-
@pin_e = PiPiper::Pin.new(:pin => pin_e, :direction => :out)
46+
RPi::GPIO.set_numbering :bcm
47+
48+
RPi::GPIO.setup pin_rs, :as => :output
49+
RPi::GPIO.setup pin_e, :as => :output
50+
51+
@pin_rs = pin_rs
52+
@pin_e = pin_e
4853
@pins_db = []
4954

50-
pins_db.each { |pin_db| @pins_db.push(PiPiper::Pin.new(:pin => pin_db, :direction => :out)) }
55+
pins_db.each { |pin_db|
56+
@pins_db.push(pin_db)
57+
RPi::GPIO.setup pin_db, :as => :output
58+
}
5159

5260
write_4_bits(0x33) # initialization
5361
write_4_bits(0x32) # initialization
@@ -165,30 +173,37 @@ def write_4_bits(bits, char_mode = false)
165173

166174
bits = bits.to_s(2).rjust(8, "0")
167175

168-
@pin_rs.update_value(char_mode)
176+
if char_mode
177+
RPi::GPIO.set_high @pin_rs
178+
else
179+
RPi::GPIO.set_low @pin_rs
180+
end
169181

170-
@pins_db.each { |pin_db| pin_db.off }
171-
(0..3).each { |i| @pins_db.reverse[i].on if bits[i].eql?("1") }
182+
@pins_db.each { |pin_db| RPi::GPIO.set_low pin_db }
183+
(0..3).each { |i| RPi::GPIO.set_high @pins_db.reverse[i] if bits[i].eql?("1") }
172184

173185
pulse_enable
174186

175-
@pins_db.each { |pin_db| pin_db.off }
176-
(4..7).each { |i| @pins_db.reverse[i - 4].on if bits[i].eql?("1") }
187+
@pins_db.each { |pin_db| RPi::GPIO.set_low pin_db }
188+
(4..7).each { |i| RPi::GPIO.set_high @pins_db.reverse[i - 4] if bits[i].eql?("1") }
177189

178190
pulse_enable
179191
end
180192

181193
def pulse_enable
182-
@pin_e.off
194+
RPi::GPIO.set_low @pin_e
183195
delay_microseconds(1)
184-
@pin_e.on
196+
RPi::GPIO.set_high @pin_e
185197
delay_microseconds(1)
186-
@pin_e.off
198+
RPi::GPIO.set_low @pin_e
187199
end
188200

189201
def delay_microseconds(microseconds)
190202
seconds = microseconds/1_000_000.0
191203
sleep(seconds)
192204
end
193205

206+
def clean_pins
207+
RPi::GPIO.clean_up
208+
end
194209
end

0 commit comments

Comments
 (0)