Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

gpio ruby gem allows for ruby code running on devices such as raspberry pi or systems with 1wire usb adapters to speak to the system's input/output pins. the end goal is for people to contribute code for specific devices, sensors and outputs.

branch: master
README.md

description

a ruby gem and repository to contribute gpio code for devices such as Raspberry Pi to read sensors and control outputs.

gpio allows for devices such as raspberry pi or systems with 1wire usb adapters to speak to the system's input/output pins.

installation

bundler

using bundler, add this to your Gemfile in the root of your app

gem 'gpio'

install bundler and then run bundle install

gem install bundler
bundle install

gem install

from command line

gem install gpio

require in your ruby file

require 'gpio'

example

let's setup a motion sensor on GPIO pin 17 on a RaspberryPi (default).

motion = GPIO::MotionDetector.new(pin: 17)

do we detect and motion yet?

motion.detect

let's print a message corresponding to the motion.detect?

puts motion.detect ? "Motion detected!" : "No motion detected."

was the value any different than the last time it detected?

motion.changed?
puts "last: #{motion.last_reading}, current: #{motion.reading}"

wait until the value changes before we move on.

until motion.changed? do
    motion.detect
    sleep 0.5
end
puts "Something changed!"
puts "last: #{motion.last_reading}, current: #{motion.reading}"
Something went wrong with that request. Please try again.