无法访问 /dev/mem。以 root 身份尝试 运行

No access to /dev/mem. Try running as root

我是新手!

我有 python 文件代码来打开灯: 我试过了 herehere and here here 在论坛上 我 chmod pi for /dev ,添加用户组 文件 1

print "================================"
    print "ROBOT: DANG MO QUAT"
    print "================================"
os.system("aplay -D hw:1,0 /home/pi/jasper/static/audio/dangmoquat.wav")
minh.main(['-p',pin,'on'])

文件2访问GPIO:

def GPIO_SETMODE(pin):
    if int(pin) in GPIOs:
#   GPIO.cleanup()
        GPIO.setmode(GPIO.BOARD) ## Use BOARD pin numbering
        GPIO.setup(int(pin), GPIO.OUT)
    return True
    else:
    return False 


def main(argv):
       type = ''   
       try:
          opts, args = getopt.getopt(argv,"b:p:h:s:r",['input=', 'params=', 'help'])
       except getopt.GetoptError:
          print 'Wrong command'
          sys.exit(2)
       print opts,args

       for opt, arg in opts:
          #...........doing something here....................#
       elif opt in ("-p", "--power"):
     input = arg
         if GPIO_SETMODE(input):#------------> errror occurs here#
                if args[0] == 'on':
                        Power(int(input), True)
                elif args[0] == 'off':
                        Power(int(input), False)
                else:
                        print 'Please choose on or off'

此处出现错误。

"No access to /dev/mem. Try running as root!" 我试过了here

here and here here 在论坛上

和google。我一直醒到天亮。我有 chmod 777 pi dev -R 我能知道什么? 请帮我。

不仅对 /dev 的访问可以获得访问权限,设备本身也可能受到保护。

您应该执行 ls -l /dev 并检查您尝试访问的 I/O 设备。看到群组后,请尝试将自己添加到该群组:

$ sudo usermod -aG <iogroup> user

之后,您可能需要注销并重新登录才能添加群组。

否则您可以将权限更改为 777(设备),但更改组更正确。