Page 1 of 1

Attaching/reading sensor values from InterfaceKitPhidget

Posted: Wed Nov 06, 2013 9:48 am
by ganadiotis
Hi,

i am trying to get a very basic sensor configuration working and i'm facing issues, so would appreciate some help here.

Setup + environment:

I'm working on a windows 7 sp1 machine with 8 gigs of memory and JDK 1.7.0_25. I have purchased a PhidgetInterfaceKit 8/8/8 board (1018) and a couple of sensors (Luminance, 1143 and Temperature/Humidity, 1125).

My goal is to be able to periodically read data from the sensors and record their values in an application db. For this purpose, i have connected the sensors to the 1018 analog input ports and the 1018 itself to a USB port in my PC, using the cables that came with the devices.

Testing process + issue at hand:

Initially, i run the Phidget Control Panel to check whether everything was connected properly. Both sensors seemed to be working and recording values that correspond to environmental conditions.

Then i tried to work with the Java API to register the proper event handlers that would allow me to get these values programmatically. I am experienced in Java and the tutorials seemed straightforward. I started with the HelloWorld class and it just worked. Then i tried to extend this example and this is where things started being incomprehensible.

First of all, i noticed from the start that the 1018 was the only Phidget listed by the AttachListener. This seemed a bit strange, given that the sensors were attached to it and working properly as verified by the Control Panel, however i thought that maybe the 1143 and 1125 needed to be explicitly opened/attached, so i tried to do just that.

Omitting the 1143 for the time being, since i could not find a representing class in the API, i focused on the 1125. I tried the sequence of openAny and waitForAttachment commands, as seemed reasonable and also suggested in sample code (TemperatureExample) and elsewhere. However, execution hanged on waitForAttachment. If on the other hand i omitted the waitForAttachment statement, trying to getAmbientTemperature produced a PhidgetException 5 (Phidget not physically attached.) as would be expected.

I tried a number of things here, including numerous code permutations and experiments, running the TemperatureExample as-is, changing USB port and cable, using compliance JRE modes (al the way back to 1.2) and even eventually switching to Python, all of which produced the exact same result.

I'm pretty sure by now there is something fundamentally wrong here, just not sure at all what it could be, so any help would be greatly appreciated.

Thanks in advance

George Anadiotis

Re: Attaching/reading sensor values from InterfaceKitPhidget

Posted: Wed Nov 06, 2013 10:12 am
by mparadis
The 1143 and 1125 are not intelligent devices like the 1018 is, so there's no need to wait for them to attach as long as the InterfaceKit they're attached to is connected. The TemperatureExample you mentioned is for a different Phidget that measures temperature and plugs directly into USB without the need for an InterfaceKit. In order to access values from the 1143 and 1125, you just need to read the inputs of the 1018. In Java, it would look something like:

Code: Select all

temperature = ifk.getSensorValue(0);
humidity = ifk.getSensorValue(1);
light = ifk.getSensorValue(2);


Where "ifk" is the variable name of the attached InterfaceKit and the sensors are plugged into the first three analog inputs. Each sensor returns an integer from 0 to 1000, which can be converted to the appropriate unit of measurement by applying the formula in the user guide for that sensor.

Re: Attaching/reading sensor values from InterfaceKitPhidget

Posted: Wed Nov 06, 2013 10:47 am
by ganadiotis
Thanks for clearing this up.

In the meanwhile i continued experimenting, so i now realize that even in this way execution will hang at waitForAttachment if the Control Panel is running, as it also attaches to the 1018. If i close the Control Panel and try again, then indeed i am able to retrieve sensor values as described. Just mentioning it here as it may help somebody in the future.

Re: Attaching/reading sensor values from InterfaceKitPhidget

Posted: Wed Nov 06, 2013 11:14 am
by mparadis
Yes, you can only have one application connected to a Phidget an any given time, unless you use the Phidget Webservice to connect to them instead.