Skip to content
Advertisement

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

I’m a newbie!

I have python files code to turn on the light: i tried here and here and here here on forum i chmod pi for /dev , adduser group file 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'])

file 2 access 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'

Error occurs here.

“No access to /dev/mem. Try running as root!” i have try here

and here and here here on forum

and google. I was awaked until dawn. I have chmod 777 pi dev -R What can i do know? Please help me.

Advertisement

Answer

Not only access to /dev can be privileged for access, also the device itself will probably be protected.

You should do an ls -l /dev and check the I/O device you are trying to access. Once you see the group, try adding yourself to that group:

$ sudo usermod -aG <iogroup> user

After that, you probably need to log out and in again for the group to be added.

Else you could change the permission to 777 (of the device), but changing the group is more correct.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement