<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Udev :: 标签 :: yafeng 的博客</title>
    <link>https://yafengabc.github.io/tags/udev/index.html</link>
    <description></description>
    <generator>Hugo</generator>
    <language>zh-cn</language>
    <lastBuildDate>Sat, 19 Sep 2026 16:30:07 +0800</lastBuildDate>
    <atom:link href="https://yafengabc.github.io/tags/udev/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>让普通用户可以控制树莓派的GPIO(Archlinuxarm)</title>
      <link>https://yafengabc.github.io/cnblogs/p8873397/index.html</link>
      <pubDate>Wed, 18 Apr 2018 11:52:00 +0800</pubDate>
      <guid>https://yafengabc.github.io/cnblogs/p8873397/index.html</guid>
      <description>Raspbian上的Rpi.GPIO库是可以在普通用户下控制树莓派的GPIO的，然而在ArchlinuxARM下，却需要root用户才行，这无疑会引起安全问题，好在RPi.GPIO提供了一个获取权限的脚本：create_gpio_user_permissions.py&#xA;然而这个脚本是没法在ArchlinuxARM上直接运行的，因为Archlinux缺少adduser命令。&#xA;这个脚本是这样的：&#xA;import grp import subprocess def ensure_gpiogroup(): try: grp.getgrnam(&#39;gpio&#39;) except KeyError: print(&#39;GPIO group does not exist - creating...&#39;) subprocess.call([&#39;groupadd&#39;, &#39;-f&#39;, &#39;-r&#39;, &#39;gpio&#39;]) subprocess.call([&#39;adduser&#39;, &#39;pi&#39;, &#39;gpio&#39;]) # in future, also for groups: # spi # i2c add_udev_rules() def add_udev_rules(): with open(&#39;/etc/udev/rules.d/99-gpio.rules&#39;,&#39;w&#39;) as f: f.write(&#34;&#34;&#34;SUBSYSTEM==&#34;bcm2835-gpiomem&#34;, KERNEL==&#34;gpiomem&#34;, GROUP=&#34;gpio&#34;, MODE=&#34;0660&#34; SUBSYSTEM==&#34;gpio&#34;, KERNEL==&#34;gpiochip*&#34;, ACTION==&#34;add&#34;, PROGRAM=&#34;/bin/sh -c &#39;chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport ; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport&#39;&#34; SUBSYSTEM==&#34;gpio&#34;, KERNEL==&#34;gpio*&#34;, ACTION==&#34;add&#34;, PROGRAM=&#34;/bin/sh -c &#39;chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value&#39;&#34; &#34;&#34;&#34;) if __name__ == &#39;__main__&#39;: ensure_gpiogroup() 反正很简单，手动搞进去就行了</description>
    </item>
  </channel>
</rss>