Monday 27 February 2012

Bus tracker lives!

And so for the first project on here...

Here in Edinburgh we have these wonderful posts with LCDs on them that tell you when the next bus is coming.  On a Sunday, the buses are less frequent as you'd expect, so it's handy to judge your leaving time with reasonable accuracy... there is a web site but we don't always have a computer on (hard to believe, I know!) so I decided to make my own equivalent for the house!

The basic ingredients are a computer with ethernet, some form of display, and a button to change what is being displayed.  Plan was then to put it all inside a cheap canvas frame which could be painted up to look a bit like a bus...

The Computer

There are a number of small computer-y things lying about the house, but I eventually settled on a Bifferboard as I had a couple of them spare from an audio design that didn't quite suit.  This a little 486-compatible SoC with USB and 100Mbit ethernet that typically runs OpenWRT... the handful of GPIO ports made it ideal for the job.

 
It took a little while to get OpenWRT set up correctly and flashing a useful image, but once finally done, that's it!  When building an image from scratch, you *really* appreciate having quad cores in your dev machine... it takes a little while.

The Display

My immediate reaction was to go for a 20x4 LCD as it's similar to size used on the actual bus trackers, and also have familiarity with HD44780 displays from my work on the Zero One Ti48 transport.  It needed to be large so as to be visible from a distance - most are far too small for this kind of application.  Rapid came good with the Winstar WH2004L unit which isn't too expensive and is nice and large.


I was tempted to go with the white on blue a la the Ti48 but figured it was nicer to have black on green as it's what the real bus trackers use.  As HD44780 displays are parallel, conventionally they need quite a lot of pins to drive, which is a shame as the Biffer doesn't have a huge amount available.  You could use a USB to Parallel port converter and drive it that way, but I thought it'd be simpler to use a simple HC595 serial to parallel chip to do the job off the Biffer GPIO.  So I thought...

I came across this website which seemed to have done most of the work already.  However, I found the LCD to be very unreliable (particularly initialisation) and the positioning code was missing.  In the end, I rewrote all of the code and wired the '595 latch to Enable which avoids unnecessary state transitions on the output pins, which seemed to make the LCD happier.  Other than that, the wiring is essentially the same. 

The Button (ooh!)

The Bifferboard already has a button on the front of it, but it's likely to wear out in short fashion if used day in, day out.  A cheap minature switch from Maplin was procured and wired in parallel with the Biffer's button.  Due to the sloping internal sides of the frame it wasn't very feasible to mount on the outside without glueing, so instead ended up screwing it into the inside and dropping in a shaft extender in the shape of an M3 hex spacer - hack-tastic!


The Inside

So here's what it looks like in the inside the frame.  You can see the metal L brackets used to mount the internal sheet to the wooden frame - the sheet itself is a kind of foam commonly used for advertising boards... the great thing about it is that you can cut pieces out with a scalpel, yet it is still strong enough to support the electronics.  At the top there's the biffer board with a lead going down to the shifter unit piggybacking on the LCD display.


The white plastic block is a budget-style "passive" Power Over Ethernet converter... purpose of this is ultimately to run the unit off ethernet power, but my main PoE power source is 12V so needs to be converted down to 5V before this can happen - for now, it just runs off the original 5V supply.

The Code

The code was pretty straightforward - it's a C++ application using standard POSIX calls, no special libs required as all it needs to do is pull down an XML file over HTTP, parse out the bits it wants, and display it.  It took far longer to get the OpenWRT image right than it did to actually write the app itself!  To learn where to get the XML from, I took a look at the Android Bus Tracker application, and the parameters to send were very self-explanatory.

For brevity, the parser is only *just* sophisticated enough to get the job done... rather than employ a heavyweight XML library, the code relies on certain strings being in the right place.  If they ever change the format, it will probably break the app, but that shouldn't be too hard to fix.

Power

For those power geeks out there, according to my Fluke, power on peaks at around 450mA (2.25W) and it typically sits at around 326mA (1.63W).  This is about double what my "Energy Monitor" told me, so need to take it with a big pinch of salt in future when it comes to really low power stuff!  The screen is probably taking around 80mA, most of which will be in the backlight - this could be tuned down a bit, but the unit doesn't run off batteries so not so critical

"Finished" Product

And here it is...


Thanks to Anna for doing the artwork - I think it looks friendly and a bit silly, which is exactly how I like it!  Seems to work fine - the canvas was velcro'd to the wall with some small squares of the stuff... the adhesive seems strong enough to hold a light frame like this, which is handy!

The display updates every two seconds with a new page - you can speed it up with a quick tap of the button.  Hold down the button for a second or so for a different bus stop.

Pleased to have it completed to a point where it can be used every day... projects like this tend to start with such enthusiasm but then little problems crop up here and there and it starts to drag a little - starts to feel like work!  But it's generally worth it when you're done - certainly was in this case.  :)

No comments:

Post a Comment