I'm working on a project that involves (very fast) manipulation of the GPIO pins using Java.
I had originally planned on using the rpi-gpio-java library recommended on the elinux.org wiki.
But when I returned to the Google code site to look up some documentation, I saw that the library is no longer accessible at http://code.google.com/p/rpi-gpio-java/. Does anyone know what happened to that project?
I have since moved onto using the enum from the Google code project "fr-drd-raspberrypi-gpio". (http://code.google.com/p/fr-drd-raspberrypi-gpio/)
This project claims to be able to achieve around 30kHz max frequency, which would be excellent for my project.
Another library I have heard some talk about is the Pi4J project. I intend to look into that project more this weekend.
Something that I've noticed is that all these libraries choose to approach the different PCB revisions. The first library appears to have no support for it, and it labeled (if I remember correctly) Pin 5 as NOT a GPIO pin, so it wouldn't let me output from it. I'm hoping these other two libraries have better support in this area. For this type of information, I mainly referred to the diagrams from http://www.raspberrypi-spy.co.uk/2012/06/simple-guide-to-the-rpi-gpio-header-and-pins/, is this advisable?
With that setup, I can finally get to my questions.
I'm currently testing some basic flipping of a couple output pins and I"m running into some strange behavior. My main function performs the following (again, using the fr-drd-raspberrypi-gpio library at the moment):
- Code: Select all
GPIO stepPin = GPIO.GPIO_0;
GPIO directionPin = GPIO.GPIO_1;
stepPin.open();
directionPin.open();
stepPin.setDirection(GPIO.SENS.out);
directionPin.setDirection(GPIO.SENS.out);
directionPin.output(true);
for(int i=0; i<100; i++){
stepPin.output(true);
stepPin.output(false);
}
directionPin.output(false);
for(int i=0; i<100; i++){
stepPin.output(true);
stepPin.output(false);
}
stepPin.close();
directionPin.close();
When I first execute this code on a freshly-booted RPi, it completes the execution successfully with no exceptions. I only appear to receive one toggle output, however. I have yet to confirm whether this is due to a poor physical wire connection.
Either way, after the first execution, subsequent executions fail, throwing
- Code: Select all
java.io.IOException: Device or resource busy
It's my understanding that if the first execution completed successfully, the connections to the files that control the GPIO pins should be closed.
Am I missing some fundamental understanding of how GPIO pins work on the RPi?
Is there a simple way to close those files via terminal instead of restarting my RPi?