NOTE: This article is 3 years or older so its information may no longer be relevant. Read on at your own discretion! Comments for this article have automatically been locked, refer to the FAQ
for more details.
The TEMPer1 USB Thermometer finally arrived a few days ago, so I started to play around with it. It comes with a CD with software on it, which I promptly disregarded. After searching around the net, I could not find anyone that's written Java code to interface with the device, but I did find other useful information like javahidapi
and this blog post: Controlling your TEMPer on Mac OS X
. Now my Objective-C is quite bad, but I was able to follow the code to extract the required information to read the temperature from the TEMPer1.
I've downloaded the javahidapi and the source code. Running the sample program to list the connected devices gives me this:
From the information above I was able to extract the following constants into the Java code:
The main method of my Java class load the HID library from the classpath and call the readDevice() method.
The two methods below are ported from the code mentioned in the blog entry above. These are for converting the raw temperature reading to Celsius and another method to convert Celsius to Fahrenheit and Kelvin, depending on the parameters.
The method below does the actual reading of the device values. To read the device, a command is sent to the device first (by writing to the device), then the response is read.
The code above only retrieves the temperature reading. The TEMPer1 can also report humidity readings, this is something I've not looked into yet. Running this code produces the following output:
As described in the blog entry I've referenced at the top, there are two HID devices exposed, these are returned in a non-deterministic order. My code doesn't make any attempt to grab the correct device, so sometimes if the 'keyboard' device is grabbed, the code locks up. To fix this, all that's requires is to enumerate all the devices and get the correct one based on the usage_page, but it's not something I've done.
Hope you found this post useful...
...so please read on! I love writing articles that provide beneficial information,
tips and examples to my readers. All information on my blog is provided free of
charge and I encourage you to share it as you wish. There is a small favour I ask in return however -
engage in comments below, provide feedback, and if you see mistakes let me know.
If you want to show additional support and help me pay for web hosting and
domain name registration,
donations, no matter how small, are always welcome!
Use of any information contained in this blog post/article is subject to this disclaimer
Other posts you may like...