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

Tue Nov 20, 2012 9:22 am

savageautomate wrote:
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.
I've already managed to get around this by creating a nice array which contains these statics. Thanks techpaul for the suggestion!
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

Tue Nov 20, 2012 9:23 am

savageautomate wrote: 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/):

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 ;)
OK, let's wait for that nice surprise then :)
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

Tue Nov 20, 2012 9:24 am

savageautomate wrote: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
Thank you, Robert! I'll do my best to test it tonight and I'll let you know!
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

Tue Nov 20, 2012 3:37 pm

I have made a first attempt to test with the new Pi4J, but no luck so far. It seems that the Pi4J is now compiled with a different version of Java or something like that. My Eclipse sees no problem, but my Java app fails during run time with the following problem:

Code: Select all

type Exception report

message java.lang.UnsupportedClassVersionError: com/pi4j/io/gpio/Pin : Unsupported major.minor version 51.0 (unable to load class com.pi4j.io.gpio.Pin)

description The server encountered an internal error (java.lang.UnsupportedClassVersionError: com/pi4j/io/gpio/Pin : Unsupported major.minor version 51.0 (unable to load class com.pi4j.io.gpio.Pin)) that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: java.lang.UnsupportedClassVersionError: com/pi4j/io/gpio/Pin : Unsupported major.minor version 51.0 (unable to load class com.pi4j.io.gpio.Pin)
	com.vaadin.terminal.gwt.server.AbstractApplicationServlet.handleServiceException(AbstractApplicationServlet.java:1010)
	com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:548)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause

java.lang.UnsupportedClassVersionError: com/pi4j/io/gpio/Pin : Unsupported major.minor version 51.0 (unable to load class com.pi4j.io.gpio.Pin)
	org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2905)
	org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1170)
	org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
	org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
At first I had OpenJDK 1.6.0_24 on the Pi, but then I upgraded to 1.7.0_07 (sudo apt-get install openjdk-7jdk). However I still get the same error...
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 3:49 pm

I am running Java 7. I don't remember the specific dependency off the top of my head, but there is a Java 7 dependent class in the Pi4J codebase.

See this article to make sure that the default version of Java is configured for java-7:
http://www.savagehomeautomation.com/pro ... e-jvm.html

This is how mine is configured:

Code: Select all

There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-openjdk-armhf/jre/bin/java   1063      auto mode
  1            /usr/lib/jvm/java-6-openjdk-armhf/jre/bin/java   1057      manual mode
  2            /usr/lib/jvm/java-7-openjdk-armhf/jre/bin/java   1063      manual mode

Press enter to keep the current choice[*], or type selection number:
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

Tue Nov 20, 2012 3:54 pm

I'm afraid that's does not help :(
java -version returns 1.7.0_07:

Code: Select all

java version "1.7.0_07"
OpenJDK Runtime Environment (IcedTea7 2.3.2) (7u7-2.3.2a-1+rpi1)
OpenJDK Zero VM (build 22.0-b10, mixed mode)
Also, I restarted Tomcat 7. I doubt that the whole Linux system needs a reboot, but I'll try that too...
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 4:05 pm

I have run into this problem before ... I just need to remember what I did to correct it.....

I am compiling on a Windows 7 machine with:

Code: Select all

java version "1.7.0_06"
Java(TM) SE Runtime Environment (build 1.7.0_06-b24)
Java HotSpot(TM) 64-Bit Server VM (build 23.2-b09, mixed mode)
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 4:12 pm

Is there a JAVA_HOME environment variable pointing to the JRE/JDK 6? Is tomcat possibly running under Java 6?
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

Tue Nov 20, 2012 4:21 pm

Yepp, that was it!

I needed to edit the file /etc/default/tomcat7 and change the JAVA_HOME variable in it. Until now this line was commented, but I guess it did not matter because I only had one version of Java installed on the Pi (1.6.0_24). But now, that I've installed 1.7.0_07 too, I needed to explicitely speicfy that I want Tomcat to use this version:

Code: Select all

JAVA_HOME=/usr/lib/jvm/java-7-openjdk-armhf
I hesitated what value to give it excatly because in the /usr/lib/jvm directory there are more than one candidates that seem to be suitable:

Code: Select all

[email protected]:/usr/lib/jvm$ ls
default-java              java-6-openjdk-armhf   java-7-openjdk-common
java-1.6.0-openjdk-armhf  java-6-openjdk-common
java-1.7.0-openjdk-armhf  java-7-openjdk-armhf
I went with the above setting and it works :)

And finally, allow me to confirm the great news: all pins are now handled correctly bu Pi4J!

My deepest and most sincere thanks to Robert! :)
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 4:40 pm

Un4Seen wrote:And finally, allow me to confirm the great news: all pins are now handled correctly bu Pi4J! My deepest and most sincere thanks to Robert! :)
Excellent news!
You are welcome and I am glad to be able to help out and contribute back to the Pi community!
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 4:46 pm

Un4Seen wrote:Yepp, that was it!
I needed to edit the file /etc/default/tomcat7 and change the JAVA_HOME variable in it. Until now this line was commented, but I guess it did not matter because I only had one version of Java installed on the Pi (1.6.0_24). But now, that I've installed 1.7.0_07 too, I needed to explicitely speicfy that I want Tomcat to use ...
FYI ...
If you don't want to modify a tomcat config file, I think you can also define a system environment variable for JAVA_HOME and the tomcat startup scripts will honor that when loading.

See section "ADD JAVA_HOME ENVIRONMENT VARIABLE" on this page for more details:
http://www.savagehomeautomation.com/pro ... -170u.html
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

Tue Nov 20, 2012 4:53 pm

savageautomate wrote: FYI ...
If you don't want to modify a tomcat config file, I think you can also define a system environment variable for JAVA_HOME and the tomcat startup scripts will honor that when loading.

See section "ADD JAVA_HOME ENVIRONMENT VARIABLE" on this page for more details:
http://www.savagehomeautomation.com/pro ... -170u.html
Thanks! Seems like a reasonable alternative, but I don't see any inconvenience in editing the Tomcat config file.
By the way, your website is just like Gordon's: the more I explore it, the more useful info I find on it :)
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 5:01 pm

Un4Seen wrote:By the way, your website is just like Gordon's: the more I explore it, the more useful info I find on it :)
Thanks! That is definitely a compliment!

FWIW .. I try to keep all Raspberry Pi related articles indexed/listed on this page: http://pislices.com/
This may serve as a good page to bookmark to more easily find specific content.
Robert Savage | Follow me @savageautomate
http://www.pi4j.com | http://www.pislices.com
http://www.savagehomeautomation.com

Return to “General programming discussion”