Jump to content


Photo

[Open Source] Java GPIO Manager


  • Please log in to reply
19 replies to this topic

#1 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 13 February 2015 - 03:19 AM

Made a quick GUI app using Netbeans (on the pcDuino) that lets the user play around with the GPIO Pins.

I also made a class GPIO_Pin with all the functions you need for accessing and manipulating the GPIO pins.

34ffr.png

Video: 

Full source code on Github: https://github.com/M...ib/GPIO-Manager

The helpful object to manipulate the GPIO Pins: GPIO_Pin.java

The executable jar: GPIO_Manager.jar

A full screenshot: http://puu.sh/34fd5

Note: Installing Java and Netbeans can be done with 2 simple commands on a pcDuino running lubuntu:
sudo apt-get install openjdk-7-jdk
sudo apt-get install netbeans


  • LS-Support-12 likes this

#2 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 13 February 2015 - 03:19 AM

I m getting Exception in thread "main" java.lang.UnsupportedClassVersionError: pcduino/test/Main : Unsupported major.minor version 51.0
   at java.lang.ClassLoader.defineClass1(Native Method)
   at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
   at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
   at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
   at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
   at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: pcduino.test.Main. Program will exit.
Is there something i'm missing?
Thanks smiley.gif



#3 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 13 February 2015 - 03:19 AM

It is a fantastic utility, but I can't get it working either.  sad.gif


ubuntu@ubuntu:~/GPIO-Manager-master$ java -jar GPIO_Manager.jar
Exception in thread "main" java.lang.UnsupportedClassVersionError: pcduino/test/Main : Unsupported major.minor version 51.0
   at java.lang.ClassLoader.defineClass1(Native Method)
   at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
   at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
   at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
   at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
   at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: pcduino.test.Main. Program will exit.



#4 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 13 February 2015 - 03:19 AM

I haven't tested it yet but try this command
 

Code: [Select]

java -cp . -jar GPIO_Manager.jar

Dealing with cross platform, you will have to tell the system where your classpath is. This is the most tricky for newbies.



#5 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 13 February 2015 - 03:19 AM

@macro, @forgetmichel
need openjdk-7-jdk to run this program.
try /usr/lib/jvm/java-7-openjdk-armhf/bin/java instead.



#6 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 13 February 2015 - 03:19 AM

It works!   cheesy.gif

Thanks!



#7 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 13 February 2015 - 03:19 AM

That is a bright light in the video.  

Did you have to use a special low current LED, as the specs say the pins can only handle 4mA max?

Also, what resistor did you use, please?
modify_inline.gif
 
 


#8 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 13 February 2015 - 03:19 AM

till can make it work, macro what did you do to make it work . i m new to linux and i need more info 
thanks



#9 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 13 February 2015 - 03:19 AM

Please use the commands provided in the first post to install java. Then run the program.



#10 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 13 February 2015 - 03:20 AM

No resistors or anything used. I'm pretty nooby at Hardware so I just plugged it directly into the GPIO and ground.



#11 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 13 February 2015 - 03:20 AM

Hi @MohammadAdib,
Yes I followed the commands in your first post but it didn't work, but after following the hint from @Ids to use an absolute path to the correct version of Java, it works well now.  The problem is that your instructions don't work if there is a concurrent older version of Java installed.

But thanks, I have learned a lot from your code.

Hi @forgetmichel,
I got it going, (thanks to @MohammadAdib and @Ids), by opening up the terminal app and typing the following:
 

Code: [Select]

/usr/lib/jvm/java-7-openjdk-armhf/bin/java  -jar GPIO_Manager.jar



#12 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 13 February 2015 - 03:20 AM

No resistors or anything used. I'm pretty nooby at Hardware so I just plugged it directly into the GPIO and ground.
 

I think that is kind of risky.  You might damage the pcDuino that way as I believe there aren't any internal resisters like there is on pin 13 of the Arduino.



#13 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 13 February 2015 - 03:20 AM

Bad news @forgetmichel, I didn't get it to work after all.  sad.gif

