GPIO control

The brains of your robot

GPIO control

Postby Bastian » Mon Dec 29, 2014 12:54 am

Hi,

I’m playing around with a lot of sensors and ran out of DAGU-ARDuino options (as far as I can understand the layers of code up till now). So, I’m attempting to use the GPIO-pins as they are there and all open for gaming.

So, I wrote some ordinary commands in my script: Import RPi.GPIO as GPIO; GPIO.setmode(GPIO.BCM): TRIG=23, GPIO.setup(TRIG, GPIO.OUT)

And there’s where I got stuck. I get the notorious output: “RuntimeError: No access to /dev/mem. Try running as root!” Obvious, since I’m running through py_websockets_bot. (I also try to make use of the mini_driver for the motors, servo’s and some sensors).

Googling brought me the escape of running the script from IDLE 3. So, I created a copy-script with all print-statements converted to Python-3 syntax, but then I encountered the phenomena that IDLE 3 doesn’t use the same path and module/class conventions and py_websockets_bot.mini_driver (a.o.) suddenly was unknown.

Being an amateur, I got annoyed at that point: lacking the proper docs in detail, I was thinking about defaulting to the standard Raspbian image, building from scratch and do the Arduino sketching also. To be honest: that’s too much for an elderly ;-0)

So, I’m wondering if there’s a way to enforce root-rights from within my scripts. Maybe it is possible to use the parser? Or fit in some additional Linus-scripts?
Bastian
 
Posts: 23
Joined: Fri Nov 28, 2014 11:30 am

Re: GPIO control

Postby Alan » Mon Dec 29, 2014 12:34 pm

Hi Bastian,

I'm not sure how you would give your scripts root permissions in general. My Linux knowledge is not that deep, although I'm sure there's probably a way. :) Instead I would probably just run my scripts using sudo, would that suffice?

Alternatively, depending upon what you want to do with the GPIO pins, you can actually write a Python sensor module which is used by the main web server program to take sensor readings with the GPIO pins. Because the web server runs with root privileges, there's no problem using he GPIO pins.

There's a brief explanation of how to do this at the bottom of our blog post on adding sensors (look at the section entitled 'Connecting Sensors to the Raspberry Pi'). If you decide to try this route and need any extra info, please let me know.

Regards

Alan
Alan
Site Admin
 
Posts: 311
Joined: Fri Jun 14, 2013 10:09 am


Return to Software

Who is online

Users browsing this forum: No registered users and 0 guests