User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Using 17 GPIO output pins with Pi4J

Wed Nov 14, 2012 10:52 am

Hi!

I have a binary clock project in which I'm trying to light up 17 LEDs using the Raspberry Pi in order to run a binary clock. The project may not be that impressive and perhaps it's not the best way to create a binary clock, but its true purpose is learning how to use the GPIO in different ways. After successfully implementing the software for the binary LED clock in bash script (you may check out the video about it here: http://www.youtube.com/watch?v=dY3wTtFPn48), I'm now moving on to controlling the 17 LEDs from a Java application run by the Tomcat server, so that I can control the LEDs from a browser. I'm using the Pi4J Java library to control the GPIO pins from Java. During my early attempts to achieve this, I have run into some issues which I'd like to ask some questions about:

1. I was only able to issue calls to the Pi4J library successfully by running the Tomcat server with root privileges (otherwise I was getting an error message, something like: "Unable to access the WiringPi export interface"). On the Pi4J website it is clearly stated that Pi4J won't run in any other way, but I'm wondering if this will change in the future. I don't feel comfortable running Tomcat as root.

2. I tried to set up all the 17 GPIO pins as digital output pins, so that I can call nice methods like blink(), toggle(), pulse(), etc. I set the pins up like this:

Code: Select all

GpioController gpioController = GpioFactory.getInstance();
		
		//Initialize all GPIO pins to output mode
		mGPIOPins[0] = gpioController.provisionDigitalOutputPin(RaspiPin.GPIO_00, "GPIO_Pin_00" , PinState.LOW);
		mGPIOPins[1] = gpioController.provisionDigitalOutputPin(RaspiPin.GPIO_01, "GPIO_Pin_01" , PinState.LOW);
		mGPIOPins[2] = gpioController.provisionDigitalOutputPin(RaspiPin.GPIO_02, "GPIO_Pin_02" , PinState.LOW);
		mGPIOPins[3] = gpioController.provisionDigitalOutputPin(RaspiPin.GPIO_03, "GPIO_Pin_03" , PinState.LOW);
		mGPIOPins[4] = gpioController.provisionDigitalOutputPin(RaspiPin.GPIO_04, "GPIO_Pin_04" , PinState.LOW);
		mGPIOPins[5] = gpioController.provisionDigitalOutputPin(RaspiPin.GPIO_05, "GPIO_Pin_05" , PinState.LOW);
		mGPIOPins[6] = gpioController.provisionDigitalOutputPin(RaspiPin.GPIO_06, "GPIO_Pin_06" , PinState.LOW);
		mGPIOPins[7] = gpioController.provisionDigitalOutputPin(RaspiPin.GPIO_07, "GPIO_Pin_07" , PinState.LOW);
		mGPIOPins[8] = gpioController.provisionDigitalOutputPin(RaspiPin.GPIO_08, "GPIO_Pin_08" , PinState.LOW);
		mGPIOPins[9] = gpioController.provisionDigitalOutputPin(RaspiPin.GPIO_09, "GPIO_Pin_09" , PinState.LOW);
		mGPIOPins[10] = gpioController.provisionDigitalOutputPin(RaspiPin.GPIO_10, "GPIO_Pin_10" , PinState.LOW);
		mGPIOPins[11] = gpioController.provisionDigitalOutputPin(RaspiPin.GPIO_11, "GPIO_Pin_11" , PinState.LOW);
		mGPIOPins[12] = gpioController.provisionDigitalOutputPin(RaspiPin.GPIO_12, "GPIO_Pin_12" , PinState.LOW);
		mGPIOPins[13] = gpioController.provisionDigitalOutputPin(RaspiPin.GPIO_13, "GPIO_Pin_13" , PinState.LOW);
		mGPIOPins[14] = gpioController.provisionDigitalOutputPin(RaspiPin.GPIO_14, "GPIO_Pin_14" , PinState.LOW);
		mGPIOPins[15] = gpioController.provisionDigitalOutputPin(RaspiPin.GPIO_15, "GPIO_Pin_15" , PinState.LOW);
		mGPIOPins[16] = gpioController.provisionDigitalOutputPin(RaspiPin.GPIO_16, "GPIO_Pin_16" , PinState.LOW);
The first thing that bothers me here is that I could not find a way to call the provisionDigitalOutputPin() method in a for loop (from 0 to 16), because the method requires an argument like RaspiPin.GPIO_0. These are defined as static variables in the RaspiPin class and I couldn't find a way to enumerate them.

After that I tried to call toggle() on each of the digital output pins to light the LEDs up, like this:

Code: Select all

mGPIOPins[index].toggle() //i goes from 0 to 16 in a for loop
I was surprised to see that this works well for 14 pins, but not for the other 3. The LEDs which don't light up correspond to pins 02, 08 and 09. It's definitely not a hardware problem, because my bash script has no problem lighting those LEDs up (using the WiringPi command line utility like this: "gpio write index 1"). So it seems that pins 2,8 and 9 are used differently in Pi4J (compared to the others). What I suspect is that they cannot be used as digital output pins. If that's the case, then I won't be able to call nice methods like toggle(), blink(), pulse(), etc, because the ancestor GpioPin class does not have these methods. Does anybody know why these pins (2,8,9) behave differently in Pi4J and how I could use them?

Thank you!
Andras
http://iqjar.com

User avatar
joan
Posts: 14193
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Using 17 GPIO output pins with Pi4J

Wed Nov 14, 2012 11:15 am

I've lost track of the pin naming schemes. Which pins are you actually using?

Which pins on P1?

e.g. P1-2 is +5V, P1-8 is TXD, P1-9 is GND.

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Using 17 GPIO output pins with Pi4J

Wed Nov 14, 2012 11:19 am

joan wrote:I've lost track of the pin naming schemes. Which pins are you actually using?

Which pins on P1?

e.g. P1-2 is +5V, P1-8 is TXD, P1-9 is GND.
I'm using the following 17 programmable GPIO pins (indexed 0 to 16):
Image
Andras
http://iqjar.com

User avatar
joan
Posts: 14193
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Using 17 GPIO output pins with Pi4J

Wed Nov 14, 2012 11:28 am

2 (gpio2) P1-13 should work.

Perhaps 8/9 (i2c sda/scl) P1-3/5 are being used by a loaded i2c module?

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Using 17 GPIO output pins with Pi4J

Wed Nov 14, 2012 11:45 am

joan wrote:2 (gpio2) P1-13 should work.

Perhaps 8/9 (i2c sda/scl) P1-3/5 are being used by a loaded i2c module?
Nope, they are not being used by anything :)
Andras
http://iqjar.com

User avatar
joan
Posts: 14193
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Using 17 GPIO output pins with Pi4J

Wed Nov 14, 2012 11:49 am

I think the sda/scl lines have resistor pull ups/downs. Could that affect what you are doing?

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Using 17 GPIO output pins with Pi4J

Wed Nov 14, 2012 11:55 am

joan wrote:I think the sda/scl lines have resistor pull ups/downs. Could that affect what you are doing?
I have thought about this. But why does it work when I used those pins with the WiringPi gpio command line utility? It's seems to me that the problem is Pi4J-specific. It would be a real shame not to be able to use these 3 pins as output pins from Pi4J because it's possible to use them from other software and I really like Pi4J (the class structure, the easy of use, the elegance of it), I have a strong desire to use it in my project :)
Andras
http://iqjar.com

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: Using 17 GPIO output pins with Pi4J

Wed Nov 14, 2012 12:04 pm

Un4Seen wrote: The first thing that bothers me here is that I could not find a way to call the provisionDigitalOutputPin() method in a for loop (from 0 to 16), because the method requires an argument like RaspiPin.GPIO_0. These are defined as static variables in the RaspiPin class and I couldn't find a way to enumerate them.
To get around the declarations put them into a list I would do something like this in Python and I am sure you can do similar in Pi4J, even for declarations.

Code: Select all

# GPIO pins in use for output order of segments A to G
pins = [ 11, 12, 13, 15, 16, 18, 22 ]

# GPIO function numbers GPIO by their P1 pin number
GPIO.setmode( GPIO.BOARD )
GPIO.setwarnings( False )

