question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue init GPIO on TinkerBoard

See original GitHub issue

[…] I will do more tests asap […] _Originally posted by @zixzix in https://github.com/mattjlewis/diozero/issues/69#issuecomment-819760978_

After many tests I noticed some strange behaviors that I report here in detail

Test Environment

TinkerBoard 1
Armbian Focal 21.02.3
Diozero 1.2.1
Java 16
Tomcat 10
OUT Pin for test: 184, 163, 162
IN Pin for test: 257, 166, 168

Java code for init DigitalInputDevice

DigitalInputDevice pin = new DigitalInputDevice(pinNumber, GpioPullUpDown.PULL_UP, GpioEventTrigger.BOTH);
pin.addListener(event -> {...});

Java code for init DigitalOutputDevice

DigitalOutputDevice pin = new DigitalOutputDevice(pinNumber, true, false);

Java code for close Pin

pin.close();

Java code for shutdown

DeviceFactoryHelper.shutdown();

Scenario 1 (diozero.gpio.chardev=false) First init of new DigitalInputDevice works fine. First init of new DigitalOutputDevice works fine.

After close all initialized pins and call shutdown method

Second init of new DigitalInputDevice fails with following error:

epoll_ctl: error in add, Bad file descriptor
com.diozero.api.RuntimeIOException: Error registering file '/sys/class/gpio/gpio257/value' with epoll
        at com.diozero.util.EpollNative.register(EpollNative.java:168)
        at com.diozero.internal.provider.builtin.SysFsDigitalInputDevice.enableListener(SysFsDigitalInputDevice.java:122)
        at com.diozero.internal.spi.AbstractInputDevice.setListener(AbstractInputDevice.java:58)
        at com.diozero.api.DigitalInputDevice.setListener(DigitalInputDevice.java:252)
        at com.diozero.api.AbstractDigitalInputDevice.enableDeviceListener(AbstractDigitalInputDevice.java:71)
        at com.diozero.api.GpioInputDevice.addListener(GpioInputDevice.java:64)

Second init of new DigitalOutputDevice fails with following error:

java.lang.NullPointerException: Cannot load from object array because "this.gpioBanks" is null
        at com.diozero.internal.board.tinkerboard.TinkerBoardMmapGpio.gpioWrite(TinkerBoardMmapGpio.java:312)
        at com.diozero.internal.provider.builtin.SysFsDigitalOutputDevice.setValue(SysFsDigitalOutputDevice.java:102)
        at com.diozero.internal.provider.builtin.SysFsDigitalOutputDevice.<init>(SysFsDigitalOutputDevice.java:76)
        at com.diozero.internal.provider.builtin.DefaultDeviceFactory.createDigitalOutputDevice(DefaultDeviceFactory.java:262)
        at com.diozero.internal.spi.GpioDeviceFactoryInterface.provisionDigitalOutputDevice(GpioDeviceFactoryInterface.java:84)
        at com.diozero.api.DigitalOutputDevice.<init>(DigitalOutputDevice.java:158)
        at com.diozero.api.DigitalOutputDevice.<init>(DigitalOutputDevice.java:142)

Scenario 2 (diozero.gpio.chardev=false) First init of new DigitalInputDevice works fine. First init of new DigitalOutputDevice works fine.

After close all initialized pins and without call shutdown method

Second init of new DigitalOutputDevice works fine Second init of new DigitalInputDevice give me the following warn but works:

  • No listener for fd 93, event value: ‘1’
  • No listener for fd 95, event value: ‘1’

Scenario 3 (diozero.gpio.chardev=true) First init of new DigitalOutputDevice works fine. First init of new DigitalInputDevice fails with following error:

java.lang.IndexOutOfBoundsException
        at java.base/java.nio.Buffer.checkIndex(Unknown Source)
        at java.base/java.nio.DirectIntBufferU.get(Unknown Source)
        at com.diozero.util.MmapIntBuffer.get(MmapIntBuffer.java:56)
        at com.diozero.internal.board.tinkerboard.TinkerBoardMmapGpio.setPullUpDown(TinkerBoardMmapGpio.java:281)
        at com.diozero.internal.provider.builtin.NativeGpioInputDevice.<init>(NativeGpioInputDevice.java:69)
        at com.diozero.internal.provider.builtin.DefaultDeviceFactory.createDigitalInputDevice(DefaultDeviceFactory.java:240)
        at com.diozero.internal.spi.GpioDeviceFactoryInterface.provisionDigitalInputDevice(GpioDeviceFactoryInterface.java:61)
        at com.diozero.api.DigitalInputDevice.<init>(DigitalInputDevice.java:195)
        at com.diozero.api.DigitalInputDevice.<init>(DigitalInputDevice.java:175)

After close all initialized pins and call shutdown method

Second init of new DigitalInputDevice fails with following error:

