Comments (7)
Hi Andy, some of the program code got cut off, can you please paste the rest of it (or link to it if you have it in a public repository). Thanks, Robert
from pi4j-v1.
Hello,
don't understand why the code got cut off but here it is:
package atael;
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;
public class Pi4JGPIOPins {
public static void main(String[] args) throws InterruptedException {
final GpioController gpio = GpioFactory.getInstance();
final GpioPinDigitalOutput GPIOPinOut[] = {
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_00, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_02, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_05, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_06, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_07, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_08, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_09, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_10, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_11, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_12, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_13, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_14, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_15, PinState.LOW),
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_16, PinState.LOW)
};
gpio.setShutdownOptions(true, PinState.LOW, GPIOPinOut);
while (true) {
for (int i = 0; i <= 16; i++) {
GPIOPinOut[i].pulse(50);
Thread.sleep(50);
System.out.print(i + " ");
}
}
}
}
On Sun, Jan 27, 2013 at 10:48 AM, Robert Savage [email protected]:
Hi Andy, some of the program code got cut off, can you please paste the
rest of it (or link to it if you have it in a public repository). Thanks,
Robert—
Reply to this email directly or view it on GitHubhttps://github.com//issues/31#issuecomment-12757020.
from pi4j-v1.
The class GpioScheduledExecutorImpl creates a ThreadPoolExecutor with a queue size of 5
scheduledExecutorService = Executors.newScheduledThreadPool(5);
You are submitting 16 jobs to the queue. The queue will be full after submitting only 5 jobs, then the Executor will start rejecting jobs.
It would seem to me that the size of the Executors queue should be at least equal to the number of gpio pins.
You could change the size of the Executors queue in the pi4j code or you could use this code, which would need to go into it's own thread to be useful.
this code doesn't quite do what you had coded, but I think it does what you intended - 50ms on then 50ms off on all pins.
while(true)
{
for (int i = 0; i <= 16; i++)
{
GPIOPinOut[i].high();
}
Thread.sleep(50); System.out.print(i + " ");
for (int i = 0; i <= 16; i++)
{
GPIOPinOut[i].low();
}
Thread.sleep(50); System.out.print(i + " ");
}
from pi4j-v1.
I am working on the scheduled executors issue.
Another workaround may be to use the new blocking pulse function that was added in 0.0.5-SNAPSHOT.
(https://github.com/Pi4J/pi4j/blob/develop/pi4j-core/src/main/java/com/pi4j/io/gpio/GpioPinDigitalOutput.java#L48)
GPIOPinOut[i].pulse(50);
Thread.sleep(50);
Since you are pulsing for 50 ms and then sleeping for 50 ms, I think this could be simplified using this single line and removing the sleep statement. The "true" argument will cause the pulse to block for the pulse duration.
GPIOPinOut[i].pulse(50, true);
This pulse() blocking call does not use the scheduled executor and will return a null future object.
(https://github.com/Pi4J/pi4j/blob/develop/pi4j-core/src/main/java/com/pi4j/io/gpio/impl/GpioPinImpl.java#L275)
The real issue of limited thread needs to be addressed in the project, but I think this will get it working for your particular situation.
Thanks, Robert
from pi4j-v1.
Robert,
thank you! The GPIOPinOut[i].pulse(50, true); seems to be right way to go for me and works like a charm. Now off to more challenging stuff...
--Andy
from pi4j-v1.
I am reopening the issue because the limited number of threads needs to be addressed in a future build.
from pi4j-v1.
Fixed in latest 0.0.5-SNAPSHOT (2013-02-09) build.
New build includes enough threads in the pool by default to handle all the RPi GPIO pins.
Also, there is a new ExecutorServiceFactory implementation that allow users to provide their own executor service factory where you can create the executors and manage your own thread pool.
from pi4j-v1.
Related Issues (20)
- Where is the PCA9685 code? HOT 3
- Published artifacts have class file version incompatible with JDK 8
- Parity bit is not sent with 1.4 on serial0 rpi4 HOT 1
- Computer Module 4 IO board Pinout issue
- PCA9685 servo question: setAlwaysOff sometimes makes the servo jump to zero position HOT 3
- Could be posible to manage Baud of 5800 on Serial0
- NoClassDefFoundError com/pi4j/io/gpio/gpiofactory HOT 5
- Not able to use spi in emteria.os
- Serial Port won't open HOT 5
- Can I use this library for other boards? HOT 2
- dependency on javax.xml.bind makes it impossible to jlink on JDK 11 HOT 3
- Question - change pinMode of GpioPinDigitalMultipurpose HOT 1
- [Question] serial control signals physical pins HOT 2
- J8 pin Different HOT 1
- PCIe x1 connector HOT 3
- Sorry, not something I can answer as the Pi4J project doesn't provide PCIE access.
- Serial buffer waits 100ms before letting me "read()" the bytes
- problem with openhab on pi4: not handling mcp23017 HOT 1
- vcgencmd is in /usr/bin on some systems - can you check this if /opt/vc.... isn't there
- Cannot run program "/opt/vc/bin/vcgencmd"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pi4j-v1.