Raspberry PI

Raspberry Pi: KMTronic One Relay vs. Phidgets Interface Kit

the comparison between the two relay boards may be a bit unfair, because the Phidgets offering is a series of sensors, motors, relays, displays and other stuff which are all handled by the same sophisticated driver library, whereas the KMTronic relay is just a relay operated via a USB connection and a virtual COM port. Phidgets devices come with a wealth of example software supporting all programming languages you can think of. On the other side, the KMTronics use case is so simple it does not even need a lot of example code, although it can be found on their web site.

KMTronic USB One Relay

product_377-500x500A KMTronic  USB relay attached to a Raspberry Pi is really simple to use. On Raspbian the FTDI Driver is already included, so the relay just needs to be plugged into a free USB port.


will find the device:

Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 7392:7811 Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS]
Bus 001 Device 005: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC

Switching the relay on, assuming it can be  accessed as /dev/ttyUSB0 using bash:

stty -F /dev/ttyUSB0 9600
echo -e '\xff\x01\x01' > /dev/ttyUSB0 

Switching it off works accordingly:

echo -e '\xff\x01\x00' > /dev/ttyUSB0

Switching the relay with Python, using 1 for “on” and 0 for “off” in the command line:

#!/usr/bin/env python

import serial
import sys

onoff =0
if len (sys.argv) > 1:
    onoff = int(sys.argv[1])

#Oeffne Seriellen Port
port = serial.Serial('/dev/ttyUSB0',9600)

# timeout?
if not port.isOpen():
    print "cannot connect to serial port."

on = chr(0xFF) + chr (0x01) + chr (0x01)
off= chr(0xFF) + chr (0x01) + chr (0x00)

port.write(on) if onoff>0 else port.write(off)

the second byte in the string sent to the device represents the channel. For boards with more than one relay, this channel addresses the relay to be switched.

As no drivers or whatsoever need to be installed, it took me less than 30 minutes from plugging in the device until it worked reliably, controlled by a python script .

I just noticed the more recent boards allow to read out the status of the relay(s) by sending 0xFF 0x01 0x03. The board will respond with the status of the relay.

 Phidgets InterfaceKit 0/0/4

1014_2_bigThe interface kit 0/0/4 exhibits 4 relays. In order to operate a Phidgets Interface Kit we need to install a couple of drivers:

  • lsusb-1.0-0-dev
  • Download and install Phidgets libraries
  • Download and install Phodgets Python Module
  • copy Python examples to Raspberry Pi and try out.

I followed these instructions.  The same can be found at instructables.com. Although the instructions are crystal clear the whole procedure took me about 2 hours until I succeeded to discover my interface kit 0/0/4. Especially compiling the libraries took quite some time.

However, the interface kit immediately resets when the relays are activated by a command. This happens with all power supplies that I have tried. I connected a 5V/4A power supply that I have been using for years reliably with Raspberry Pis with the same result. Therefore I tried  a external active USB hub as it is recommended by Phidgets. After I found a hub that is compatible to the Raspberry Pi (Kensington Pockethub Mini USB 2.0) and that does not backpower the Raspberry, I had the same result.

It seems that the switching of the relays causes transients on the board itself that lead the board to detach and attach again, like i would unplug the USB cable and plug back in. I will give it possibly a last try with a big buffer capacitor mounted on the board. Not straight forward, actually. Or are the boards defective? I have 3 of them, all operate in the same manner.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s