Pi4J / pi4j-v2

Pi4J Version 2.0
Apache License 2.0
268 stars 55 forks source link

No hardware PWM's on all GPIO #31

Open DanielMartensson opened 4 years ago

DanielMartensson commented 4 years ago

Hi!

Just started with Pi4J 2.0 and I got an error.

2020-07-10 15:44:02 gpioHardwarePWM: bad gpio for PWM (3)
[http-nio-8080-exec-5] WARN com.pi4j.library.pigpio.impl.PiGpioNativeImpl - PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM

And the Java code:

     // This will turn on/off the FQP30N06L MOSFET
    private Pwm createDigitalPWMOutput(int pinOutput, Context pi4j) {
        try {
            // use try-with-resources to auto-close I2C when complete
            PwmConfig config = Pwm.newConfigBuilder(pi4j)
                    .id("my-pwm-pin")
                    .name("My Test PWM Pin")
                    .address(pinOutput)
                    .pwmType(PwmType.HARDWARE)
                    .frequency(pwmFrequency)   // optionally pre-configure the desired frequency to 1KHz
                    .dutyCycle(0)     // optionally pre-configure the desired duty-cycle (50%)
                    .shutdown(0)       // optionally pre-configure a shutdown duty-cycle value (on terminate)
                    .initial(0)     // optionally pre-configure an initial duty-cycle value (on startup)
                    .build();
            Pwm pwm = pi4j.providers().get(PiGpioPwmProvider.class).create(config);
            pwm.on();
            return pwm;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

I call that function with:

Context pi4j = Pi4J.newAutoContext();
Pwm pwm0 = createDigitalPWMOutput(3, pi4j);

That's weird because Pigpio says that there are 0-31 hard ware PWM's http://abyz.me.uk/rpi/pigpio/

savageautomate commented 4 years ago

I have used hardware PWM in a live demo that I did for CodeOne 2019. So it's at least been tested before to some degree. Have you installed the latest version of PIGPIO from their site or are you using the version that comes with Raspbian?

If you have not already, I would suggest getting and installing he latest version: http://abyz.me.uk/rpi/pigpio/download.html

savageautomate commented 4 years ago

@DanielMartensson

It looks like I used different PWM channels in my demo project: https://github.com/Pi4J/pi4j-example-telegraph/blob/c07f4a92f50f60ecdc2229621b8cc57445e67330/src/main/java/com/pi4j/demo/telegraph/Telegraph.java#L48-L49

If it possible for you to try pin 18 or 19?

I wonder if there is a mode not getting applied to the requested PWM GPIO pin.

This looks suspicious: https://github.com/Pi4J/pi4j-v2/blob/5edf5a8a9d65f1dce1ce38397b14835c18030d40/plugins/pi4j-plugin-pigpio/src/main/java/com/pi4j/plugin/pigpio/provider/pwm/PiGpioPwmHardware.java#L77-L99

DanielMartensson commented 4 years ago

@DanielMartensson

It looks like I used different PWM channels in my demo project: https://github.com/Pi4J/pi4j-example-telegraph/blob/c07f4a92f50f60ecdc2229621b8cc57445e67330/src/main/java/com/pi4j/demo/telegraph/Telegraph.java#L48-L49

If it possible for you to try pin 18 or 19?

I wonder if there is a mode not getting applied to the requested PWM GPIO pin.

This looks suspicious:

https://github.com/Pi4J/pi4j-v2/blob/5edf5a8a9d65f1dce1ce38397b14835c18030d40/plugins/pi4j-plugin-pigpio/src/main/java/com/pi4j/plugin/pigpio/provider/pwm/PiGpioPwmHardware.java#L77-L99

I can try 4, 5, 6 and 13. That's clean GPIO's. No I2C or SPI.

DanielMartensson commented 4 years ago

I have used hardware PWM in a live demo that I did for CodeOne 2019. So it's at least been tested before to some degree. Have you installed the latest version of PIGPIO from their site or are you using the version that comes with Raspbian?

If you have not already, I would suggest getting and installing he latest version: http://abyz.me.uk/rpi/pigpio/download.html

I have

pi@raspberrypi:~/Documents $ pigpiod -version
71
pi@raspberrypi:~/Documents $ 
DanielMartensson commented 4 years ago

I post the whole error log and also the Java code:

Java code:


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;

import com.pi4j.Pi4J;
import com.pi4j.context.Context;
import com.pi4j.exception.Pi4JException;
import com.pi4j.io.gpio.digital.DigitalInput;
import com.pi4j.io.gpio.digital.DigitalInputConfig;
import com.pi4j.io.gpio.digital.DigitalInputProvider;
import com.pi4j.io.gpio.digital.PullResistance;
import com.pi4j.io.pwm.Pwm;
import com.pi4j.io.pwm.PwmConfig;
import com.pi4j.io.pwm.PwmType;
import com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmProvider;

import lombok.Getter;

@PropertySource("classpath:application.properties")
@Getter
public class IO {

    // Frequency for the PWM 
    @Value("${pi4j.pwmFrequency}")
    private int pwmFrequency;

    // PWM outputs
    private Pwm pwm0;
    private Pwm pwm1;
    private Pwm pwm2;
    private Pwm pwm3;

    // Digital inputs
    private DigitalInput pulseOn;
    private DigitalInput stopSignalOn;

    // ADS1115 16-Bit ADC
    private ADS1115_ADS1015 ads;

    public IO() {
        try {
            Context pi4j = Pi4J.newAutoContext();
            pwm0 = createDigitalPWMOutput(4, pi4j);
            pwm1 = createDigitalPWMOutput(5, pi4j);
            pwm2 = createDigitalPWMOutput(6, pi4j);
            pwm3 = createDigitalPWMOutput(13, pi4j);
            pulseOn = createDigitalInput(23, pi4j);
            stopSignalOn = createDigitalInput(24, pi4j);
            ads = new ADS1115_ADS1015(pi4j, 1, ADS1115_ADS1015.ADS_ADDR_GND); // I2C bus = 1
            ads.useADS1115();

        } catch (Pi4JException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    // This will read the pulse input and the stop signal
    private DigitalInput createDigitalInput(int pinInput, Context pi4j) {
        try {
            DigitalInputConfig config = DigitalInput.newConfigBuilder(pi4j)
                    .id("Digial input")
                    .name("Digital input")
                    .address(pinInput)
                    .pull(PullResistance.PULL_DOWN)
                    .debounce(3000L)
                    .build();

            // get a Digital Input I/O provider from the Pi4J context
            DigitalInputProvider digitalInputProvider = pi4j.provider("pigpio-digital-input");
            return digitalInputProvider.create(config);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;

    }

    // This will turn on/off the FQP30N06L MOSFET
    private Pwm createDigitalPWMOutput(int pinOutput, Context pi4j) {
        try {
            // use try-with-resources to auto-close I2C when complete
            PwmConfig config = Pwm.newConfigBuilder(pi4j)
                    .id("my-pwm-pin")
                    .name("My Test PWM Pin")
                    .address(pinOutput)
                    .pwmType(PwmType.HARDWARE)
                    .frequency(pwmFrequency)   // optionally pre-configure the desired frequency to 1KHz
                    .dutyCycle(0)     // optionally pre-configure the desired duty-cycle (50%)
                    .shutdown(0)       // optionally pre-configure a shutdown duty-cycle value (on terminate)
                    .initial(0)     // optionally pre-configure an initial duty-cycle value (on startup)
                    .build();
            Pwm pwm = pi4j.providers().get(PiGpioPwmProvider.class).create(config);
            pwm.on();
            return pwm;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}

And for the ADS1115 16-bit ADC

import java.io.IOException;

import com.pi4j.context.Context;
import com.pi4j.io.i2c.I2C;
import com.pi4j.io.i2c.I2CConfig;
import com.pi4j.io.i2c.I2CProvider;

// Not the complete class!
public class ADS1115_ADS1015 {

    public ADS1115_ADS1015(Context pi4j, Integer i2cBus, Integer i2cDevice) {
        hi2c = begin(pi4j, i2cBus, i2cDevice);
    }

    // This will read the ADS1115 16-bit ADC
    private I2C begin(Context pi4j, Integer i2cBus, Integer i2cDevice) {
        try {
            I2CConfig config = I2C.newConfigBuilder(pi4j)
                     .id("my-i2c-bus")
                     .name("My I2C Bus")
                     .bus(i2cBus)
                     .device(i2cDevice)
                     .build();
            I2CProvider i2CProvider = pi4j.provider("pigpio-i2c");
            return i2CProvider.create(config);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

pi@raspberrypi:~/Documents $ sudo java -jar opensourcelogger-1.0-SNAPSHOT.jar // Spring Boot start up only.... 2020-07-10 16:43:14 gpioHardwarePWM: bad gpio for PWM (4) [http-nio-8080-exec-1] WARN com.pi4j.library.pigpio.impl.PiGpioNativeImpl - PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM [http-nio-8080-exec-1] ERROR com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware - PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM java.io.IOException: PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM at com.pi4j.library.pigpio.impl.PiGpioBase.validateResult(PiGpioBase.java:292) at com.pi4j.library.pigpio.impl.PiGpioBase.validateResult(PiGpioBase.java:277) at com.pi4j.library.pigpio.impl.PiGpioNativeImpl.gpioHardwarePWM(PiGpioNativeImpl.java:597) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.off(PiGpioPwmHardware.java:162) at com.pi4j.io.pwm.PwmBase.initialize(PwmBase.java:119) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmBase.initialize(PiGpioPwmBase.java:88) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.initialize(PiGpioPwmHardware.java:120) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.initialize(PiGpioPwmHardware.java:50) at com.pi4j.provider.impl.ProviderProxyHandler.invoke(ProviderProxyHandler.java:105) at com.sun.proxy.$Proxy127.create(Unknown Source) at se.danielmartensson.pi4j.IO.createDigitalPWMOutput(IO.java:95) at se.danielmartensson.pi4j.IO.(IO.java:44) at se.danielmartensson.views.components.threads.ControlThread.(ControlThread.java:40) at se.danielmartensson.views.ControlView.init(ControlView.java:198) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at com.pi4j.exception.InitializeException: java.io.IOException: PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.initialize(PiGpioPwmHardware.java:127) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.initialize(PiGpioPwmHardware.java:50) at com.pi4j.provider.impl.ProviderProxyHandler.invoke(ProviderProxyHandler.java:105) at com.sun.proxy.$Proxy127.create(Unknown Source) at se.danielmartensson.pi4j.IO.createDigitalPWMOutput(IO.java:95) at se.danielmartensson.pi4j.IO.(IO.java:44) at se.danielmartensson.views.components.threads.ControlThread.(ControlThread.java:40) at se.danielmartensson.views.ControlView.init(ControlView.java:198) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at Caused by: com.pi4j.exception.InitializeException: java.io.IOException: PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM at com.pi4j.io.pwm.PwmBase.initialize(PwmBase.java:124) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmBase.initialize(PiGpioPwmBase.java:88) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.initialize(PiGpioPwmHardware.java:120) ... 87 more Caused by: com.pi4j.io.exception.IOException: java.io.IOException: PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.off(PiGpioPwmHardware.java:173) at com.pi4j.io.pwm.PwmBase.initialize(PwmBase.java:119) ... 89 more Caused by: java.io.IOException: PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM at com.pi4j.library.pigpio.impl.PiGpioBase.validateResult(PiGpioBase.java:292) at com.pi4j.library.pigpio.impl.PiGpioBase.validateResult(PiGpioBase.java:277) at com.pi4j.library.pigpio.impl.PiGpioNativeImpl.gpioHardwarePWM(PiGpioNativeImpl.java:597) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.off(PiGpioPwmHardware.java:162) ... 90 more 2020-07-10 16:43:14 gpioHardwarePWM: bad gpio for PWM (5) [http-nio-8080-exec-1] WARN com.pi4j.library.pigpio.impl.PiGpioNativeImpl - PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM [http-nio-8080-exec-1] ERROR com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware - PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM java.io.IOException: PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM at com.pi4j.library.pigpio.impl.PiGpioBase.validateResult(PiGpioBase.java:292) at com.pi4j.library.pigpio.impl.PiGpioBase.validateResult(PiGpioBase.java:277) at com.pi4j.library.pigpio.impl.PiGpioNativeImpl.gpioHardwarePWM(PiGpioNativeImpl.java:597) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.off(PiGpioPwmHardware.java:162) at com.pi4j.io.pwm.PwmBase.initialize(PwmBase.java:119) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmBase.initialize(PiGpioPwmBase.java:88) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.initialize(PiGpioPwmHardware.java:120) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.initialize(PiGpioPwmHardware.java:50) at com.pi4j.provider.impl.ProviderProxyHandler.invoke(ProviderProxyHandler.java:105) at com.sun.proxy.$Proxy127.create(Unknown Source) at se.danielmartensson.pi4j.IO.createDigitalPWMOutput(IO.java:95) at se.danielmartensson.pi4j.IO.(IO.java:45) at se.danielmartensson.views.components.threads.ControlThread.(ControlThread.java:40) at se.danielmartensson.views.ControlView.init(ControlView.java:198) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at com.pi4j.exception.InitializeException: java.io.IOException: PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.initialize(PiGpioPwmHardware.java:127) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.initialize(PiGpioPwmHardware.java:50) at com.pi4j.provider.impl.ProviderProxyHandler.invoke(ProviderProxyHandler.java:105) at com.sun.proxy.$Proxy127.create(Unknown Source) at se.danielmartensson.pi4j.IO.createDigitalPWMOutput(IO.java:95) at se.danielmartensson.pi4j.IO.(IO.java:45) at se.danielmartensson.views.components.threads.ControlThread.(ControlThread.java:40) at se.danielmartensson.views.ControlView.init(ControlView.java:198) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at Caused by: com.pi4j.exception.InitializeException: java.io.IOException: PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM at com.pi4j.io.pwm.PwmBase.initialize(PwmBase.java:124) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmBase.initialize(PiGpioPwmBase.java:88) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.initialize(PiGpioPwmHardware.java:120) ... 87 more Caused by: com.pi4j.io.exception.IOException: java.io.IOException: PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.off(PiGpioPwmHardware.java:173) at com.pi4j.io.pwm.PwmBase.initialize(PwmBase.java:119) ... 89 more Caused by: java.io.IOException: PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM at com.pi4j.library.pigpio.impl.PiGpioBase.validateResult(PiGpioBase.java:292) at com.pi4j.library.pigpio.impl.PiGpioBase.validateResult(PiGpioBase.java:277) at com.pi4j.library.pigpio.impl.PiGpioNativeImpl.gpioHardwarePWM(PiGpioNativeImpl.java:597) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.off(PiGpioPwmHardware.java:162) ... 90 more 2020-07-10 16:43:14 gpioHardwarePWM: bad gpio for PWM (6) [http-nio-8080-exec-1] WARN com.pi4j.library.pigpio.impl.PiGpioNativeImpl - PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM [http-nio-8080-exec-1] ERROR com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware - PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM java.io.IOException: PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM at com.pi4j.library.pigpio.impl.PiGpioBase.validateResult(PiGpioBase.java:292) at com.pi4j.library.pigpio.impl.PiGpioBase.validateResult(PiGpioBase.java:277) at com.pi4j.library.pigpio.impl.PiGpioNativeImpl.gpioHardwarePWM(PiGpioNativeImpl.java:597) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.off(PiGpioPwmHardware.java:162) at com.pi4j.io.pwm.PwmBase.initialize(PwmBase.java:119) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmBase.initialize(PiGpioPwmBase.java:88) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.initialize(PiGpioPwmHardware.java:120) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.initialize(PiGpioPwmHardware.java:50) at com.pi4j.provider.impl.ProviderProxyHandler.invoke(ProviderProxyHandler.java:105) at com.sun.proxy.$Proxy127.create(Unknown Source) at se.danielmartensson.pi4j.IO.createDigitalPWMOutput(IO.java:95) at se.danielmartensson.pi4j.IO.(IO.java:46) at se.danielmartensson.views.components.threads.ControlThread.(ControlThread.java:40) at se.danielmartensson.views.ControlView.init(ControlView.java:198) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at com.pi4j.exception.InitializeException: java.io.IOException: PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.initialize(PiGpioPwmHardware.java:127) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.initialize(PiGpioPwmHardware.java:50) at com.pi4j.provider.impl.ProviderProxyHandler.invoke(ProviderProxyHandler.java:105) at com.sun.proxy.$Proxy127.create(Unknown Source) at se.danielmartensson.pi4j.IO.createDigitalPWMOutput(IO.java:95) at se.danielmartensson.pi4j.IO.(IO.java:46) at se.danielmartensson.views.components.threads.ControlThread.(ControlThread.java:40) at se.danielmartensson.views.ControlView.init(ControlView.java:198) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at Caused by: com.pi4j.exception.InitializeException: java.io.IOException: PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM at com.pi4j.io.pwm.PwmBase.initialize(PwmBase.java:124) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmBase.initialize(PiGpioPwmBase.java:88) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.initialize(PiGpioPwmHardware.java:120) ... 87 more Caused by: com.pi4j.io.exception.IOException: java.io.IOException: PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.off(PiGpioPwmHardware.java:173) at com.pi4j.io.pwm.PwmBase.initialize(PwmBase.java:119) ... 89 more Caused by: java.io.IOException: PIGPIO ERROR: PI_NOT_HPWM_GPIO; GPIO has no hardware PWM at com.pi4j.library.pigpio.impl.PiGpioBase.validateResult(PiGpioBase.java:292) at com.pi4j.library.pigpio.impl.PiGpioBase.validateResult(PiGpioBase.java:277) at com.pi4j.library.pigpio.impl.PiGpioNativeImpl.gpioHardwarePWM(PiGpioNativeImpl.java:597) at com.pi4j.plugin.pigpio.provider.pwm.PiGpioPwmHardware.off(PiGpioPwmHardware.java:162) ... 90 more com.pi4j.io.exception.IOAlreadyExistsException: IO instance [Digial input] already exists in the Pi4J runtime context; unable to create a new instance using this reserved id. at com.pi4j.provider.impl.ProviderProxyHandler.invoke(ProviderProxyHandler.java:99) at com.sun.proxy.$Proxy126.create(Unknown Source) at se.danielmartensson.pi4j.IO.createDigitalInput(IO.java:73) at se.danielmartensson.pi4j.IO.(IO.java:49) at se.danielmartensson.views.components.threads.ControlThread.(ControlThread.java:40) at se.danielmartensson.views.ControlView.init(ControlView.java:198) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) 2020-07-10 16:43:15 sigHandler: Unhandled signal 11, terminating

2020-07-10 16:43:15 sigHandler: Unhandled signal 4, terminating

2020-07-10 16:43:15 sigHandler: Unhandled signal 11, terminating

pi@raspberrypi:~/Documents $

savageautomate commented 4 years ago

So reading that PIPGIO supported hardware PWM on pins 0-31 was a bit confusing to me.
From WiringPi, Pi4J V1 and all the previous work I had done with PWM ... I was only aware of two GPIO pins that supported hardware PWM --- ore more accurately two hardware PWM channels that could be exposed to select GPIO pins via the ALT modes: GPIO PINS 12,13,18,19

GPIO (BCM#) PWM Channel ALT Function URL
12 PWM0 ALT0 https://pinout.xyz/pinout/pin32_gpio12
13 PWM1 ALT0 https://pinout.xyz/pinout/pin32_gpio12
18 PWM0 ALT5 https://pinout.xyz/pinout/pin12_gpio18
19 PWM1 ALT5 https://pinout.xyz/pinout/pin35_gpio19

If you read further in the actual function description on PiGpio: http://abyz.me.uk/rpi/pigpio/cif.html#gpioHardwarePWM

You will see that it says: "The GPIO must be one of the following ..."

The same PWM channel is available on multiple GPIO. 
The latest frequency and dutycycle setting will be used by all GPIO which share a PWM channel.

The GPIO must be one of the following:

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only

So I think that the RaspberryPi hardware only supports 2 hardware PWM channel and they can be routed to the GPIO pins listed above --- but in the end you only get 2 hardware PWM channels.

So I'm not sure if the documentation on the PIPGIO site that says: "hardware timed PWM on all of GPIO 0-31" ... really just means that if you use the software PWM functions that the library is using some hardware timing elements to emulate PWM in software or if this just means that the library supports the hardware PWM functions on all pins, but its up to the actual hardware as to which pins can accept hardware PWM

So .. I guess try BCM pin 13.

DanielMartensson commented 4 years ago

So reading that PIPGIO supported hardware PWM on pins 0-31 was a bit confusing to me. From WiringPi, Pi4J V1 and all the previous work I had done with PWM ... I was only aware of two GPIO pins that supported hardware PWM --- ore more accurately two hardware PWM channels that could be exposed to select GPIO pins via the ALT modes: GPIO PINS 12,13,18,19

GPIO (BCM#) PWM Channel ALT Function URL 12 PWM0 ALT0 https://pinout.xyz/pinout/pin32_gpio12 13 PWM1 ALT0 https://pinout.xyz/pinout/pin32_gpio12 18 PWM0 ALT5 https://pinout.xyz/pinout/pin12_gpio18 19 PWM1 ALT5 https://pinout.xyz/pinout/pin35_gpio19 If you read further in the actual function description on PiGpio: http://abyz.me.uk/rpi/pigpio/cif.html#gpioHardwarePWM

You will see that it says: "The GPIO must be one of the following ..."

The same PWM channel is available on multiple GPIO. 
The latest frequency and dutycycle setting will be used by all GPIO which share a PWM channel.

The GPIO must be one of the following:

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only

So I think that the RaspberryPi hardware only supports 2 hardware PWM channel and they can be routed to the GPIO pins listed above --- but in the end you only get 2 hardware PWM channels.

So I'm not sure if the documentation on the PIPGIO site that says: "hardware timed PWM on all of GPIO 0-31" ... really just means that if you use the software PWM functions that the library is using some hardware timing elements to emulate PWM in software or if this just means that the library supports the hardware PWM functions on all pins, but its up to the actual hardware as to which pins can accept hardware PWM

So .. I guess try BCM pin 13.

So the conclusion is that there are 0-31 hardware PWM pins, bit raspberry pi can only use two of them?

I need 4 PWM pins - hardware.

DanielMartensson commented 4 years ago

Ok! It's seems to work now. But I have another issue you might want to look at.

I have selected the pins you suggested. It's seems to...not giving any errors. Also I removed the id-label. Not sure if they are needed.


public class IO {

    // Frequency for the PWM 
    @Value("${pi4j.pwmFrequency}")
    private int pwmFrequency;

    // PWM outputs
    private Pwm pwm0;
    private Pwm pwm1;
    private Pwm pwm2;
    private Pwm pwm3;

    // Digital inputs
    private DigitalInput pulseOn;
    private DigitalInput stopSignalOn;

    // ADS1115 16-Bit ADC
    private ADS1115_ADS1015 ads;

    public IO() {
        try {
            Context pi4j = Pi4J.newAutoContext();
            pwm0 = createDigitalPWMOutput(12, pi4j);
            pwm1 = createDigitalPWMOutput(13, pi4j);
            pwm2 = createDigitalPWMOutput(18, pi4j);
            pwm3 = createDigitalPWMOutput(19, pi4j);
            pulseOn = createDigitalInput(23, pi4j);
            stopSignalOn = createDigitalInput(24, pi4j);
            ads = new ADS1115_ADS1015(pi4j, 1, ADS1115_ADS1015.ADS_ADDR_GND); // I2C bus = 1
            ads.useADS1115();

        } catch (Pi4JException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    // This will read the pulse input and the stop signal
    private DigitalInput createDigitalInput(int pinInput, Context pi4j) {
        try {
            DigitalInputConfig config = DigitalInput.newConfigBuilder(pi4j)
                    .name("Digital input")
                    .address(pinInput)
                    .pull(PullResistance.PULL_DOWN)
                    .debounce(3000L)
                    .build();

            // get a Digital Input I/O provider from the Pi4J context
            DigitalInputProvider digitalInputProvider = pi4j.provider("pigpio-digital-input");
            return digitalInputProvider.create(config);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;

    }

    // This will turn on/off the FQP30N06L MOSFET
    private Pwm createDigitalPWMOutput(int pinOutput, Context pi4j) {
        try {
            // use try-with-resources to auto-close I2C when complete
            PwmConfig config = Pwm.newConfigBuilder(pi4j)
                    .name("My Test PWM Pin")
                    .address(pinOutput)
                    .pwmType(PwmType.HARDWARE)
                    .frequency(pwmFrequency)   // optionally pre-configure the desired frequency to 1KHz
                    .dutyCycle(0)     // optionally pre-configure the desired duty-cycle (50%)
                    .shutdown(0)       // optionally pre-configure a shutdown duty-cycle value (on terminate)
                    .initial(0)     // optionally pre-configure an initial duty-cycle value (on startup)
                    .build();
            Pwm pwm = pi4j.providers().get(PiGpioPwmProvider.class).create(config);
            pwm.on();
            return pwm;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}

And now to the error. Not sure what it means. But it close the spring boot application.


2020-07-11 12:32:34 sigHandler: Unhandled signal 11, terminating

2020-07-11 12:32:34 sigHandler: Unhandled signal 11, terminating
hackerjimbo commented 4 years ago

On 11/07/2020 11:35, Daniel Mårtensson wrote:

||

And now to the error. Not sure what it means. But it close the spring boot application.

|2020-07-11 12:32:34 sigHandler: Unhandled signal 11, terminating 2020-07-11 12:32:34 sigHandler: Unhandled signal 11, terminating |

I think this is an issue that I uncovered a while back. Essentially PiGpio decides it wants to control all the signal handlers. The Java runtime has different ideas. Chaos ensues.

I'll see if I can get a fix sorted this weekend.

Regards,

Jim.

DanielMartensson commented 4 years ago

On 11/07/2020 11:35, Daniel Mårtensson wrote: || And now to the error. Not sure what it means. But it close the spring boot application. |2020-07-11 12:32:34 sigHandler: Unhandled signal 11, terminating 2020-07-11 12:32:34 sigHandler: Unhandled signal 11, terminating | I think this is an issue that I uncovered a while back. Essentially PiGpio decides it wants to control all the signal handlers. The Java runtime has different ideas. Chaos ensues. I'll see if I can get a fix sorted this weekend. Regards, Jim.

Ok! I tried to add id-labels to all of them now. Separately id:s. Now I only got this error 2020-07-11 12:40:14 sigHandler: Unhandled signal 4, terminating I assume that your're right. Now I got Unhandled signal 11, terminating when I restarted my application.

savageautomate commented 4 years ago

@DanielMartensson

So the conclusion is that there are 0-31 hardware PWM pins, bit raspberry pi can only use two of them?

I need 4 PWM pins - hardware.

No, I don't think that accurately reflects the situation.

See this post in the Raspberry Pi forums: https://www.raspberrypi.org/forums/viewtopic.php?t=150254#p987511

Re: Which pin(s) on RPi 3B is PWM capable Quote Fri Jun 03, 2016 7:51 am

pigpio (and others) will provide hardware timed PWM on all the GPIO connected to the expansion header. Once started the > PWM uses no CPU time. It has less resolution and restricted frequencies compared to the two hardware PWM channels. >The default of 800Hz 250 steps is pretty much the same as an Arduino.

The Raspberry Pi supports 2 hardware based PWM channels. You can access these two channels via 2 separate sets of 4 GPIO header pins. But still limited to only 2 channels (2 unique PWM timing configurations).

The PIGPIO library is providing additional PWM support to any of the GPIO pins (0-31) and its using some hardware timing technique to optimize performance --- but its not the same as the actual hardware PWM pins natively on the RaspberryPi. In the Pi4J API, we would call this "Software" PWM and you would need to set .pwmType(PwmType.SOFTWARE). We consider this software-based PWM because its being provided at a software layer, in this case by the PIGPIO library.

If you need 4 PWM pins, then I would suggest trying to use the software PWM functionality, it may be perfectly fine for your application. If they are not good enough, then you will probably need a PWM expander board/chip (controlled by I2C/SPI) to provide additional PWM support.

Thanks, Robert

savageautomate commented 4 years ago

Ok! It's seems to work now. But I have another issue you might want to look at.

I have selected the pins you suggested. It's seems to...not giving any errors. Also I removed the id-label. Not sure if they are needed.

The ID is not required, it will get auto-assigned an identifier string if you don't provide one. If you do provide one, they must be unique.

As @hackerjimbo mentioned, the signals issues was recently uncovered and is being tracked via issue: #15

DanielMartensson commented 4 years ago

@DanielMartensson

So the conclusion is that there are 0-31 hardware PWM pins, bit raspberry pi can only use two of them? I need 4 PWM pins - hardware.

No, I don't think that accurately reflects the situation.

See this post in the Raspberry Pi forums: https://www.raspberrypi.org/forums/viewtopic.php?t=150254#p987511

Re: Which pin(s) on RPi 3B is PWM capable Quote Fri Jun 03, 2016 7:51 am pigpio (and others) will provide hardware timed PWM on all the GPIO connected to the expansion header. Once started the > PWM uses no CPU time. It has less resolution and restricted frequencies compared to the two hardware PWM channels. >The default of 800Hz 250 steps is pretty much the same as an Arduino.

The Raspberry Pi supports 2 hardware based PWM channels. You can access these two channels via 2 separate sets of 4 GPIO header pins. But still limited to only 2 channels (2 unique PWM timing configurations).

The PIGPIO library is providing additional PWM support to any of the GPIO pins (0-31) and its using some hardware timing technique to optimize performance --- but its not the same as the actual hardware PWM pins natively on the RaspberryPi. In the Pi4J API, we would call this "Software" PWM and you would need to set .pwmType(PwmType.SOFTWARE). We consider this software-based PWM because its being provided at a software layer, in this case by the PIGPIO library.

If you need 4 PWM pins, then I would suggest trying to use the software PWM functionality, it may be perfectly fine for your application. If they are not good enough, then you will probably need a PWM expander board/chip (controlled by I2C/SPI) to provide additional PWM support.

Thanks, Robert

Hmm.. Still got the error, even if I replaced all hardware enums with software enums.

2020-07-12 19:56:03 sigHandler: Unhandled signal 4, terminating
hackerjimbo commented 4 years ago

That's because it's got nothing to do with the enums, it's all about signal handling. Signal 4 is illegal instruction rather than your earlier signal 11 (segmentation fault).

@DanielMartensson, what hardware are you running on?

DanielMartensson commented 4 years ago

That's because it's got nothing to do with the enums, it's all about signal handling. Signal 4 is illegal instruction rather than your earlier signal 11 (segmentation fault).

@DanielMartensson, what hardware are you running on?

I'm using Raspberry Pi 4B

hackerjimbo commented 4 years ago

OK, I now have no idea why it's not work. It should get this right.

DanielMartensson commented 4 years ago

OK, I now have no idea why it's not work. It should get this right.

Perhaps the Pi4J project is to complex? I personally would avoid OOP when talking to hardware. Only use functions.

hackerjimbo commented 4 years ago

I make a lot of use of OOP on my hardware drivers. A great (and very recent) one was talking to the SH1106 display driver. This is available via both I2C and SPI. The vast majority of the code is common but I have a few abstract methods that allow me to drive it one the specific device in use. See also the MCP27x17.

Are you running 32 or 64 bit on the Pi 4? I know for certain that the 32-bit one probes the exact hardware in use by checking what works and what doesn't (trapping the illegal instructions and from that deducing what the functionality available). This allows the JIT compilation to be perfectly tuned for the hardware.

I wouldn't describe Pi4J as too complex. Software only gets complex when it hits 1 000 000 lines! :-)

Right now we're shaking down the pigpio drivers (which I think we've fixed now) and getting Pi4J to talk nicely to them even on a Pi Zero (getting cross-compilation right, which I also think we've done). Not bad for about a week's work!

DanielMartensson commented 4 years ago

I make a lot of use of OOP on my hardware drivers. A great (and very recent) one was talking to the SH1106 display driver. This is available via both I2C and SPI. The vast majority of the code is common but I have a few abstract methods that allow me to drive it one the specific device in use. See also the MCP27x17.

Are you running 32 or 64 bit on the Pi 4? I know for certain that the 32-bit one probes the exact hardware in use by checking what works and what doesn't (trapping the illegal instructions and from that deducing what the functionality available). This allows the JIT compilation to be perfectly tuned for the hardware.

I wouldn't describe Pi4J as too complex. Software only gets complex when it hits 1 000 000 lines! :-)

Right now we're shaking down the pigpio drivers (which I think we've fixed now) and getting Pi4J to talk nicely to them even on a Pi Zero (getting cross-compilation right, which I also think we've done). Not bad for about a week's work!

I'm using ARMv7 Processor, which is 32 bit.

pi@raspberrypi:~/Documents $ cat /proc/cpuinfo
processor   : 0
model name  : ARMv7 Processor rev 3 (v7l)
BogoMIPS    : 108.00
Features    : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part    : 0xd08
CPU revision    : 3

processor   : 1
model name  : ARMv7 Processor rev 3 (v7l)
BogoMIPS    : 108.00
Features    : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part    : 0xd08
CPU revision    : 3

processor   : 2
model name  : ARMv7 Processor rev 3 (v7l)
BogoMIPS    : 108.00
Features    : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part    : 0xd08
CPU revision    : 3

processor   : 3
model name  : ARMv7 Processor rev 3 (v7l)
BogoMIPS    : 108.00
Features    : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part    : 0xd08
CPU revision    : 3

Hardware    : BCM2835
Revision    : b03112
Serial      : 1000000020b891af
Model       : Raspberry Pi 4 Model B Rev 1.2
pi@raspberrypi:~/Documents $
hackerjimbo commented 4 years ago

The v7l means that it's a 64-bit processor operating in 32-bit mode. You've also got a more recent model than I because I have the 1.1 version. Although the other Pi 4 is a 1.4! :-)

However, knowing that you're running in 32-bit mode is helpful. Which JVM are you using?

DanielMartensson commented 4 years ago

The v7l means that it's a 64-bit processor operating in 32-bit mode. You've also got a more recent model than I because I have the 1.1 version. Although the other Pi 4 is a 1.4! :-)

However, knowing that you're running in 32-bit mode is helpful. Which JVM are you using?

pi@raspberrypi:~/Documents $ java --version
openjdk 11.0.7 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Raspbian-3deb10u1)
OpenJDK Server VM (build 11.0.7+10-post-Raspbian-3deb10u1, mixed mode)
pi@raspberrypi:~/Documents $ 
hackerjimbo commented 4 years ago

Just for reference for @savageautomate and others, on the Pi Zeros I'm using:

openjdk 11.0.7 2020-04-14 LTS
OpenJDK Runtime Environment Zulu11.39+61-CA (build 11.0.7+10-LTS)
OpenJDK Client VM Zulu11.39+61-CA (build 11.0.7+10-LTS, mixed mode)
DanielMartensson commented 4 years ago

Just for reference for @savageautomate and others, on the Pi Zeros I'm using:

openjdk 11.0.7 2020-04-14 LTS OpenJDK Runtime Environment Zulu11.39+61-CA (build 11.0.7+10-LTS) OpenJDK Client VM Zulu11.39+61-CA (build 11.0.7+10-LTS, mixed mode)

Do you think Java 8 will solve this issue temporary?

hackerjimbo commented 4 years ago

No. Pi4J-v2 is based on Java 11 and uses the extra features of that. The issues aren't with the language version but with the binding to PiGPIO. I think we've got that more-or-less understood and fixed now.

DanielMartensson commented 4 years ago

No. Pi4J-v2 is based on Java 11 and uses the extra features of that. The issues aren't with the language version but with the binding to PiGPIO. I think we've got that more-or-less understood and fixed now.

If you want! I can upload my web application software so you can really see what issues there are inside my setup?

hackerjimbo commented 4 years ago

I'd like to get the known issues fixed and publicly available. Then we'll see which of yours remain.

DanielMartensson commented 4 years ago

I'd like to get the known issues fixed and publicly available. Then we'll see which of yours remain.

This will help. https://github.com/DanielMartensson/OpenSourceLogger

@savageautomate @FDelporte

FDelporte commented 4 years ago

Thanks for all the info shared in this topic, I used it for the initial content of the PWM page on the new site --> https://v2.pi4j.com/getting-started/io-examples/pwm

DanielMartensson commented 4 years ago

Thanks for all the info shared in this topic, I used it for the initial content of the PWM page on the new site --> https://v2.pi4j.com/getting-started/io-examples/pwm

Did you try my software? Perhaps it will work on your Pi?

FDelporte commented 4 years ago

@DanielMartensson no sorry, not yet, I'm a bit behind with testing on the Pi itself...

savageautomate commented 4 years ago

@DanielMartensson

Here is a compiled from (pi4j-library-pigpio-2.0-SNAPSHOT.jar) JAR with @hackerjimbo 's suggested fix for the signals issue if you want to give it a try: https://www.dropbox.com/s/8cm176mbknk2s0m/pi4j-library-pigpio-2.0-SNAPSHOT.jar

DanielMartensson commented 4 years ago

@DanielMartensson

Here is a compiled from (pi4j-library-pigpio-2.0-SNAPSHOT.jar) JAR with @hackerjimbo 's suggested fix for the signals issue if you want to give it a try: https://www.dropbox.com/s/8cm176mbknk2s0m/pi4j-library-pigpio-2.0-SNAPSHOT.jar

Is is available for pom.xml?

The current settings for my pom.xml

<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>se.danielmartensson</groupId>
    <artifactId>opensourcelogger</artifactId>
    <name>OpenSourceLogger</name>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <vaadin.version>14.2.1</vaadin.version>

        <!-- DEPENDENCIES VERSIONS for Pi4J -->
        <slf4j.version>2.0.0-alpha0</slf4j.version>
        <pi4j.version>2.0-SNAPSHOT</pi4j.version>

    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.0.RELEASE</version>
    </parent>

    <repositories>
        <!-- The order of definitions matters. Explicitly defining central here to make sure it has the highest priority. -->

        <!-- Main Maven repository -->
        <repository>
            <id>central</id>
            <url>https://repo.maven.apache.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>

        <!-- Repository used by many Vaadin add-ons -->
        <repository>
            <id>Vaadin Directory</id>
            <url>https://maven.vaadin.com/vaadin-addons</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
           <id>vaadin-addons</id>
           <url>https://maven.vaadin.com/vaadin-addons</url>
        </repository>

        <!-- Pi4J 2.0 repository -->
        <repository>
            <id>oss-snapshots-repo</id>
            <name>Sonatype OSS Maven Repository</name>
            <url>https://oss.sonatype.org/content/groups/public</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>

    </repositories>

    <pluginRepositories>
        <!-- Main Maven repository -->
        <pluginRepository>
            <id>central</id>
            <url>https://repo.maven.apache.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-bom</artifactId>
                <version>${vaadin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>com.vaadin</groupId>
            <!-- Replace artifactId with vaadin-core to use only free components -->
            <artifactId>vaadin</artifactId>
            <exclusions>
                <!-- Webjars are only needed when running in Vaadin 13 compatibility mode -->
                <exclusion>
                    <groupId>com.vaadin.webjar</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.insites</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.polymer</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.polymerelements</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.vaadin</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.webcomponents</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-spring-boot-starter</artifactId>
            <exclusions>
                <!-- Excluding so that webjars are not included. -->
                <exclusion>
                    <groupId>com.vaadin</groupId>
                    <artifactId>vaadin-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-testbench</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <!-- Added by me -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
           <groupId>org.vaadin.crudui</groupId>
           <artifactId>crudui</artifactId>
           <version>4.3.0</version>
        </dependency>
        <dependency>
           <groupId>com.github.appreciated</groupId>
           <artifactId>apexcharts</artifactId>
           <version>2.0.0.beta9</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>

        <!-- Pi4J Dependencies -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
        </dependency>

        <!-- include Pi4J Core -->
        <dependency>
            <groupId>com.pi4j</groupId>
            <artifactId>pi4j-core</artifactId>
            <version>${pi4j.version}</version>
        </dependency>

        <!-- include Pi4J Plugins (Platforms and I/O Providers) -->
        <dependency>
            <groupId>com.pi4j</groupId>
            <artifactId>pi4j-plugin-raspberrypi</artifactId>
            <version>${pi4j.version}</version>
        </dependency>
        <dependency>
            <groupId>com.pi4j</groupId>
            <artifactId>pi4j-plugin-pigpio</artifactId>
            <version>${pi4j.version}</version>
        </dependency>
    </dependencies>

    <build>
        <defaultGoal>spring-boot:run</defaultGoal>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <!-- Clean build and startup time for Vaadin apps sometimes may exceed
                     the default Spring Boot's 30sec timeout.  -->
                <configuration>
                    <wait>500</wait>
                    <maxAttempts>240</maxAttempts>
                </configuration>
            </plugin>

            <!--
                Take care of synchronizing java dependencies and imports in
                package.json and main.js files.
                It also creates webpack.config.js if not exists yet.
            -->
            <plugin>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-maven-plugin</artifactId>
                <version>${vaadin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-frontend</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <!-- Production mode is activated using -Pproduction -->
            <id>production</id>
            <properties>
                <vaadin.productionMode>true</vaadin.productionMode>
            </properties>

            <dependencies>
                <dependency>
                    <groupId>com.vaadin</groupId>
                    <artifactId>flow-server-production-mode</artifactId>
                </dependency>
            </dependencies>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <configuration>
                            <jvmArguments>-Dvaadin.productionMode</jvmArguments>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>com.vaadin</groupId>
                        <artifactId>vaadin-maven-plugin</artifactId>
                        <version>${vaadin.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>build-frontend</goal>
                                </goals>
                                <phase>compile</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>it</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>start-spring-boot</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>stop-spring-boot</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- Runs the integration tests (*IT) after the server is started -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <trimStackTrace>false</trimStackTrace>
                            <enableAssertions>true</enableAssertions>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

    </profiles>
</project>
savageautomate commented 4 years ago

@DanielMartensson

As soon as @hackerjimbo confirms the fix here, I'll deploy it to the maven repositories.

In the meantime, you could manually copy the JAR file into the directory where you are running it on the Pi.

DanielMartensson commented 4 years ago

@DanielMartensson

As soon as @hackerjimbo confirms the fix here, I'll deploy it to the maven repositories.

In the meantime, you could manually copy the JAR file into the directory where you are running it on the Pi.

@savageautomate

Do I have to remove the Pi4J dependencies in Pom.xml?

I tried to include the JAR file into my project. Still got the same error

2020-07-13 17:08:39 sigHandler: Unhandled signal 4, terminating

Notice that I'm using Pi4J inside a thread.

I tried also to remove Pi4J-Core dependency in Pom.xml, but it gave me the same result -

2020-07-13 17:16:23 sigHandler: Unhandled signal 4, terminating
hackerjimbo commented 4 years ago

@savageautomate — it works! Tested on a Pi Zero and a Pi 1. Both crash with the old version of the java code and the system pigpio and now work with the OS-supplied pigpio and the fix you posted. Great work!

DanielMartensson commented 4 years ago

Have a look at this code: https://github.com/DanielMartensson/OpenSourceLogger/blob/master/src/main/java/se/danielmartensson/views/components/threads/ControlThread.java

       public ControlThread(IO io) {
        pwm0 = io.getPwm0();
        pwm1 = io.getPwm1();
        pwm2 = io.getPwm2();
        pwm3 = io.getPwm3();
        pulseOn = io.getPulseOn();
        stopSignalOn = io.getStopSignalOn();
        ads = io.getAds();
    }

https://github.com/DanielMartensson/OpenSourceLogger/blob/master/src/main/java/se/danielmartensson/views/ControlView.java

                @Autowired
            private IO io;

                // Start the tread forcontrol
        if(control == null) {
            control = new ControlThread(io);
            control.start();
        }

https://github.com/DanielMartensson/OpenSourceLogger/blob/master/src/main/java/se/danielmartensson/pi4j/IO.java

            public IO() {
        try {
            Context pi4j = Pi4J.newAutoContext();
            pwm0 = createDigitalPWMOutput(12, pi4j, "pwm0");
            pwm1 = createDigitalPWMOutput(13, pi4j, "pwm1");
            pwm2 = createDigitalPWMOutput(18, pi4j, "pwm2");
            pwm3 = createDigitalPWMOutput(19, pi4j, "pwm3");
            pulseOn = createDigitalInput(23, pi4j, "di0");
            stopSignalOn = createDigitalInput(24, pi4j, "di1");
            ads = new ADS1115_ADS1015(pi4j, 1, ADS1115_ADS1015.ADS_ADDR_GND); // I2C bus = 1
            ads.useADS1115();

        } catch (Pi4JException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
DanielMartensson commented 4 years ago

@savageautomate — it works! Tested on a Pi Zero and a Pi 1. Both crash with the old version of the java code and the system pigpio and now work with the OS-supplied pigpio and the fix you posted. Great work!

Why did it not work for me?

savageautomate commented 4 years ago

@DanielMartensson ,

Why did it not work for me?

Please try again. I have deployed the latest version (with the signal fix) to the Maven SNAPSHOT repository now.

You may want to first delete the directory and files on your local system where this JAR file could be cached to ensure the new version is picked up by Maven.

~/.m2/repository/com/pi4j/pi4j-library-pigpio/
DanielMartensson commented 4 years ago

@DanielMartensson ,

Why did it not work for me?

Please try again. I have deployed the latest version (with the signal fix) to the Maven SNAPSHOT repository now.

You may want to first delete the directory and files on your local system where this JAR file could be cached to ensure the new version is picked up by Maven.

~/.m2/repository/com/pi4j/pi4j-library-pigpio/

Ok! Seems that there are no errors now :) Need to check if the PWM's can pulse too.

savageautomate commented 4 years ago

@DanielMartensson

Just checking in to see if this issue can now be closed.

Thanks, Robert

DanielMartensson commented 4 years ago

@DanielMartensson

Just checking in to see if this issue can now be closed.

Thanks, Robert

I haven't test my PWM's yet. I just have created my project and I will soon test it. https://github.com/DanielMartensson/OpenSourceLogger

DanielMartensson commented 4 years ago

@savageautomate

Nope. No activity from the GPIO's here:

https://github.com/DanielMartensson/OpenSourceLogger/blob/master/src/main/java/se/danielmartensson/views/components/threads/ControlThread.java

Row 134 It seems that the duty cycle is not set. The doX variables are set.