Friday, June 29, 2012

Road Trip Day 2 - March Field Air Museum

As our big summer trip this year, my dad and I decided to take a six day road trip across southern California and Arizona to hit a number of museums that have been on our respective bucket lists for some time now.
 After spending most of the day at the Orange Empire Railway Museum, we decided to break up our drive to Blythe by stopped at the March Field Air Museum.
We aren't particularly knowledgeable about aircraft, so we came to this much more reliant on the museum's interpretation than we're used to.  Luckily, I would say that March Field held their own in that regard; every plane had an interesting engraved sign telling you what it is and why it was important.  Many of the signs suffered from needing a new wipe-down with India ink, but when that's your largest issue with a museum, you know they're doing some things right.
 And this place has plenty of planes for you to look at.  Row after row of planes was impressive, but we felt a little out of our league.  A powerful lesson came from this; when interpreting historical equipment to the public, it is really easy to forget how mundane the differences between a B-52D and a B-52G are.  Many museums quickly forget this nuance of nuances.

One thing that had been completely off my radar that took me by surprise was the D-21 reconnaissance drone.  The SR-71 is a very recognizable aircraft, but I had completely forgotten about it's little sister who never quite worked out.  It's interesting to look at this aircraft now, and compare its capabilities to that of your typical amateur, who can now for a few hundred dollars build their own drone.  No one has home-built a Mach-3 drone yet, but still, that and range are about the only major features lacking from many of the drones you see now.  Makes you wonder how much farther ahead the military is now than we realize.
There were some interpretive exhibits in addition to the giant field of air planes, but the field certainly seemed to be what you should be most interested in.  I found it most interesting to spend time getting a good sense of the physical size of each plane; surprisingly, various models were either larger or smaller than I had expected once I saw them in person, instead of all in one direction or the other.

Like most museums, I got the feeling that with a good docent or passionate friend, this museum could be ten times as interesting.  As it was, we found it a mildly interesting, but uneventful, way to take an hour leg-stretch break on our way to Arizona.

Wednesday, June 27, 2012

Road Trip Day 2 - Orange Empire Railway Museum

As our big summer trip this year, my dad and I decided to take a six day road trip across southern California and Arizona to hit a number of museums that have been on our respective bucket lists for some time now.
The first stop of our trip was the Orange Empire Railway Museum, in Perris, CA, near LA.  We haven't been here in a very long time, so although it wasn't our first visit, 20 years made us effectively first time visitors.  Both Paul and I are very active at the Western Pacific Railroad Museum, so it was a very interesting experience to spend the day comparing and contrasting with a museum of very much the same caliber of ours.
We have always joked that we've been trying to run a real mickey mouse railroad, but Orange seems to have us beat in that regard.  These ticket booths seemed oddly familiar, and it wasn't until the end of the day when we finally placed it; these were originally from Disney Land.
OERM has several storage barns which they keep the best of their collection in. 
 This gives them a huge advantage in their preservation of equipment.  The paint on many of their pieces of equipment, such as this E unit, are simply immaculate.
There were several interesting interpretive exhibits squirreled throughout the museum, so you really want to just wander around the whole place to get the full experience.
 We did find some part's of the OERM railway particularly interesting.  They have a switchable cross-over, which doesn't currently have switch stands installed, but is a good example of a piece of rail you rarely see.
Much of their right of way is also dual-gauge, which is important since much of the passenger equipment in their collection isn't the typical American 4'8.5".  We pity trying to keep not one, but two, tracks in gauge.

Since they are a trolley museum, 600VDC overhead power is needed to run their equipment.  The museum typically runs using a solid-state inverter, but they also have this second motor generator substation.
 OERM has an impressive HO model layout, complete with scale centenary for their model trolleys.  We spent quite a bit of time appreciating this display, although admittedly not because we have any interest in modeling, but because the building was air conditioned.
