In this application note is shown how to drive 4 lamps by a PC with an Ethernet connection. It is built with 4 relays, driven by GPIO ports of SR01E12. Four ports of SR01E12 are configured to output. Each one drives an indication LED and transistor that open and close a relay. On demo board exist 3,3V regulator for the Ethernet bridge and 5V regulator for the relays.
Just adding relays, the board can be extended to drive up to 12 outputs. Outputs can be extended to many more by using shift registers like 74HC595.
Board require 6,5-9V 400mA power supply to POWER connector. It can be provided by wall power adapter. Each relay has normally open and normally closed output. Relays used in design can handle up to 250V 5A load.
The user interface is built with QT framework. It is split in 2 dialogs, first is to obtain all network interfaces, search for SR01E12 boards and select one of them. Second dialog has 4 buttons to toggle the relays.
A very simple command line tool to drive the relays. Whole source code is:
#include <stdio.h> #include <string.h> #include <stdlib.h> #include "libschremote.h" #define FIRST_RELAY_PIN 8 int main(int argc, char *argv[]) { SR_HANDLE srh; int relay; if (argc < 3) { printf("Usage SrRelay <ip> <relay 1-4> <on|off>"); return 0; } srh = sr_open_eth(argv[1]); if (!srh) { printf("Failed to allocate a handle\n"); return 0; } relay = atoi(argv[2]); if (relay < 1 || relay > 4) { printf("Invalid relay number\n"); return 0; } if (stricmp(argv[3], "on") == 0) { printf("Relay %d ON: ", relay); if (!sr_pin_setup(srh, FIRST_RELAY_PIN + relay-1, sr_pt_dout_high)) printf("FAIL\n"); else printf("OK\n"); } else //assume off { printf("Relay %d OFF: ", relay); if (!sr_pin_setup(srh, FIRST_RELAY_PIN + relay-1, sr_pt_dout_low)) printf("FAIL\n"); else printf("OK\n"); } }
To compile, is needed just to add the libschremote library to the project. For example in VC is done like: "cl SrRelay.cpp /link libschremote.lib". Sample usage of executable is: "SrRelay 192.168.1.119 1 on".
SrRelay QT GUI Exec | QT GUI version - Executable file with all needed libraries |
SrRelay QT GUI Src | QT GUI version - Source code (requires QT framework) |
SrRelay Cmd Exec | Command Line version - Executable file with all needed libraries |
SrRelay Cmd Src | Command Line version - Source code |
| Full Size |
* On grayed area of evaluation board are placed components not related to the project.