This is a silly question regarding GPIO access.
It is possible to access I2C at user level (non root) buy adding your user to the I2C group
Is there a similar way to gain access to the GPIO pins (as a user not root)
This is a silly question regarding GPIO access.
It is possible to access I2C at user level (non root) buy adding your user to the I2C group
Is there a similar way to gain access to the GPIO pins (as a user not root)
Yes.
Additionally, if you use the gpio command (part of wiringPi) to load the i2c kernel module then it changes ownership to that of the calling user.
You can - I think the foundation has changed group ownership to 'gpio' which makes it easier, but I think you still need to be root to setup the actual export via the /sys/class/gpio interface. Again wiringPi's gpio command will make this easy for you.
It runs as a set-uid root program, so you can run it from the command-line or in scripts without using sudo ..
The down-side of using the sysfs interface is thats it's not that fast - fine for simple stuff though.
Gordon
I have already set this up manually (Working fine) but may be useful for others.
Speed is not an issue, I just don't want code running a root if it is not needed.
wiringPI looks like it needs downloading as source & compiling, is there a simpler option (I am not opposed to building software if necessary but would prefer to keep to the standard repositories if possible)
Cheers for the info so far.
I probably should have added I will be programming in python. after years of 8 bit assembler programming I don't want to get involved in all that low level stuff again.
This is what we wrote in the PIF
Provided you have /etc/modprobe.d/raspi-blacklist.conf, you will need to remove the I2C and SPI blacklisting. Start up an editor, for instance nano:
sudo nano /etc/modprobe.d/raspi-blacklist.conf
then comment out these lines by putting a # at the start of each line:
blacklist spi-bcm2708 blacklist i2c-bcm2708
Add the I2C kernel modules by editing /etc/modules:
sudo nano /etc/modules
and insert two lines at the end of the file:
i2c-bcm2708 i2c-dev
then reboot (sudo reboot).
Download the i2ctools utility:
sudo apt-get install python-smbus sudo apt-get install i2c-tools
and check that the ... board is visible:
sudo i2cdetect -y 1
It's in the works as it were - so it'll be in the repositories in a week or 2, hopefully.
wiringPi is a C library for C/C++ programs. I don't consider it particularly low-level.
// blink.c:
#include main () { wiringPiSetup () ; pinMode (0, OUTPUT) ; for (;;) { digitalWrite (0, 1) ; delay (500) ; digitalWrite (0, 0) ; delay (500) ; } }
The gpio command is a command-line swiss army knife type utility for all the Pi's GPIO. It started life as the wiringPi test program then because usefull - I've written projects in bash using it... (and been horrified to see people using it via system() from C, Python, PHP, and even my BASIC which has it built in...
#!/bin/bash
gpio mode 0 out while true; do gpio write 0 1 ; sleep 0.5 gpio write 0 0 ; sleep 0.5 done
You probably want RPi.GPIO for your Python code.
Gordon
As i said I have already done this for the i2c the question was could the same be done for the GPIO so far Gordon has given me a good start by suggesting wiringPI.
Yep, I read the question too quickly. Apologies.
Tim
silly question If i build wiringPi on my shiny new fast 2B will it run on my old rev 1 model B?
Yes.
And if you use wiringPi pin numbers you don't need to wory about the pin 22->27 change either. (Nor the I2C interface)
Gordon
Have something to add? Share your thoughts — no account required.
Ask the community — no account required