Giter Club home page Giter Club logo

linux-gpio.java's Introduction

Linux-GPIO

Maven Central

Javadoc

CircleCI

Handle GPIO lines on a Linux system in a portable and fast way from the JVM.

  • Control several lines at once
  • Surprisingly fast
  • Better support for interrupts than others usual methods
  • Standard

Rationale

Handling GPIO lines from user space on a Linux system is typically done by writing directly to '/dev/mem' or to the more permissive '/dev/gpiomem'. While being fast, this approach is very closely thight to the hardware which means the code is not portable. Another way is to use the sysfs method where each pin is exported and represented in the file system. Users can read and write specific files for configuration and IO. While being standard, this method is slow and deprecated. Both methods present caveats. For instance, there is no way to claim pins nor any kind of automatic clean-up.

Since Linux 4.8, a new API is provided. It is not widely known nor used in spite of the fact it is standard and fast. Certain platforms such as Raspbian on the Raspberry Pi already support this API. This Java library wraps the C API in order to provide a more idiomatic interface accessible from the JVM while trying not to be too opiniated.

Usage

Any accessed GPIO device need at least read permission (which is enough even for writing). Typically, only the root user has access, hence permissions need to be set. For instance, for device 0 on a Raspberry Pi (user pi) :

$ chown root:pi /dev/gpiochip0
$ chmod g+r /dev/gpiochip0

The javadoc provide all details.

Have a look at the examples.

Run an example where $EXAMPLE is the name of an example such as AlternatingLeds :

$ ./gradlew :examples:$EXAMPLE:run

Run tests :

$ ./gradlew test

Run tests on the Raspberry Pi 3 (or similar), will test some IO :

$ ./gradlew test -DonRaspberry=true

Resources

License

Copyright © 2018 Adam Helinski

Licensed under the term of the Mozilla Public License 2.0, see LICENSE.

linux-gpio.java's People

Contributors

helins avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

sdo91 pratiklib16

linux-gpio.java's Issues

java 8 target

Hello,
I tested your lib with openjdk8. I recompiled all the dependencies and linux-gpio.java. It is working.
Nice job, I can count pulses in user space up to without any errors at 100hz (I didn't test greater frequency).

So, your default target can be java 8, it won't be a problem.
It can help other people that use old jdk for some reasons like me.

(this is really not a big issue)

event.getId() always returns 0

When I run the push buttons example, event.getId() always returns 0.
Any idea why that might be happening?
I'm running the code on an UP board, Ubuntu 16.04

I changed the device path and line numbers to match my board:

PATH_TO_DEVICE = "/dev/gpiochip4" ;
LINE_NUMBER_BUTTON_1 = 6 ;
LINE_NUMBER_BUTTON_2 = 5 ;

run output:

Starting push buttons...

Come on, press any button and keep pressin' ! Program will terminates after 15000 milliseconds of inactivity.

// when I push the 1st button (expected output: button 1)
1598314100861091495 button 0
1598314101203325508 button 0

// when I push the 2nd button (expected output: button 2)
1598314106373799169 button 0
1598314106500737447 button 0

Timeout, terminating program...

Override Gpio line consumer?

Hi,
I'm using your library to detect button press connected to gpio lines on imx6 board running embedded linux (buildroot). When I call GpioEventHandle requestEvent() to register the handle I'm getting IO exception: java.io.IOException: A requested line is already being used elsewhere
I read in your javadoc that request can be handled by one instance at a time. Is there a way to newly register request handle and overriding consumer which is already using it by setting new one? (FYI I did getconsumer on gpio line and it shows "sysfs")

Thanks

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.