Saturday, July 16, 2011

Computer controlled, cheap and easy

This little bad-boy is a 4-relay controller that plugs into the USB of a computer. You can communicate with it over serial bus (this is actually a virtual serial communication, but that abstraction layer is someone else's problem).

That means you can putty into this machine to give it commands and ask it questions. It also means you can connect to using python. Once you're into it, you can control the mechanical relays. If you hook up some electronics to those relays you'll be able to control things in the real world with computer commands.

The controller itself was about $50 and setting it up required no software installation on my linux machine and took me about 15 minutes without any instructions. If you choose to do this, you will have my instructions:

Start python:
% python

Run this code:
>>> import serial
>>> ser = serial.Serial('/dev/ttyACM0',115200)
(If this gives you an error, go to that directory and see what's there. I found it by connecting to ever file in that directory which had been modified around when I plugged the device into the USB port)
>>> ser.isOpen()
(we're just checking it with this command)
>>> ser.write('\r\n')
(For some reason it won't respond unless you give it a command first)
(this should start getting characters back. Keep going till you get two ":" characters)
>>> ser.write('REL3.ON\r\n')
(this will lite the third relay as the machine attempts to activate it. Till you put a 9V power supply on the board, however, nothing will actually move.)