leodh
Posts: 8
Joined: Fri Apr 18, 2014 10:23 am

Geany and RuntimeError

Sat Apr 19, 2014 12:32 am

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

Johan Vandewalle
Posts: 40
Joined: Wed Apr 16, 2014 2:45 pm

Re: Geany and RuntimeError

Sat Apr 19, 2014 8:11 am

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)
Johan Vandewalle
(Belgium)

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: Geany and RuntimeError

Sat Apr 19, 2014 9:21 am

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
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

leodh
Posts: 8
Joined: Fri Apr 18, 2014 10:23 am

Re: Geany and RuntimeError

Sat Apr 19, 2014 12:22 pm

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

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: Geany and RuntimeError

Sat Apr 19, 2014 2:18 pm

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!
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

Return to “Beginners”