The OERM goes on for much farther than you first expect.  We almost missed an entire half of the grounds open to the public, and the chance to appreciate this narrow-gauge manual turn-table.
Hands-down, the most impressive part of the entire museum was their block-signal exhibit.  They have several different styles of block signals installed, with weather-proof buttons and interpretive signs, to allow you to activate each one.  These types of exhibits are surprisingly difficult to build and maintain, so it was not hard to appreciate how impressive this was.

Video:


Overall, we had a good experience spending the day experiencing a new train museum.  It was not the best train museum we have ever attended, but it was neither the worst, and "best" is a hard thing to qualify when each train museum does different things really well.

Monday, June 25, 2012

ARRL Field Day 2012

 This weekend was the national ARRL Field Day competition, where amateur radio operators go out and spend the weekend participating in an interesting mix of public relations, disaster-preparedness, and contesting.  I have spent the last several years of this event with WVARA, who are a ham radio club based out of San Jose.  Every year, we set up on the top of Mora Hill in Los Altos, and spend the 24 hours of the event trying to rack up as many contest points and public foot traffic as we can.
 Since we operate from the side of a hill, the need for portable towers is paramount.  There aren't particularly very many trees on this hill, and they aren't in very useful places.
At the base of this tower, you can also see the set of solar panels and batteries used to power two of our ten stations.  Since we operated the entire weekend on batteries and solar power and never transmitted more than 5W radio power, we enjoy a 5x points multiplier when it's all said and done.
Since we over-look the Silicon Valley, one of our ten stations is focused on VHF/UHF, which tend to be limited to line-of-sight range.  The other three towers hold antennas for frequencies ranging from 3MHz to 30MHz, which even at just 5W lets us make contacts with people all over the United States.
Each station then sets up it's own tent (except the CW guys; we cram them all in one tent because the rest of us don't like them that much /kidding).  Since the contest spans a 24 hour window, it is to our advantage to keep all of these stations running throughout the night.  Most people aren't such fans of spending the entire night out on the side of a hill, so the fact that I'm stupid enough to enjoy that makes me well liked at these events.

Video of me operating PSK31 digital radio:


Video of me operating 80m SSB voice in early morning. I am very tired, which is why I kept misunderstanding the other station:


Saturday, June 23, 2012

We've Moved!

After six years, and nearly 450 blog posts, I've finally broken down and paid real cash money for the domain TheLifeofKenneth.com.  This blog is now hosted at blog.TheLifeofKenneth.com; lucky for you, kennethfinnegan.blogspot.com now redirects to that, and the RSS feed is still exactly the same, so when I tell you to update your bookmarks, it's an entirely gratuitous request!

I have not yet bought (or built) hosting for the root domain, so having the blog.* subdomain is important.  I'm still weighing my options for hosting, so any recommendations, coupon codes, or referral links in the comments will be considered.  I'm looking for something low-cost but flexible enough for me to develop and run my own CGI and daemon projects on.

Like always, a huge thanks to all of you, my readers, for finding my stuff interesting enough to keep coming back.  It's your comments and page views that continue to reassure me that this is worth while, and my Google and Amazon advertising revenue funds the lion's share of my projects that you see on here.

Monday, June 11, 2012

Minimalist C SMTP Mail Server

