• Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Unipi with diozero

    Scheduled Pinned Locked Moved Evok API
    4 Posts 2 Posters 1.8k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      rick3ry
      last edited by rick3ry

      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.

      Martin KudláčekM 1 Reply Last reply
      Reply Quote 0
      • Martin KudláčekM
        Martin Kudláček @rick3ry
        last edited by

        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

        1 Reply Last reply
        Reply Quote 0
        • R
          rick3ry
          last edited by

          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());
                  }
              }
          }
          
          Martin KudláčekM 1 Reply Last reply
          Reply Quote 0
          • Martin KudláčekM
            Martin Kudláček @rick3ry
            last edited by

            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

            1 Reply Last reply
            Reply Quote 0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post