I thought it was working because the dialog box came up with the working interface, but I was waiting for @MohammadAdib to get back to me with a resistor value for the LED before I could test it further.

After wiring up an LED and resistor and selecting the correct GPIO pin from the drop down menu, then selecting the HIGH form the state menu, and the mode to OUTPUT, pressing the 'Apply' button just gave me an error:
java.io.IOException: No such file or directory

Also, I forgot to tell you that I changed directory to the .jar file before I gave the command that brings up the GPIO Manager interface:
 

Code: [Select]

cd /home/ubuntu/GPIO-Manager-master
@MohammadAdib, what directory do I need to put the GPIO_Manager.jar file in, and what is the exact command to invoke it?

Thanks...



#14 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 13 February 2015 - 03:20 AM

works perfectly
ubuntu@ubuntu:~$ cd Downloads
ubuntu@ubuntu:~/Downloads$ /usr/lib/jvm/java-7-openjdk-armhf/bin/java  -jar GPIO_Manager.jar
Wrote "1" to /sys/devices/virtual/misc/gpio/mode/gpio0
Wrote "0" to /sys/devices/virtual/misc/gpio/pin/gpio0
Wrote "1" to /sys/devices/virtual/misc/gpio/mode/gpio0
Wrote "1" to /sys/devices/virtual/misc/gpio/pin/gpio0
Wrote "1" to /sys/devices/virtual/misc/gpio/mode/gpio7
Wrote "0" to /sys/devices/virtual/misc/gpio/pin/gpio7
 cheesy.gif
Thanks macro



#15 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 13 February 2015 - 03:20 AM

It now works for me!    cheesy.gif

I found out by searching through the forums, that for some reason the GPIO driver module is not loaded by the default!

It would be great if the next SD image would have this as a default, and if not, to at least include this info on more detailed instructions for projects.

It is hard enough for people new to Linux to follow full instructions sets, let alone having holes in them.

 

The GPIO driver module is not loaded by default.

To load the gpio driver manually:
Code: [Select]
sudo modprobe gpio

To make the gpio driver load automatically at boot, add it to the /etc/modules file:
Code: [Select]
echo gpio | sudo tee -a /etc/modules


#16 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 13 February 2015 - 03:20 AM

I have ported this project to Android, you can find it here:

https://github.com/F...Manager-Android



#17 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 13 February 2015 - 03:20 AM

Hello guys, first of all, sorry for my english.

I faced same problem connecting serial device to GPIO1 (cheap rfid card reader, "noname" brand)

I made python program 

Code: [Select]

## Select and configure the port
myPort = serial.Serial('/dev/ttyS1', 9600, timeout = 10)

## Wait for data to come in- one byte, only
x = myPort.read(10)

## Echo the data to the command prompt
print "You entered " + x

## Close the port so other applications can use it.
myPort.close()

But nothing happens, card reader beeps, but program just wait for 10 sec and then write "You entered " and that is all.

Please answer my questions:

  • How to know what mode my GPIO1 is ? (is there serial mode, input or output?)
  • How can i know if i have gpio driver loaded ?
  • What else should i check for serial data reading ?


#18 justalone

justalone

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 20 March 2017 - 07:21 PM

Hello Jim,

 

nice work for you GPIO manager!

 

Is there a way to use a part of it as an import library for processing (ARM version of course)? Because I cant find a way to use GPIO with processing...

 

I have this error message when using the processing "processing.io" library :

 

GPIO%20permission%20denied.jpg



#19 justalone

justalone

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 21 March 2017 - 06:14 PM

Solved "Permission denied" by using the following command :

 

sudo chgrp -R ubuntu /sys/class/gpio
sudo chmod -R g+rw /sys/class/gpio

 

But now I've this :

 

GPIO_not_available_on_your_platform.jpg



#20 justalone

justalone

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 24 March 2017 - 12:27 PM

Path for GPIO configuration file is not good :

GPIO path for raspberry is :/sys/class/gpio/export

GPIO path for pcDuino is :/sys/devices/virtual/misc/gpio/export

 

How to modify path in Processing?






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users