Showing posts with label hardware. Show all posts
Showing posts with label hardware. Show all posts

Thursday, September 16, 2010

Big Red Button

(I seem to have been carried away a little, but you can always skip the intro.)

If you've ever tried fiddling with some electronics on an amateurish level you'd probably thought at some point that it would be awesome if you could plug something into your computer and make it obey your evil commands. And then you'd laugh your evil mad laugh...

Or is it just me?

Anyway, it's a bugger to do that sort of thing with USB, especially if you're only learning which way of the solderer is the bit you hold and which is the bit you hold when you possibly want a day off and some attention of medical personnel. Right, anyway... So USB is a pain because to even turn a simple diode on or off you can't plug it into the USB socket or anything because it's a serial port, so it has a complicated protocol to follow before it spits out any actual information. So you'd probably need to interface with the socket via a FT232R integrated circuit or somerthing, but that's fiddly to hook up even in the best of times, and not as cheap as you'd like them to be.

But if you happen to find a computer which has a parallel port (you know, that pink one which you used to use for the printer) then you're all set, because that's not a serial port. No. It is a parallel port, as name implies. In fact you can plug some 8 diodes and things in just like that and they will receive a nice 5V signal (Hey! Good for TTLs!) when you program the computer to do so. And that's what I'd done and other people have done as well.