# Setup pins as output and turn LEDs off
for index in pins :
	GPIO.setup( index, GPIO.OUT )
	GPIO.output( index, 0 )
So make an array/list of the declarations and loop through that array/list. You can do this for setupor update or blink.
After that I tried to call toggle() on each of the digital output pins to light the LEDs up, like this:

Code: Select all

mGPIOPins[index].toggle() //i goes from 0 to 16 in a for loop
I was surprised to see that this works well for 14 pins, but not for the other 3. The LEDs which don't light up correspond to pins 02, 08 and 09. It's definitely not a hardware problem, because my bash script has no problem lighting those LEDs up (using the WiringPi command line utility like this: "gpio write index 1"). So it seems that pins 2,8 and 9 are used differently in Pi4J (compared to the others). What I suspect is that they cannot be used as digital output pins. If that's the case, then I won't be able to call nice methods like toggle(), blink(), pulse(), etc, because the ancestor GpioPin class does not have these methods. Does anybody know why these pins (2,8,9) behave differently in Pi4J and how I could use them?
Pins 8 and 9 your pins is probably because Pi4J stops you using I2C pins even if not using I2C

Pin 2 is no doubt because either Pi4J is setup for Rev 2 board and you have Rev 1 or the other way round. The P1-13 pin changed between Rev 1 and Rev 2 as to which GPIO pin from the SoC was actually taken out to that pin.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Using 17 GPIO output pins with Pi4J

Wed Nov 14, 2012 12:16 pm

Thanks, techpaul! This is really useful info!

First of all, putting the pins into a list is definitely the way to go, I don't know why I haven't thought of that. Thanks for the tip :)

Regarding the usage of pin 8 and 9, if you're right that Pi4J stops me from using them, it's a sad thing. Pi4J is built upon WiringPi and WiringPi has no such restrictions, so I'm hoping that you're not right about this.
As for pin 2, you have a good point there. I have a board Rev B and the problem could be that Pi4J is not aware of the existence of Rev B boards yet. However, this also sounds a little fishy because WiringPi is aware of the rev B boards and handles them well, so if Pi4J is built upon it, why does it not handle it well? Perhaps because of some internal data structures that it uses to store/control pins, which might contain some incorrect assumptions, that are valid only for older boards (rev A).

I'm hoping that somebody who is a Pi4J expert will read this or somebody who has tried this before me and can give me a certain answer.
Andras
http://iqjar.com

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Using 17 GPIO output pins with Pi4J

Wed Nov 14, 2012 12:19 pm

Un4Seen wrote: As for pin 2, you have a good point there. I have a board Rev B and the problem could be that Pi4J is not aware of the existence of Rev B boards yet. However, this also sounds a little fishy because WiringPi is aware of the rev B boards and handles them well, so if Pi4J is built upon it, why does it not handle it well? Perhaps because of some internal data structures that it uses to store/control pins, which might contain some incorrect assumptions, that are valid only for older boards (rev A).
Actually, on the Pi4J official site they are clearly aware of rev.2.0 boards, as seen here:
http://pi4j.com/usage.html
Andras
http://iqjar.com

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: Using 17 GPIO output pins with Pi4J

Wed Nov 14, 2012 12:24 pm

You might need to update Wiring Pi and or Pi4J, it may be you dont have versions that support the Rev B and Rev A.

As for I2C lines only Pi4J peeps can verify that or actions to take.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Using 17 GPIO output pins with Pi4J

Wed Nov 14, 2012 12:31 pm

techpaul wrote:You might need to update Wiring Pi and or Pi4J, it may be you dont have versions that support the Rev B and Rev A.
The fact that the command line gpio WiringPi tool works fine proves that my WiringPi is up-to-date (enough to handle this well). As for Pi4J, the latest available build is quite old (I think it's from the 27th of October, 2012), but unfortunately no newer build was published since. This might be the problem indeed.
techpaul wrote:As for I2C lines only Pi4J peeps can verify that or actions to take.
Unfortunately, yes :(
Andras
http://iqjar.com

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: Using 17 GPIO output pins with Pi4J

Wed Nov 14, 2012 12:56 pm

Suggest you post question about Pi4J in "Other Languages" as often someone from Pi4J hangs around in there.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Using 17 GPIO output pins with Pi4J

Wed Nov 14, 2012 1:22 pm

techpaul wrote:Suggest you post question about Pi4J in "Other Languages" as often someone from Pi4J hangs around in there.
Will do, thank you! :)
Andras
http://iqjar.com

geoffgomez
Posts: 2
Joined: Fri Nov 16, 2012 12:57 pm

Re: Using 17 GPIO output pins with Pi4J

Fri Nov 16, 2012 1:13 pm

I was having a similar issue using pins 8 & 9 as for input after I upgraded my pi to see the full 512MB (it had worked previously). Anyway the issue seemed to be due to the wiringPi library (libpi4j.so) included in the snapshot build being built against an older wiringPi release which doesn't recognise the revision 2 boards with 512MB so assumes it is a rev 1. To fix it, I ended up downloading the latest source packages for both wiringPi and pi4j and building both from scratch (in that order). I'm a complete novice with Maven so I found the pi4j challenging but got with a working library in the end. Looking at the frequency of the snapshots I would guess that there will be a fresh one available fairly shortly if you'd rather not roll your own.

If you do decide to build yourself be aware that the latest wiringPi does not create /usr/local/lib/libwiringPi.a which pi4j relies on. I created a symbolic link to libwiringPi.so.1.0 which allowed it to build (presumably correctly as it works). This is probably a bit iffy but has worked for me.

Hope this helps.

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Using 17 GPIO output pins with Pi4J

Fri Nov 16, 2012 3:23 pm

It does help! A lot! At least now I know for sure that it's not a problem in my code (although I was quite sure even until now about that).
I don't know if I'm going to try building it, from your comment it seems like a painful process (add that to the fact that I have no idea what Maven is and that I've never built Java code under Linux and you realize that it's going to be a hard fight :) ). But the fact that the fix is already in the current Pi4J code is great news! Thanks for sharing it :)
Andras
http://iqjar.com

geoffgomez
Posts: 2
Joined: Fri Nov 16, 2012 12:57 pm

Re: Using 17 GPIO output pins with Pi4J

Fri Nov 16, 2012 9:31 pm

It's not actually as bad as you'd think, I made notes when I did it and (excluding my mistakes) it comes down to the following:

I'm assuming from the earlier thread you have already installed wiringPi using git.

Create symbolic link to libwiringPi.a:

[email protected] ~ $ cd /usr/local/lib
[email protected] /usr/local/lib $ ls
libwiringPi.so  libwiringPi.so.1  libwiringPi.so.1.0  python2.7  python3.2
[email protected] /usr/local/lib $ sudo ln -s libwiringPi.so.1.0 libwiringPi.a


Get the pi4j Source:

[email protected] ~ $ git clone git://github.com/Pi4J/pi4j
Cloning into 'pi4j'...
remote: Counting objects: 9122, done.
remote: Compressing objects: 100% (1781/1781), done.
remote: Total 9122 (delta 6750), reused 9122 (delta 6750)
Receiving objects: 100% (9122/9122), 10.69 MiB | 840 KiB/s, done.
Resolving deltas: 100% (6750/6750), done.

