擅长:python、mysql、java
<p>您应该非常小心地以<code>root</code>的形式运行。由于<code>root</code>可以访问所有内容,因此一个简单的错误就可能导致系统无法使用。在</p>
<p>作为普通用户访问硬件的正确方法是更改对所需设备文件的权限。在</p>
<p>您提到的实用程序似乎使用了<a href="http://wiringpi.com/" rel="nofollow noreferrer">WiringPi</a>库。对<a href="https://git.drogon.net/?p=wiringPi;a=blob;f=wiringPi/wiringPi.c;h=503151f61014418b9c42f4476a6086f75cd4e64b;hb=HEAD" rel="nofollow noreferrer">source code</a>的一些挖掘表明它使用<code>/dev/gpiomem</code>(或<code>/dev/mem</code>)设备。在</p>
<p>在raspbian上,使用<code>udev</code>设置设备权限。请参见<a href="https://unix.stackexchange.com/questions/147494/how-can-i-set-device-rw-permissions-permanently-on-raspbian">here</a>和{a4}。在</p>
<p>您可以通过创建一个文件,例如<code>/etc/udev/rules.d/local.rules</code>并将以下文本放入其中,从而为每个用户提供对<code>/dev/gpiomem</code>和其他gpio设备的访问权限:</p>
<pre><code>ACTION=="add", KERNEL=="gpio*", MODE="0666"
ACTION=="add", KERNEL=="i2c-[0-9]*", MODE="0666"
</code></pre>
<p>第一行提供gpio设备,第二行提供I2C设备。在</p>