I2C with Java?
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!
Re: I2C with Java?
I think the easiest way to access I2C with Java is by first load the i2c-dev Linux kernel module
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
Code: Select all
sudo modprobe i2c-dev
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
twitter.com/xranby
Re: I2C with Java?
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.
If anyone could shed some light on this or show a successful implementation of i2c in java It would be really useful for me.
Re: I2C with Java?
Peter "rotok" have built a working #raspi #java #linux #i2c binding using #JNA.
http://www.raspberrypi.org/phpBB3/viewt ... 73#p187073
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
twitter.com/xranby
Re: I2C with Java?
http://pi4j.com has I2C support.