2

When trying to use GPIO with ruby using various gems (wiringpi, pi_piper, ruby-gpio, rpi_gpio) I get a "Permission Denied" error trying to run a script to control GPIO pins. I am using RVM to manage gemsets and versions, so using sudo will not help me at all. Is there someway to allow communication on the GPIO pins?

(ssh) pi@raspberrypi : ~/ruby/gpio/led_flash
[127] % ./led_flash.rb
/home/pi/.rvm/gems/ruby-1.9.3-p551/gems/ruby-gpio-0.0.2/lib/ruby-gpio.rb:111:in `initialize': Permission denied - /sys/class/gpio/gpio17/direction (Errno::EACCES)
        from /home/pi/.rvm/gems/ruby-1.9.3-p551/gems/ruby-gpio-0.0.2/lib/ruby-gpio.rb:111:in `open'
        from /home/pi/.rvm/gems/ruby-1.9.3-p551/gems/ruby-gpio-0.0.2/lib/ruby-gpio.rb:111:in `write'
        from /home/pi/.rvm/gems/ruby-1.9.3-p551/gems/ruby-gpio-0.0.2/lib/ruby-gpio.rb:27:in `as'
        from ./led_flash.rb:6:in `block in <main>'
        from /home/pi/.rvm/gems/ruby-1.9.3-p551/gems/ruby-gpio-0.0.2/lib/ruby-gpio.rb:82:in `instance_eval'
        from /home/pi/.rvm/gems/ruby-1.9.3-p551/gems/ruby-gpio-0.0.2/lib/ruby-gpio.rb:82:in `access'
        from ./led_flash.rb:5:in `<main>'

Script in question

#! /usr/bin/env ruby

require 'ruby-gpio'

GPIO.access(led: 17, button: 18) do
  led.as :out
  button.as :in
  led.off

  button.async.watch_once_for(1) do
    if led.read == 1
      led.off
    else
      led.on
    end
  end

  sleep
end
redcodefinal
  • 909
  • 3
  • 11
  • 24
  • May be [this](http://stackoverflow.com/questions/22597223/errnoeaccess-permission-denied-running-compass-watch) similar question may give some clue on the fix. – bprasanna Apr 16 '15 at 05:07
  • @learningloop This is an issue with not being privileged enough to access the GPIO from a RVM ruby since `sudo ./led_flash.rb` will complain that ruby-gpio doesn't exist. This has nothing to do with sass or compass. – redcodefinal Apr 16 '15 at 05:10
  • possible duplicate of [Accessing the GPIO (of a raspberry pi) without \`\`sudo\`\`](http://stackoverflow.com/questions/12133860/accessing-the-gpio-of-a-raspberry-pi-without-sudo) –  Apr 16 '15 at 05:13
  • @stacksonstacks tried it and to no avail. Is there some way to "sudo" rvm so I can just use the modified ruby versioning on sudo? – redcodefinal Apr 16 '15 at 05:19

0 Answers0