A1332 and AS1115

I have been able to get these two items to work on my Raspberry Pi. I am making a device to sense the rotational angle of the crank on a punch press and report the angle to the operator. I have adapted the java script that I downloaded from your website and on a very basic level made it collect the position and display it. I need these items to make it work.

The issue I’m facing is as I attempt to create Methods that I’ll reuse that I do not know how to instantiate the I2C objects. Using this in main works perfectly:

	// Create I2C bus
	I2CBus Bus = I2CFactory.getInstance(I2CBus.BUS_1);
	// Get I2C device, A1332 I2C address is 0x0C(12)
	I2CDevice Idevice = Bus.getDevice(0x0C);
	// Get I2C device, AS1115 I2C address is 0x00(00)
	I2CDevice Odevice = Bus.getDevice(0x00);

If i create:
public void getAngle() {
// Get the angle from A1332

public void showAngle() {
      // Display the angle on the AS1115

inside the class I don’t know where to place this. I have tried several times and it fails to work. I do not see many examples in Java and when I search for Java I don’t see anything dealing with I2C.

Many times the best thing to do is instantiate an object in Main and then pass it to functions which can use it. So if your getAngle or showAngle functions require the I2C bus object just pass it in as an argument.

Yes that worked.

I had the biggest issue to find how the Method received the object. Then Jacob Youngblood (National Controls Devices) gave me the clue.

Call my_custom_function(Odevice); and receive it with my_custom_function(I2CDevice Odevice) {…

I had attempted to send it as a string but failed to use the I2CDevice type. I suppose it should have been obvious and now it is but you don’t know what you don’t know and I danced all around that one.

Thanks for your assistance.

No problem Steve. Please let us know if you have any other questions.