java.lang.IllegalArgumentException: Can't find chip for id 5
        at com.diozero.internal.provider.builtin.DefaultDeviceFactory.createDigitalInputDevice(DefaultDeviceFactory.java:237)
        at com.diozero.internal.spi.GpioDeviceFactoryInterface.provisionDigitalInputDevice(GpioDeviceFactoryInterface.java:61)
        at com.diozero.api.DigitalInputDevice.<init>(DigitalInputDevice.java:195)
        at com.diozero.api.DigitalInputDevice.<init>(DigitalInputDevice.java:175)

Second init of new DigitalOutputDevice fails with following error:

java.lang.IllegalArgumentException: Can't find chip for id 6
        at com.diozero.internal.provider.builtin.DefaultDeviceFactory.createDigitalOutputDevice(DefaultDeviceFactory.java:256)
        at com.diozero.internal.spi.GpioDeviceFactoryInterface.provisionDigitalOutputDevice(GpioDeviceFactoryInterface.java:84)
        at com.diozero.api.DigitalOutputDevice.<init>(DigitalOutputDevice.java:158)
        at com.diozero.api.DigitalOutputDevice.<init>(DigitalOutputDevice.java:142)

Scenario 4 (diozero.gpio.chardev=true) First init of new DigitalOutputDevice works fine. First init of new DigitalInputDevice fails with following error:

java.lang.IndexOutOfBoundsException
        at java.base/java.nio.Buffer.checkIndex(Unknown Source)
        at java.base/java.nio.DirectIntBufferU.get(Unknown Source)
        at com.diozero.util.MmapIntBuffer.get(MmapIntBuffer.java:56)
        at com.diozero.internal.board.tinkerboard.TinkerBoardMmapGpio.setPullUpDown(TinkerBoardMmapGpio.java:281)
        at com.diozero.internal.provider.builtin.NativeGpioInputDevice.<init>(NativeGpioInputDevice.java:69)
        at com.diozero.internal.provider.builtin.DefaultDeviceFactory.createDigitalInputDevice(DefaultDeviceFactory.java:240)
        at com.diozero.internal.spi.GpioDeviceFactoryInterface.provisionDigitalInputDevice(GpioDeviceFactoryInterface.java:61)
        at com.diozero.api.DigitalInputDevice.<init>(DigitalInputDevice.java:195)
        at com.diozero.api.DigitalInputDevice.<init>(DigitalInputDevice.java:175)

After close all initialized pins and without call shutdown method Second init of new DigitalOutputDevice works fine. Second init of new DigitalInputDevice fails with following error:

Error setting line event: Device or resource busy
com.diozero.api.RuntimeIOException: Error in provisionGpioInputDevice: -16
        at com.diozero.internal.provider.builtin.gpio.GpioChip.provisionGpioInputDevice(GpioChip.java:203)
        at com.diozero.internal.provider.builtin.NativeGpioInputDevice.<init>(NativeGpioInputDevice.java:65)
        at com.diozero.internal.provider.builtin.DefaultDeviceFactory.createDigitalInputDevice(DefaultDeviceFactory.java:240)
        at com.diozero.internal.spi.GpioDeviceFactoryInterface.provisionDigitalInputDevice(GpioDeviceFactoryInterface.java:61)
        at com.diozero.api.DigitalInputDevice.<init>(DigitalInputDevice.java:195)
        at com.diozero.api.DigitalInputDevice.<init>(DigitalInputDevice.java:175)

I am available to provide further data and tests Thank you

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mattjlewiscommented, May 14, 2021

I think I’ve reproduced scenarios 1-3 with this test app: https://github.com/mattjlewis/diozero/blob/main/diozero-sampleapps/src/main/java/com/diozero/sampleapps/ShutdownRestartTest.java Scenario 4 might be TinkerBoard specific, will check later. I’ll commit and push as 1.2.2 this weekend after further tests.

0reactions
mattjlewiscommented, Jun 3, 2021

Assume fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

GPIO connect Relay not working - Hardware - Tinker Board
Dears: When I try to connect the Relay through the GPIO pin, pulling the pin high or low has no effect. The same...
Read more >
Access GPIOs on Asus Tinker Board S - Configuration
I'm working to get tinker board mimic the RPi, as Asus projected. But at certain point there are problem regarding the permissions to...
Read more >
Tinker Board GPIO - Tinkerboard - Armbian Community Forums
The 16 post relay board I am using wants 3.3 volts to signal the logic board as 12 volts to power the relays....
Read more >
Asus Tinker Board S R2.0 - Product support - balena Forums
Asus Tinker Board S R2.0 Wifi issue. When using the image for the Tinker Board S, and then running nmcli dev (while connected...
Read more >
Tinker Board 2S 6-Core 2.0 GHz Rockchip RK3399 Single ...
Amazon.com: Tinker Board 2S 6-Core 2.0 GHz Rockchip RK3399 Single Board Computer 4GB RAM 16GB eMMC Storage GB LAN Wi-Fi & Bluetooth 5.0...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found