With Pi4J, I can communicate with I2C with Java. But is there any way I can communicate with I2C with Java, without Pi4J. Just by using Linux internal...shell-ish...command?

I want to read and write data.

  • Not Pi specific. The I2C device is implemented as a file. If Java allows you to read and write files you can use I2C.
    – joan
    Commented Oct 8, 2020 at 9:21
  • @joan How can I do that? Can I use ProcessBuilder to work with the file? Any commands etc?
    – euraad
    Commented Oct 8, 2020 at 9:23
  • This has nothing to do with the Pi. This is the wrong site for the question.
    – joan
    Commented Oct 8, 2020 at 10:19

1 Answer 1


Implementation example available here: https://github.com/mattjlewis/diozero/tree/master/diozero-core/src/main/java/com/diozero/internal/provider/builtin/i2c Two versions, one via JNI, the other using a Java RandomAccessFile. Note that for the second Java implementation a small bit of C code is required to run an ioctl command to setup the file for I2C (I2C select slave).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.