For one of my projects, I thought it would be really useful for my home file server to be able to receive emails from public email addresses.  This way I would be able to send emails from any contemporary email address to some magic "something@kwf.dyndns.org" email address, and have it be received on my server.  This is different than how most people are used to interacting with their email, because most people expect to have something like example@gmail.com, and then expect Google to deal with keeping a server on all the time to handle incoming mail (via SMTP), so that the user only needs to use a mail agent (such as Outlook or Gmail's web interface) to interact with email when they feel like it.

The problem is that, while digging through all of the documentation for Postfix and Sendmail, which are the programs one would typically use to set up these email backends, is that they do way more than I need and are likewise much more complicated than I need (as they should be - email is a hard thing).  My project really only needs the most basic of mail processing; receive an email, figure out which account it is addressed to, and extract the subject line and actual body of the email.  What I plan on doing with it once I have these things becomes quite a bit easier, so I really only want an email server which can handle the network exchange and then intelligently punt received emails to different programs to do with as they please.

Many moons ago, I happened upon the very interesting Mailinator blog. Mailinator is a rather useful service providing you with disposable email addresses, but what I most enjoy about it is Paul's very interesting technical articles on the trials of writing your own high-performance custom-application mail server.  In one of his early articles, he really impressed on the fact that SMTP (Simple Mail Transfer Protocol) is actually a really simple protocol, so I figured that if I think Postfix is too complicated for what I need, why don't I just write my very own mail server from scratch?

SMTP, like the vast majority of protocols used throughout the Internet, has been freely documented in a series of documents called RFCs, or "Request for Comments."  Granted, just because something exists as an RFC does not mean that it is actually used, but it's a good place to start looking for how the Internet works.  The basics of SMTP happen to be documented in RFC821, which is a somewhat intimidating 67 pages long.  It is a running joke that actually trying to read RFCs is a nightmare, and the jokes are mostly correct; reading 67 pages on the gripping subject of how mail is transferred between mail servers is simply not an exciting exercise.  On the other hand, once I managed to get 400 lines of C to handle enough of SMTP to receive mail and print it on the screen, that was pretty cool.



How SMTP Works

 SMTP really is a very simple protocol.  Given an email that needs to be delivered to another server, your mail server connects to port 25 on the remote server, and then trades four letter verbs for three digit return codes.  For example, when an exchange first starts, the connecting server sends a "HELO" verb, and the remote server typically responds with a "250" code indicating the completion of the verb.  Once a connection is established, moving emails is nothing more than a long series of these back and forth until there's no more work to be done.

The Wikipedia article and the RFC both give simple exchange examples, and I will supplement those with one of my own, captured with my very own SMTP server:





The Source Code

Now let us be very clear here; I am not posting this 400 line SMTP server in the hopes that you find it useful as a mail server.  I very much hope that I do not ever actually see a copy of this running in the wild, and here is why: this is not a good SMTP server.

It just isn't.  It is a rather neat little toy to play with, and I think it is a very educational example of the basis for how SMTP works, Posix threads, and network programming.  That is all I think it is good for, at this point.  It isn't done yet, because I have built in almost no safe-guards with respect to remote servers doing anything naughty or unexpected.  There is no limits on bandwidth usage, RAM usage, number of connections opened at once, nothing.  That being said, all of those things would make this quite a bit longer, and muddle the basics of exactly how it works.  I thought you may find this academic example interesting, but dear God don't treat it as anything except an academic example.

That all being said, here is 409 lines of C which can manage to receive basic SMTP transfers from other mail hosts. It does crap out on emails with attachments for some reason that I don't quite understand, but this project is not even close to finished, but simply at a good point for me to take pause for your benefit.  Source code:


Intelligent Fan Controller

During the Maker Faire Salvage Crawl last month, I picked up a kiosk-size industrial computer for $20.  All well and good, except that the BIOS in it made no effort to control the fan speeds, and instead simply ran all three cooling fans at full blast.  This was unpleasantly loud, so I decided to simply build my own fan controller, using an MSP430, so I could easily monitor the system temperature and adjust the fan speeds accordingly.

Video:

As a bonus, while waiting for the computer to heat up, I give you a basic intro to the concept of a PID controller.

The hardware isn't too involved; an MSP430G2452 takes temperature readings from the CPU via a 10k thermistor, then uses this to set the fan speeds for the three fans. 

Computer fans typically come in two varieties; three pin and four pin.
  • Three pin fans have, in order, a ground, a 12V supply, and a tachometer pin.  By applying a pull-up resistor to the tach pin, the fan outputs two pulses per rotation, so the MSP430 can count these pulses and know how fast each fan is spinning.  To adjust the speed of the fan, the MSP430 pulse-width-modulates the 12V pin at 32Hz.
  • Four pin fans are backwards compatible with three pin fans, with the addition of a fourth pin for speed control.  Instead of requiring the pair of transistors to switch the 12V line as in the case of the three pin fans, you can instead simply apply the 3.3V PWM signal to this fourth pin and the fan will use it to modulate its power itself.
 This computer happened to come with two three-pin fans and a single four-pin fan, which is why I only needed two NPN-PNP transistor pairs, to switch the two three-pin fans.  The four-pin fan is controlled directly from the MSP430 digital output.
I have moved almost entirely to using 0603 surface mount passives on my prototype projects; fitting circuits on perf board is much easier when you can fit passives like resistors or capacitors between any two adjacent pins.
In the schematic, I forgot the input 10μF caps on the 12V and 5V lines.  The entire circuit board is powered using the standard 0.1" floppy disc power connector (12V (yellow), GND, GND, 5V (red)), since those tend to be numerous and under-utilized inside desktop computers.

One thing to appreciate when reading my code is that I have very deliberately left the control code weak.  It is currently a purely integral controller, which has many disadvantages which can be improved via switching to a PI controller and implementing integral spool-up prevention.  I'm considering revisiting this project with another hardware revision and some controller algorithm refinements, but alas the hazard of having this one "mostly-working" means that may take a while... I'll leave programming a faster temperature control loop as an exercise for the reader.

Source code:

Sunday, June 10, 2012

TwitterMatrixTicker Post-Op

A week and a half ago, I posted about my TwitterMatrixTweeter, consisting of a BeagleBone and a dot matrix printer watching for tweets mentioning my Twitter username.  It got picked up by several large blogs, and made for a rather entertaining week as tweets spewed out of my printer.

Special thanks go out to the commenters Joshua for managing to find the NP-10 user guide (part 1, part 2), and 0x6D64 for porting the code to OSX.  Finding the user's guide was particularly useful since it gave me the "ESC - i - 1" command sequence to put the printer in "immediate" mode, where it would automatically move the paper up out of the ribbon between tweets to make it easier to read.  It also gives me all the information I need to put the printer in bitmap graphics mode, so the printing possibilities are now essentially endless once I write the drivers for it.  Thanks again to Joshua for the find.
The final yield for a week's worth of tweets was just a few lines over three pages.  One thing that became abundantly clear by the end of the week was that, even though the print was still legible, the printer's ribbon really is in sad shape.  I have found some mentions that you can reink these ribbons using stamp pad reink kits, but I decided to opt for trying to find a NOS replacement ribbon for the short term, and save the old ribbon to experiment with in the future.
Of course, finding replacement ribbons for dot matrix printers is a little challenging, and finding a replacement specifically for the NP-10 is fairly impossible.  Luckily, these ribbon packs were originally designed to have just the ribbons replaced a couple times between entire cartridge replacements, so I really just needed to find any cloth ink ribbon that is 0.5" wide and ideally has the same single twist as the NP-10's ribbon (so that when the ribbon gets recycled through the cartridge, it turns over and the next pass uses the other side of the ribbon).  After an evening trawling eBay, I managed to find a reasonable deal on an FX80 cartridge, which looked promising with respect to its general dimensions.  If I had been lucky, these would have been a super standard size, but alas, as you can see, close but not quite.  The mechanisms in them are indistinguishable, so on the bright side I have a spare set of the stuffing gear now...
I think the internals of these cartridges are totally awesome.  There is something like 30 yards of ribbon inside these, which is literally just stuffed in one side and drawn out the other.
In the intake side, the knob allows for manual advancement, but the printer also has a gear drive which advances the ribbon as it prints.  Below the knob is an idler gear which meshes with the knob to force the ribbon into the holding bay inside the cartridge.
The fact that the ribbon looks all nice and orderly on the extraction end is really just because this cartridge is new out of its box.  After just one pass through the printer, this all ends up looking pretty crazy stuffed.  I'm almost tempted to try and retrofit in plexiglass just to be able to see the patterns the ribbon forms as it is recycled.

In any case, lots of newspaper, my MechE tendencies to get absolutely filthy, and ten minutes of very carefully repacking the ribbon into the NP-10 cartridge was fairly successful.  The FX80 ribbon unfortunately doesn't have the half-twist in it, so the printer will only ever use the bottom half of the ribbon, and I would eventually need to pull the cartridge and vertically flip the ribbon if I wanted to use the top half.
The difference in print quality is phenomenal. In the foreground is the new ribbon printing in draft mode, compared to the old ribbon printing in both near letter quality and draft mode in the background.
 So in the end, a little TLC got this printer back into its prime for another few hundred thousand characters.  I thought it was fitting that, even for a 30 year old printer, I still ended up spending almost twice as much for the replacement ink as I did the original printer ($9 vs $5).  I've saved the old ribbon, so at some point I will possibly try and recondition it as well.  At this point, we just need to hope like hell I don't end up needing to replace the actual print head (since the wires themselves do eventually wear out), since I expect finding a compatible replacement for the print head to be somewhat more challenging.

Saturday, June 9, 2012

June De Anza Flea Market Haul

 Like usual, today was the second-Saturday-of-the-month Electronics Flea Market at De Anza.  I made one grave error on the way, which was that I had the bright idea of cashing this weeks paycheck at the bank on my way to the flea market.  That got me in a little trouble, but even if I spent a little more than usual, I got one hell of a haul.
 An absolutely lovely Weston 500μA amp meter.  Typically, you would couple this to a system through a transformer, so that even though it can only measure 500μA, you divide a system's much larger current down to it.  This prevents you from having to run 100+A conductors to your front display panel. 
 I managed to haggle a guy down to $10 for three trays of RJ-45 female connectors.  I did this assuming these were the old-style straight pass-through jacks, meaning that to use them for Ethernet I'd have to buy discrete magnetics, which have become almost impossible to source since integrated magnetics (isolation transformers) have become so popular.  After ohming one out now that I'm home, it turns out they have 100bT magnetics in them... Sooo much for using these connectors and Cat5 cable for RS-485, but holy crap!  This is almost $500 worth of Ethernet jacks bought for $10.  I guess I have lots of Internet-connected projects in my future...
 $10 got me a bulk bag of 2N3904 low-power NPN transistors.  Far as I can figure, there is about 1,300 transistors in there, so I walked away with a unit price under a cent, which is respectable.  Set of NiMH batteries, since mine have given up most of their punch, and two PC fans for misc projects.
 I'm torn whether to keep them for myself or give them to DangerousPrototypes, but $2 for an entire spool of tiny warning labels.  "Apply warning labels to ALL the projects!"  A pair of old SmartHome phase-bridge transceivers out of a free pile.
 Out of the same free pile as the SmartHome plugs came what is possibly the best find of the day; A draft copy of K&R C 2nd ed, but the real gem here is the fact that the cover has written on it "Return to Bruce Perens."  In case you didn't know, Bruce Perens defined open source, so finding one of his old copies of K&R is simply incredible.  If Bruce happens to read this, apparently I have your book, so give me a call?
 Some pocket change got me another two good texts; one on adaptive systems,
 and another on material mechanics, written by Moore.  I've always found Moore's books enjoyable to read, so being able to find one is a rare treat.
 I blame peer-pressure for this purchase; $5 for a totally awesome 81mm ammo crate. 
 I have no idea what I'm going to do with this, or even where I'm going to store it, but the hardware was still in good shape, so the possibilities are broad.
On my way back to my pickup lugging this ridiculous crate, I even managed to FILL it with 1968-1975 Ham Radio and CQ magazines.

Overall, an absolutely stunning haul.  Even after going to these swap meets for a few years now, even I am floored by how good some of my finds were this weekend.  There are still a few of these flea markets left this summer; the next one will be on July 14th, so if you're in the south bay, mark your calendars.