Page 1 of 1

Geany and RuntimeError

Posted: Sat Apr 19, 2014 12:32 am
by leodh
Hi,

I am new to the Raspberry Pi and am stumbling a bit as Python is totally new to me.

I would like to be able to control some pins on the GPIO to sound a buzzer and turn on a LED when there is an over temperature event. I have got the Raspberry Pi talking to the ds18b20 thermometers but can not get control of the IO pins.
Here is a simple code snippet that shows the Error ( I am using Geany as my editor )

Code: Select all

import PRi.GPIO as GPIO

def sound_buzzer(n):
  GPIO.output(17, GPIO.HIGH if n else GPIO.LOW)

# Set pins for Buzzer
GPIO.warnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)


I get and Error File "Buzzer.py, line 12, in <module>
GPIO.setup(17, GPIO.OUT)
RuntimeError: No access to /dev/mem. try running as root!

what does this mean and how do I fix it.

Thanks
Leo

Re: Geany and RuntimeError

Posted: Sat Apr 19, 2014 8:11 am
by Johan Vandewalle
I got the same error and can't set the GPIO-ports to change from in to out.

Your code has at least 1 typo-error. In the first line you should change PRi.GPI into RPi.GPIO:

Code: Select all

import RPi.GPIO as GPIO

def sound_buzzer(n):
  GPIO.output(17, GPIO.HIGH if n else GPIO.LOW)

# Set pins for Buzzer
GPIO.warnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)

Re: Geany and RuntimeError

Posted: Sat Apr 19, 2014 9:21 am
by DeeJay
RuntimeError: No access to /dev/mem. try running as root!

what does this mean and how do I fix it.
It means you need to run the script as the 'root' - that is, admin or privileged - user.

Code: Select all

sudo python Buzzer.py

Re: Geany and RuntimeError

Posted: Sat Apr 19, 2014 12:22 pm
by leodh
Hi,

The RPi.GPIO was a typo.
I understand that I need to run it as sudo, and now it works - but is there a way to set that within the Geany program so I don't have to go to the Terminal every time to test it.

Thanks
Leo

Re: Geany and RuntimeError

Posted: Sat Apr 19, 2014 2:18 pm
by DeeJay
In the Geany gui -

[Build] - [Set Build Commands] - [Execute commands] Change 'python "%f"' to ' sudo python "%f" '

But be aware that this then runs every script under geany with sudo/root privilege, which may not be what you want, and could be dangerous for your system if you make a destructive coding error!