Sunday, December 22, 2013

TEMPer USB Thermometer on Raspberry Pi

TEMPer USB Thermometer
For a fairly cheap solution, nothing quite compares in price and convenience to the TEMPer USB Thermometer.  Due to their low price point, I have used several of these as secondary temperature check points in a server rack before.  They can be picked up for about $15 to $22 on Amazon, or cheaper on eBay.  The TEMPer is not as accurate, or reliable, as something like the Temperature@lert, which runs for about $130, but for general temperature estimation they work sufficient for my needs.

I found the easiest way to use the TEMPer with Python is to install the pyusb library and a simple temper Python class written by Bill Mania.  There were a few small issues that I ran into with the original code, so I forked the code on Github and posted the changes as the PyTEMPer repo seen below.

First let's make sure Linux can see your TEMPer device. We are looking for devices that have the VendorID of 1130 and DeviceID of 660c.
# lsusb | grep 1130:660c
Bus 004 Device 002: ID 1130:660c Tenx Technology, Inc. Foot Pedal/Thermometer

If your device is not found, the PyTEMPer script will not work with your device.

PyTEMPer Installation:
# cd /opt

# ## forked from http://www.manialabs.us/downloads/Temper.py
# sudo git clone https://github.com/kiloforce/PyTEMPer
# cd PyTEMPer

# ## Get PyUSB (if you do not already have installed)
# sudo git clone https://github.com/walac/pyusb
# sudo ln -s pyusb/usb usb

# ## Get sample temperature to verify code is setup correctly
# sudo python temper.py
0:2, 22.56 Celsius / 72.61 Fahrenheit

Now that we have the PyTEMPer class working, we can build the following Python script to get the current temperature repeatedly:
import sys
import time

sys.path.append('/opt/PyTEMPer')
import temper
temp = temper.Temper()

if not temp.devices:
    print "Error: not TEMPer devices found!"
    sys.exit(1)
device = temp.devices[0]

while True:
    # get temperature
    tempc = temp.getTemperature(device)
    print "Celsius: " + str(tempc)

    # only check temperatures every 10 seconds
    time.sleep(10)

In the final lala-pi TEMPer code, I included code to demonize the process, syslog for logging, and ZeroMQ messaging.  If you are interested in the full lala-pi source code (still a work in progress), this can be found in the GitHub lala-pi repo on Bitbucket.
# git clone https://github.com/oeey/lala-pi

More to come...   see label: lala-pi

9 comments:

  1. Hi! Any idea on the accuracy of this device?
    Thanks

    ReplyDelete
  2. RE: "Any idea on the accuracy of this device?"

    Not too accurate. Good enough to tell that temperatures are rising and falling. From what I have read, under ideal conditions it appears that it can detect changes in temperature to about .5°C (~1°F). The default temperature output also needs so calibration (shifting to correct temperature).

    ReplyDelete
  3. Hi, really new with my raspberry pi and to coding in general. I've followed the instructions to a T, but im not getting a sample temp. I looked in the /opt file and everythings there including the python temper.py, but when i run the sudo python temper.py string nothing happens. And if i try and run it straight from the terminal with no directions it says no such file or directory. Thanks for your time

    ReplyDelete
  4. Please check to see if your Raspberry Pi is even seeing the TEMPer device:

    Example:
    ---
    # lsusb | grep 1130:660c
    Bus 004 Device 002: ID 1130:660c Tenx Technology, Inc. Foot Pedal/Thermometer
    ---

    ReplyDelete
  5. Thanks for this really helpful post! Finally got my Temper USB (Tenx type) to work :)

    ReplyDelete
  6. Thanks for the tip, my Tenx TEMPer is also working well.

    ReplyDelete
  7. Just came across this script while looking for an Ubuntu script for my TEMPer.
    The company that makes it provide a nice script for Windows, buy I wish to use the device on my ASUS-eee now running Ubuntu 1710.
    Anyhow-
    when I did a lsusb, the temper device showed up as
    0c45:7401 Microdia TEMPER device.
    Just in case anyone wishes to modify your script....

    - Tony Q. King, tech aqk-dot-ca

    ReplyDelete
  8. ADDENDUM-
    Please see LINUX-JOURNAL
    for a Python script for this newer TEMPer device that I mentioned above

    - Tony, tech (at) aqk-dot-ca

    ReplyDelete
  9. Does not work. Please tell us pre-requisites.......

    ReplyDelete

Please be respectful.