I have had a couple of USB temperature sensors in my collections for some time now. They are the PCsensor Temper units from Tenx Technology, Inc.. The USB Vendor ID is 1130 and the Product ID is 660C. I wanted to use them in my Linux environment, as part of my home monitoring system. I also wanted to interact with them using Python, since that is my preferred language for most of my monitoring and robotics projects. I didn’t look very hard but didn’t find anything that someone else had already written in Python, which worked out well because I wanted to exercise my new-found PyUSB skills. I couldn’t find a datasheet for the devices but I did find a C version on Robert Kavaler’s ‘blog.
My Python class to read the temperature from the TEMPer unit is here.
Hi, I have a Temper2 device and want to use Python to access the readings from it, your module looks like just the thing.
I have tried using it but am having some issues. The device and vendor ID on my device appear to be different to yours (vendor ID = 0x0c45, device ID is 0x7401, this is what the Virtual box virtual machine I am running in is reporting the device as anyway), and is what is reported if I do lsusb. Modifying the device and vendor ID in the script to match I find the device, however I now get the error
libusb couldn’t open USB device /dev/bus/usb/002/009: Permission denied.
libusb requires write access to USB device nodes.
Unable to setup the device
libusb couldn’t open USB device /dev/bus/usb/002/009: Permission denied.
libusb requires write access to USB device nodes.
Traceback (most recent call last):
File “temper.py”, line 140, in
print ‘%5.1f %s’ % (temper.getTemperature(), temper.getUnits())
File “temper.py”, line 118, in getTemperature
0
File “/usr/local/lib/python2.7/dist-packages/usb/core.py”, line 686, in ctrl_transfer
self._ctx.managed_open()
File “/usr/local/lib/python2.7/dist-packages/usb/core.py”, line 70, in managed_open
self.handle = self.backend.open_device(self.dev)
File “/usr/local/lib/python2.7/dist-packages/usb/backend/libusb10.py”, line 494, in open_device
_check(_lib.libusb_open(dev.devid, byref(handle)))
File “/usr/local/lib/python2.7/dist-packages/usb/backend/libusb10.py”, line 403, in _check
raise USBError(_str_error[ret], ret, _libusb_errno[ret])
usb.core.USBError: [Errno 13] Access denied (insufficient permissions)
Any thoughts? I am sure I can find a way to change the permissions as needed, just a little concerned in case this indicates I am doing something else wrong…
Paul,
I have only tested my code with the one, specific Vendor ID and Product ID. It may not work at all with your version of the TEMPer.
With that said, the first line in your output explains your current trouble. In order for the program to work, the user running the program must have permission to access the USB device. Did you make appropriate entries in /etc/udev/rules.d for your device? Is the user running the program a member of the appropriate group?
As a test, my udev rules file looks like:
SUBSYSTEMS=="usb", ACTION=="add", ATTRS{idVendor}=="1130", ATTRS{idProduct}=="660c", MODE="666"
You’ll need to replace the 1130 and 660c with your values.
After you add this file as /etc/udev/rules.d/99-tempsensor.rules, execute udevadm control –reload-rules as root and try the program again.
Good luck.
—
Bill
Hi,
I appreciate that what works on your device may not work on mine.
I will try changing the permissions as you describe and let you know how it goes 🙂
If there are still issues after changing the permissions then I will try some of the other code/libraries floating around on the web, (I see some C code and Perl as well) one of them is bound to work!
If I find one that works then I will try and see what they are doing differently and if possible add the support to your module, as at the end of the day what I want is a python module.
If you are interested the project I am planning on using this in
code.google.com/p/pi-sous-vide/
Cheers,
Paul
Paul,
Your project is interesting. I’ve started brewing kombucha recently and found that I don’t have a spot in my home with the optimal, stable temperature. I may have to add some active temperature control, similar to what you’re doing.
—
Bill
With the changed permissions I get a fairly solid lockup 🙂 this may be in Virtual Box’s USB virtualisation, as it is not just the Virtual machine that locks up but also the Virtual machine manager. I will have a go on a real linux machine and if that chokes I will try some other applications.
For your brewing stuff I would first consider a fish tank heater. A quick search suggests that your ideal brewing temperature is 26-30 degrees Celsius which is pretty close to the temperature required in a tropical fish tank. My project needs much higher temperatures than a typical fish heater would produce, which is why I am doing the DIY route (well that and the fun of hacking something together).
Paul
Hi,
I wanna use python code instead of c (the pcsensor works, but I wanna integrate it into OMD). So I’m glad to found your code. It looks to be not overloaded, but I have problems with pyUSB:
import usb.core
ImportError: No module named core
I wanna run the script at Ubuntu 12.04 with installed python-usb. Some hinds to get it running?
Dennis,
It appears that either you didn’t correctly install the PyUSB modules or you installed the wrong file.
Did you retrieve the file from http://sourceforge.net/projects/pyusb/?
How did you install it and as which user?
Hi,
I took aptitude/apt-get.
dennis@host:~$ sudo aptitude search python | egrep ^i | grep usb
i python-usb – USB interface for Python
Aptitude shows, that python-usb’s version is 0.4.3-1 . The Description of the package is: “USB interface for Python
PyUSB is a native Python module written in C (meanwhile, because the next major version will use ctypes), that provides USB access for it.
Homepage: http://sourceforge.net/apps/trac/pyusb”
I didn’t install python modules from source so far, the ubuntu packages meet my requirements. Till now?
Hi again,
just my two cents: It doesn’t work with pyusb 0.4.3 . I cloned the git repo from sf (1.0.0alpha1 I think) and previous version 1.0.0alpha0. I changed the vendor/product as Bill before, but now:
dennis@host:~$ ./Temper.py
Traceback (most recent call last):
File “./Temper.py”, line 139, in
print ‘%5.1f %s’ % (temper.getTemperature(), temper.getUnits())
File “./Temper.py”, line 117, in getTemperature
0
File “/usr/local/lib/python2.7/dist-packages/usb/core.py”, line 702, in ctrl_transfer
self.__get_timeout(timeout)
File “/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py”, line 596, in ctrl_transfer
timeout))
File “/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py”, line 403, in _check
raise USBError(_str_error[ret], ret, _libusb_errno[ret])
usb.core.USBError: [Errno 32] Pipe error
Same as root. It is now within our grasp. Any last idea?
Hi, anyone else got the temper2 working on ubuntu 12.04? Cheers..