Romek
Posts: 1
Joined: Wed Sep 12, 2012 11:45 am

I2C with Java?

Wed Sep 12, 2012 11:51 am

I've found a handful of libraries around which enable me to access the GPIO pins in Java, but is there anything around for the I2C? I've been searching around for quite a while now, so any help would be appreciated. Thanks in advance!

User avatar
xranby
Posts: 539
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: I2C with Java?

Fri Sep 14, 2012 8:23 am

I think the easiest way to access I2C with Java is by first load the i2c-dev Linux kernel module

Code: Select all

sudo modprobe i2c-dev
This Linux kernel module will setup files in /dev/i2c-* that maps to all attached i2c devices.

To access these files from java you need to be able to issue linux specific "ioctl" calls, the most straight forward way to do it is by connecting Java to the system "c" library that contains the ioctl function call using JNA:
Take a look at the sourcecode to purejavacomm this file show how to map the "c" library using JNA in order to give Java applications access to "ioctl".
https://github.com/nyholku/purejavacomm ... l.java#L63

Finally you need to have the Linux kernel documentation in hand that describe how to use the /dev/i2c-* files
http://www.kernel.org/doc/Documentation ... -interface
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

ianm1981
Posts: 15
Joined: Wed Nov 30, 2011 2:18 pm

Re: I2C with Java?

Tue Sep 18, 2012 10:23 am

I would also love to get this working. I've got things running ok in python and I managed to get the rxtx libraries working on java I think but the basic listAllPorts() demo code they supply lists nothing so I can only guess <wild speculation>that the libraries cant find the Rpis hardware. </wild speculation>

If anyone could shed some light on this or show a successful implementation of i2c in java It would be really useful for me.

User avatar
xranby
Posts: 539
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: I2C with Java?

Wed Oct 03, 2012 8:46 pm

Peter "rotok" have built a working #raspi #java #linux #i2c binding using #JNA.
http://www.raspberrypi.org/phpBB3/viewt ... 73#p187073
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

pccourt
Posts: 1
Joined: Tue May 26, 2015 4:14 am

Re: I2C with Java?

Tue May 26, 2015 4:17 am

http://pi4j.com has I2C support.

Return to “Other programming languages”