Git Product home page Git Product logo

Comments (7)

savageautomate avatar savageautomate commented on June 30, 2024

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.

atael avatar atael commented on June 30, 2024

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.

rlsutton1 avatar rlsutton1 commented on June 30, 2024

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.

savageautomate avatar savageautomate commented on June 30, 2024

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.

atael avatar atael commented on June 30, 2024

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.

savageautomate avatar savageautomate commented on June 30, 2024

I am reopening the issue because the limited number of threads needs to be addressed in a future build.

from pi4j-v1.

savageautomate avatar savageautomate commented on June 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.