In pi4j change the pom.xml configuration file to point to your pi (I'm building on mine so set to localhost):

                <pi.host>localhost</pi.host>
                <pi.port>22</pi.port>
                <pi.user>pi</pi.user>
                <pi.password>raspberry</pi.password>
                <pi.abi>hard-float</pi.abi>

Note: pi.host is set in 5 places, I changed all but I don't think I should have had to.

Change JAVA_HOME entry in pi4j-native/src/main/native/Makefile to /usr/lib/jvm/java-7-openjdk-armhf so that it finds jni.h:

e.g.
INCLUDE = -I. -I/usr/lib/jvm/java-7-openjdk-armhf/include -I/usr/local/include -I. -I/usr/lib/jvm/java-7-openjdk-armhf/include/linux -I/usr/local/include/linux



Build using Maven:
(If not installed use sudo apt-get install maven)

[email protected] ~/pi4j $ mvn clean install -P native -P hard-float

Lots of information later:

[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Pi4J :: Parent POM ................................ SUCCESS [1:44.040s]
[INFO] Pi4J :: JNI Native Library ........................ SUCCESS [58.652s]
[INFO] Pi4J :: Java Library (Core) ....................... SUCCESS [9:35.354s]
[INFO] Pi4J :: GPIO Extension ............................ SUCCESS [1:59.566s]
[INFO] Pi4J :: Java Examples ............................. SUCCESS [1:04.402s]
[INFO] Pi4J :: OSGi Service .............................. SUCCESS [1:30.109s]
[INFO] Pi4J :: Device Abstractions ....................... SUCCESS [7.307s]
[INFO] Pi4J :: Distribution .............................. SUCCESS [22.185s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18:02.682s
[INFO] Finished at: Fri Nov 16 21:13:51 GMT 2012
[INFO] Final Memory: 29M/73M
[INFO] ------------------------------------------------------------------------

The built jar should be in:
pi4j-core/target/pi4j-core-0.0.3-SNAPSHOT.jar

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Using 17 GPIO output pins with Pi4J

Fri Nov 16, 2012 9:53 pm

Wow! You really gave a detailed explanation here. Even a total beginner can do it based on your instructions. Thank you! I'm sure many people will find this guide useful.

As for me, I'm still developing my Java app which will allow me to control my binary clock's LEDs from a web browser. I'll finish that first and if by that time no new Pi4J package will be available for download, I'm going to give the build a try. Your guide makes it look easy :)
Andras
http://iqjar.com

User avatar
savageautomate
Posts: 225
Joined: Thu Aug 16, 2012 3:20 pm
Location: USA
Contact: Website

Re: Using 17 GPIO output pins with Pi4J

Sat Nov 17, 2012 3:52 am

Hi Guys,

Sorry, I missed this post. I will push a new SNAPSHOT of Pi4J compiling against the latest WiringPi sources early next week. I'll post back here when its ready so you both can test it out.

Thanks, Robert
Robert Savage | Follow me @savageautomate
http://www.pi4j.com | http://www.pislices.com
http://www.savagehomeautomation.com

User avatar
savageautomate
Posts: 225
Joined: Thu Aug 16, 2012 3:20 pm
Location: USA
Contact: Website

Re: Using 17 GPIO output pins with Pi4J

Sat Nov 17, 2012 4:07 am

geoffgomez wrote:If you do decide to build yourself be aware that the latest wiringPi does not create /usr/local/lib/libwiringPi.a which pi4j relies on. I created a symbolic link to libwiringPi.so.1.0 which allowed it to build (presumably correctly as it works). This is probably a bit iffy but has worked for me.
The libwiringPi.a file is produced when the WiringPi project is compiled as a static library instead of a shared library. Originally WiringPi only produced a static library; however in later builds, support was added for shared library (*.so). I may have had to tweak the WiringPi's makefile to build the static library on my system, I really don't remember. I'll review what exactly I did and updated the build instructions file to include notes on building the wiringPi sources.

I am compiling against the static library of WiringPi to reduce the number of dependencies and required steps to get Pi4J up and running. However, this does mean that when new WiringPi updates are available, Pi4J needs to publish new builds to include the changes. As you have witnessed, installing WiringPi and compiling it yourself does not mean that Pi4J will see or use that version of the library.

Thanks, Robert
Robert Savage | Follow me @savageautomate
http://www.pi4j.com | http://www.pislices.com
http://www.savagehomeautomation.com

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Using 17 GPIO output pins with Pi4J

Sat Nov 17, 2012 9:12 am

Thank you for the info, Robert! I really do appreciate it! I'm happy to test the new Pi4J for you with my type of board (model B, rev 2.0) when it becomes available.
Andras
http://iqjar.com

User avatar
savageautomate
Posts: 225
Joined: Thu Aug 16, 2012 3:20 pm
Location: USA
Contact: Website

Re: Using 17 GPIO output pins with Pi4J

Tue Nov 20, 2012 6:44 am

The new 0.0.4-SNAPSHOT development build is available for testing. This build is compiled against the latest wiringPi sources.

You can download the latest packaged JAR from the Maven repository here:
https://oss.sonatype.org/content/groups ... -SNAPSHOT/

Please report success or any remaining defects/issues on the defect ticket here:
https://github.com/Pi4J/pi4j/issues/5

Thanks, Robert
Robert Savage | Follow me @savageautomate
http://www.pi4j.com | http://www.pislices.com
http://www.savagehomeautomation.com

User avatar
savageautomate
Posts: 225
Joined: Thu Aug 16, 2012 3:20 pm
Location: USA
Contact: Website

Re: Using 17 GPIO output pins with Pi4J

Tue Nov 20, 2012 6:59 am

PS:

I have tested GPIO pins 2,8,9 (wiringPi pin numbering scheme) on my 256 MB Raspberry Pi (don't have a 512 MB unit) with the latest Pi4J library (0.0.4-SNAPSHOT) and it seems to be working here.
Robert Savage | Follow me @savageautomate
http://www.pi4j.com | http://www.pislices.com
http://www.savagehomeautomation.com

User avatar
savageautomate
Posts: 225
Joined: Thu Aug 16, 2012 3:20 pm
Location: USA
Contact: Website

Re: Using 17 GPIO output pins with Pi4J

Tue Nov 20, 2012 7:28 am

Un4Seen wrote: 1. I was only able to issue calls to the Pi4J library successfully by running the Tomcat server with root privileges (otherwise I was getting an error message, something like: "Unable to access the WiringPi export interface"). On the Pi4J website it is clearly stated that Pi4J won't run in any other way, but I'm wondering if this will change in the future. I don't feel comfortable running Tomcat as root.
At this time, exporting the GPIO pins, setting pull-up/down resistance, setting edge detection (gpio listeners), and controlling PWM requires root privileges. This excerpt from Godon's WiringPi website explains the details a bit further (https://projects.drogon.net/raspberry-p ... functions/):
wiringPiSetupSys()

This initialises the wiringPi system but uses the /sys/class/gpio interface rather than accessing the hardware directly. This can be called as a non-root user provided the GPIO pins have been exported before-hand using the gpio program. Pin number in this mode is the native Broadcom GPIO numbers.

Note: In this mode you can only use the pins which have been exported via the /sys/class/gpio interface. You must export these pins before you call your program. You can do this in a separate shell-script, or by using the system() function from inside your program.

Also note that some functions (noted below) have no effect when using this mode as they’re not currently possible to action unless called with root priveledges.
Pi4J does not use the "wiringPiSetupSys()" mode of wiringPi but rather the "wiringPiSetup()" mode to provide the most functionality for GPIO control/access. It is also my understanding that using the sysfs interface to control GPIO is much slower (in high speed switching applications).

Gordon has mentioned the possibility of creating a device driver (/dev/) to properly control and configure the GPIO as a non-root account. So maybe someday we will get a nice surprise ;)
Robert Savage | Follow me @savageautomate
http://www.pi4j.com | http://www.pislices.com
http://www.savagehomeautomation.com

User avatar
savageautomate
Posts: 225
Joined: Thu Aug 16, 2012 3:20 pm
Location: USA
Contact: Website

Re: Using 17 GPIO output pins with Pi4J

Tue Nov 20, 2012 7:35 am

Un4Seen wrote: 2. I tried to set up all the 17 GPIO pins as digital output pins, so that I can call nice methods like blink(), toggle(), pulse(), etc. ... The first thing that bothers me here is that I could not find a way to call the provisionDigitalOutputPin() method in a for loop (from 0 to 16), because the method requires an argument like RaspiPin.GPIO_0. These are defined as static variables in the RaspiPin class and I couldn't find a way to enumerate them.
These are public static variables because each pin instance is a class (implementing the Pin interface) that describes further runtime capabilities and addressing information. Originally I did use enumerations to describe these pins; however, in the re-factoring effort to support GpioProviders and GPIO expansion capabilities, I needed something to represent a Pin that could describe more complex details about each pin.
Robert Savage | Follow me @savageautomate
http://www.pi4j.com | http://www.pislices.com
http://www.savagehomeautomation.com

Return to “General programming discussion”