Ok now... so how do I control the damn port? Well, you can put together a C program that'll do that for you, or, these days, a Python program, which is fine and dandy for us weird no-life developer nerds, but is definitely not going to work when you make a device for your dad. Back in the day, on those ugly, gray Windows 95 machines we had someone's little window application though, written in Delphi (that awful thing) but is no good for a modern, up-to-date Linux user (also, I can't find the link anymore). And I couldn't really find anything worthwhile for the one true OS...

So something had to be done. Luckily I had some plane trips when I would be motivated (by way of having no alternative occupation except of staring blankly at the seat in front of me) to hack up a little GTK application to serve my own needs, scratch an itch, that sort of thing...

(End of lengthy intro.)

Long story short, I wrote it in Python and using Quickly. I wanted to give it a simple interface, so i figured, an enormous big red button would be the best way to go. True, you can't readily turn on only one bit of the port, but you can't have everything, and this way it won't confuse the people who might not be in the habit of sitting up late at night in the light of a computer screen and wondering if there's a 24/7 pizza place anywhere within walking distance.

Anyway, take a look at this here screenshot and tell me it's not at least amusing...


Feature number two was the ability to turn it on with a delay. So, say you have a device that you turn on, but you want it to turn on in an hour? Right-clickety on the button, set up the timer and you're good to go.

And finally, you can set it up so that it to turn on or off particular pins when you press the button, so you can for instance keep one device turned on in the on position and turn on two other ones, but turn the first one off in the off position.

It can also run with or without GUI, which you can find out about by running it as a script as:
bigredbutton -h

I'm not posting the code here, because it's on the long side, but it is available at GitHub as bigredbutton/ and, as previously stated, at https://launchpad.net/~konrad-siek/+archive/ppa.

Oh, and I'm sure it's all buggy as all hell, 'cuz overtime I keep forgetting which bits I tested and fixed and which worked already. But it's on launchpad, so I'm sure I can fix them as they appear. Hell, maybe I'll even add a feature or two in the fullness of time.

How to install (on Ubuntu): You can...
  1. Open the Ubuntu Software Center, select Edit -> Software Sources...
  2. In the Software Sources dialog select the tab Other Software
  3. There, select add and type in the apt line for the package archive (viz. ppa:konrad-siek/ppa);
  4. Find the program in Get software, in a section like ppa that just appeared.
Another alternative is to do it the gritty way and create a list for apt. That you can do by creating a file in /etc/apt/sources.list.d/ and inside it type in deb http://ppa.launchpad.net/konrad-siek/ppa/ubuntu lucid main. You substitute lucid for whatever version of Ubuntu you happen to be running. Then you can install the program via whatever package management tool you want, e.g. apt:
sudo apt-get update && sudo apt-get install bigredbutton
Done.

Sunday, March 28, 2010

The TDA7056 amplifier

The TDA7056 is this integrated circuit that basically provides you with an entire amplifier. A colleague of mine has pointed me in its direction once, saying that it's a good quality amplifier and that it's almost complete. And I always wanted to give it a go. Being the klotz that I am with electronics this took a lot of time and effort.

The datasheet for the TDA7056 actually shows how to apply the integrated circuit. I also found some other application somewhere else (I forgot where though) and modified the original application with a few little details. I bought the parts and a project box and started working on this stuff.


The Vcc can be anywhere between 3V and 12V, according to the datasheet - I used 9V, 5V, and 3V, and felt little meaningful difference in the output; I finally settled for two 1.5V AAA batteries because I had the box for them at hand, and I have a lot of those batteries. I also added an on-off switch that completely cuts off the Vcc and the ground, but did not include it in the schematic, because it's a bit crowded as it is.

... that was actually in the summer. I failed miserably. First, I broke off two legs of my IC and decided to get a new one. Then, I worked on it all day and when I was done it didn't work, and I had completely no idea why. So I took a couple of weeks away from the project. I returned to it later on, only to measure some stuff, change some wires, get really frustrated and quit for a little longer. This repeated several times. Also with each time I inadvertently messed up the box a little, e.g. by sticking a soldering iron to the side by accident, or by spilling some glue on it.

Alas, this week I sat down, took everything apart, then reworked the schematics and assembled the thing again with some different parts. I tried to get every little element neatly into the box, painstakingly checking each connection to see that the solder was done ok. This worked mostly. And at the end I got tired and confused and a lot of little problems ensued with connections. At one point the circuit picked up radio even. And I screwed up the box again too.

Still, I managed. Here are some pictures:


My plans for using it include... nothing very much. This was a point of honour rather than a practical venture.

Sunday, March 21, 2010

The turner off-er

Unconventionally, this is an entry about a hardware hack I perpetrated, and not a script as such. There is a script at the end, but it's trivial.

For a long, long time I wanted to make this device. It started such a long time ago that I don't even remember what I wanted to use it for... The idea is that you have some sort of an appliance that you plug into the wall, like a refrigerator or a lamp or something, and you want to control when it is turned off and on from your computer.

I approached the subject several times now. Each of the previous times my lousy electronic and electronics-related skills had caused me either (a) to get too frustrated too continue at the planning stage, (b) not to be able to obtain the proper components, or (c) to almost annihilate the world due to a short-circuit. And each time I put it off until I got more drive.

And finally, this week (mostly due to the confidence that playing with the Arduino has given me) I've done it! It works, and I am not unhappy.

Þiſ herewiþ iſ þe chronicle of my victory.

Bright was the morning and high ovr hearts when I proceeded (again) to think about the problem of turning things on and off with my computer. I started out by searching for relevant information (because I know there are schematics available out there) and found somebody's blog post about how this can be done with an Arduino. This was an excellent point to start, because I own an Arduino, and those are easier to come to grips with than hooking up a bunch of wires to the back of the computer. And it's basically a ready solution.

Except that it isn't for me. That there is done for 120V AC and I live in a place where we have 220V AC in the wall, so I had to redesign.

So I had to find out about relays. In a nutshell these are like switches which use electromagnetic magic to turn a switch on and off. That's all I need to know. I require the relay to be turned on when a 5V DC signal appears on one of its magic electromagnetic coils, and allows 220V AC to pass through it. A longer while spent searching and a couple of questions this guy one I know allowed me to figure out that the relay I need is a JQX115F 005. A further 30 minutes with a datasheet helped me figure out that I want something like a JQX115F 005/2ZS2... which they didn't have at the store, so I finally acquired the JQX115F 005/2ZS4 instead.

Here's a sketch of what I came up with:


I used my breadboard to put the thing together and test it out, first with my Arduino.


When that worked, I soldered all the bits together and put them in a socket-like box, and then tested it out. It stopped working so well, because I soldered a few elements the wrong way (specifically, the diode was upside down)... and then I tried again and it worked fine again.


The thing left to do now was to interface with a computer. Happily, I several of those things. Having visited electronics stores, I also obtained the necessary parts to make a cable connection between the computer and the turner off-er.

There is a snag, however. I decided to use the parallel port to control the device. My main reason behind this is that using any (e.g., USB) serial port would require an additional chip between the computer and the device that would translate the values from the serial protocol to some usable form. This is expensive to put together. So I stuck to the parallel port, since I have plenty of old computers that sport it. The snag is though, that the parallel port is not designed to provide power, and may fail to give enough current to work the relay (it's not powerful enough to turn the switch on), which would not have been a problem with the USB.

I decided to do a nasty hack then, and use the USB to get power and simultaneously use the printer port to control the device. This is not pretty, I know, but it's easier, and it's enough for the moment. I'll probably try to use only USB in the future, if I ever get round to redesigning the device.

So, the cable has two endings that go into the computer. In the USB cable I tap into the Vcc 5V (usually red) and the Ground (usually black). In the parallel port, I tap into the Ground pin and the first input pin - Data0 (see image below). Then I connect ground from the USB cable and the ground the parallel port together.


As for the device, the Vcc goes into the Vcc of the turner off-er (red socket), the grounds go into the Ground of the turner off-er (black socket), and the Data0 goes into the Input of the turner off-er (yellow socket). And all is well. Although the actual cable I made looks kinda manky.


Last thing was a computer program to control the thing. I decided to go with the pyParallel library, so the script to turn the thing on or off would be something like:

 
1 #!/usr/bin/python
2 from parallel import Parallel
3 from sys import argv
4
5 def usage():
6 print "Usage: %s on|off" % argv[0]
7
8 if len(argv) != 2:
9 usage()
10 elif not argv[1] in ['on', 'off']:
11 usage()
12 else:
13 port = Parallel()
14 data = 1 if argv[1] == 'on' else 0
15 port.setData(data)


And I had to remove lp and install the ppdev kernel module on my Debian Sid box where I was testing it:

1 rmmod lp
2 modprobe ppdev

And that's it.

Update (April 19th): I later made another unit. It came out slightly neater (and much quicker) now that I knew exactly what I was doing. Thus, I give you, Mk. II:

And with the Mk. II cable: