Ryan Herbst

Relay Control & Input With Linux & xPL

 The Input/Output controller board is made up of a surplus FPGA board that was no longer used at my place of employment. This boards became obsolete when the design was updated with a more modern design.This board consists of a Spartan3 FPGA connected to an FT245BM USB device. This USB device appears to as a serial device on the Linux operating system. Data written to this serial device appears as 8-bit data on a FIFO like interface on the physical USB chip. Similarly 8-bit data written to a FIFO like interface on the physical USB device is available as serial reads from the serial device in the Linux operating system. This surplus FPGA board had a 16-bit output buffer and a 16-bit input buffer between the FPGA and an external connector.

I was able to make use of output buffers on this board to control a relay through an external NPN transister. I removed an external connector and added wires from the through hole connector footprint to the external relay board. The relay board is a hand made board consisting of 12 channels of relay drivers (NPN transiter) and 5V SPST relays. A common 24VAC input is attached to each of the relays which drivers an external solenoid (irrigatation control) or other 24VAC controlled device (contactors for pool pump control). For the irrigation valves at the far end of the house I connected a CAT6 cable from the FPGA board to a relay control board close to the irrigation valves. This allowed me to use smaller guage CAT6 cable instead of running larger guage cable capable of driving the solonoids on the irrigation valvues.

Hardware Diagram

 The Input/Output board is also capable of reading input signals, using these signals to trigger xPL messages or to update counters. At this time I am not using the input feature of this FPGA board. In the past I have used the counter feature along with a household power usage meter to track the eletrical usage within the house. I have not yet found a good use for the input event generation but I had planned to use this feature to detect doorbell and other events.

FPGA & Relay Board FPGA Board Relay Board Remote Relay Box

The current uses of this setup are:

Control Software:

The following diagram shows the structure of the FPGA board software “xPL_Iodevice”.

Software Diagram

The FPGA control software is structured in a similar way to my Insteon gateway software.  It is also designed around the xPL4Linux framework. XPL messages are received in the IoFgpaMessages class and converted into FPGA register read and write transactions. The IoFpgaCfg class tracks the known devices attached to the FPGA board. This list of available devices is read by this class from an XML configuration file. This file contains the address (relay index) of each device and a name. The IoFpgaOutput class tracks each device. The IoFgpaCntrl class handles the interface to the FPGA firmware.

FPGA Firmware

The following diagram shows the structure of the FPGA firmware:

Firmware Diagram

The USB interface logic converts the serial byte stream to/from the PC into register read/write commands. These register commands can be used to set output bits and poll input bits and counters. FPGA inputs can be configured as general inputs whose current state is polled with register reads. Inputs can also be configured to increment counters which are also read with register read transactions. Input state transitions can also be configured to generate event messages from the FPGA firmware to the software daemon.

The following xPL configuration variables are supported and can be updated using DCM or another xPL configuration manager:

  • logdevice = File to which debug messages should be written. “/var/log/home/iodevice.log”
  • iodevice = Device file which can be used to access the Insteon Power Link controller. “/dev/ttyUSB2”
  • cfgfile = File containing the XML device descriptions. “iodevice.xml”

Here is an example of a device configuration file:


My To-Do List:

  • Add support for input events
  • Add support for input counters
  • Add support for additional schemas (Current use of lighting.basic for outputs is not really correct)
  • Add internal watchdog to firmware. (Detect software crash & disable outputs)


I used the FPGA board for relay control because the board was available to me as a surplus board from work. Since it was free I was able to add relay control to my home automation project for very little cost. In the future I plan to replace this setup using Zigbee radios. I have been experimenting with Zigbee and found that the radios are very useful and inexpensive. It would not be very hard to add relay drivers to their outputs to replace the relay board I currently use. The advantage of using Zigbee is I could place the relays closer to their point of use. There also seems to be a larger number of products available using the Zigbee protocol. I plan on writing my own Zigbee to xPL gateway if I can not find a good one already written for Linux. I will add a Zigbee page to my website as I get further into this project.

Another alternative to my custom FPGA board would be to use a general purpose USB based relay control box. I have seen a few varieties out there.

Email me if you have any questions!



Amaroq Weather Station

temp: ()
humidity: %
wind: From the at MPH