当尝试使用各种宝石(wirespi,pi_piper,ruby-gpio,rpi_gpio)使用带有ruby的GPIO时,我尝试运行脚本来控制GPIO引脚时出现“Permission Denied”错误。我正在使用RVM来管理gemsets和版本,所以使用sudo根本无法帮助我。有没有允许在GPIO引脚上进行通信?
(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>'
有问题的剧本
#! /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