Unipi with diozero



  • I am using Java with the diozero library to program a raspberry pi 3B+.
    I am able to control the relays after enabling i2c on the Pi.

    I am having issues with digital inputs. I found after installing evok that diozero could read digital inputs. I have not been able to locate the specific installation step that enables the digital inputs. The entire web server that comes with evok is not appropriate for our application, so I am searching for the step in evok installation that enables digital inputs.

    I have attempted to load the devices using:

    sudo bash
    # echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-1/device/new_device
    # echo 24c01 0x57 > /sys/class/i2c-dev/i2c-1/device/new_device
    # echo 24c02 0x50 > /sys/class/i2c-dev/i2c-1/device/new_device
    # ^D
    

    After I do this, I see the devices at /sys/bus/i2c/devices: 1-0050, 1-0057, 1-006f, and i2c-1. The digital inputs are still not read however.

    Has anyone had luck using digital inputs on the uniPi with the diozero Java library?

    Alternatively, could someone suggest an initialization step I missed? The uniPi documentation warns that Pull-up/down resistors must be initialized, but the diozero library contains that as part of the API and the diozero calls work on the system with evok installed. Evok does not need to be accessed once it is installed for the diozero library to work: diozero will work immediately after boot. This leads me to the conclusion that something in the evok installation or in the startup of the evok daemons is supplying the step I am missing.

    I am using a uniPi 1.1.


  • administrators

    Hello @rick3ry,
    the digital inputs are directly connected to the GPIOs of the Raspberry. Please reffer to the technical documentation, mainly page 4.

    Best regards,
    Martin



  • Thank you Martin. I have read the document. I have the inputs working, but only after I install evok. Something in the installation of evok that is not mentioned in the document is changing or initializing hardware so that it works with the diozero library. For instance, i2c must be enabled in the operating system before the relays will work; this is not mentioned in the document you refer to.

    I have two Pi boot disks: on one I installed evok, on the other I did not. I can run my Java program and see that it is properly detecting the digital input, but only on the system that had evok installed. I am not using evok for anything, but having it installed makes the difference.

    The simple program I am testing with:

    package testPi;
    
    import com.diozero.api.DigitalInputDevice;
    import com.diozero.api.GpioEventTrigger;
    import com.diozero.api.GpioPullUpDown;
    import com.diozero.util.SleepUtil;
    import org.pmw.tinylog.Logger;
    
    public class ButtonTest {
    	public static void main(String[] args) {
            int ThePin = 24;
            
            if (args.length > 0)
                ThePin = Integer.parseInt(args[0]);
            
    		test(ThePin);
    	}
    	
    	public static void test(int pin) {
            DigitalInputDevice di = new DigitalInputDevice(pin, GpioPullUpDown.PULL_UP, GpioEventTrigger.BOTH);
            for (;;) {
                SleepUtil.sleepSeconds(.5);
                System.out.printf("%b\n", di.getValue());
            }
        }
    }
    

  • administrators

    Hi @rick3ry,
    the evok only engages the pull up resistors via pygpio library. There is no other magic from our side, so you need to consult the behaviour of the diozero library with its authors.

    Thank you for understanding,
    Martin