Submission by Ant – If I started talking to you about LCD panels for home automation use, you’d probably start thinking about kit from the sort of suppliers that you’re vaguely aware of in the same way you’re aware of the outer planets: you know they’re there, but you’re unlikely to ever have anything to do with them.
This project is about neither of the above approaches. You probably won’t even have to get a soldering iron out. Some C or C++ coding skills might be of use – at least until there are ready-to-use apps available. What we’ll end up with when we’ve finished is an LCD control panel with the following features…
- 2.9 inch colour TFT screen with backlight, capable of displaying 65,536
colours at 240×160 pixels, at 60Hz
- ARM7TDMI 32-bit RISC processor running at 16.78 MHz
- 16kb BIOS
- 256kb on-board RAM
- 32kb fast cache RAM
- 96kb Video RAM
- up to 32mb flash/ROM memory
- hardware graphics acceleration for multiple bitplanes, sprites, windowing,
- 6 channels of 8-bit stereo audio (2 DACs, onboard harmonic synthesis &
- Li-Ion rechargeable battery
- 10 buttons
- UART configurable for standard operation, or multidrop serial operation
- downloadable software, or run from flash/ROM
- several free development environments & many development resources
- fully documented architecture
By now you’re probably thinking that I’ve inhaled too much of the old solder flux. What about if I told you that this little lot would set you back under
a tonne? And that you can go buy it on the High Street? OK, enough teasing – I’m sure the more astute readers have guessed what I’m describing, and the remainder will shortly be thumping themselves in the ‘nads with belated realisation. What we are talking about here, ladies and gents, is Nintendo’s GameBoy Advance.
The GameBoy Advance (GBA henceforth) has until recently been a rather nasty little customer, with a truly horrid screen and a penchant for batteries in large quantities, topped off by an ugly plastic case available in a wide selection of entirely awful trendy colours. In short, not the sort of thing you’d want to bolt to the wall of your gaff. Fortunately, Nintendo have recently released the GameBoy Advance SP, which addresses the above issues by providing a backlight for the screen, a rechargeable Li-Ion battery, and a natty clamshell design, which makes the unit about the same size as a stack of 3 minidiscs. Click the thumbnails below for a better look.
I originally picked up one of these because of a game called Metroid Fusion. I’m not generally partial to console games, but this was by way of an homage to it’s precursor “Super Metroid” on the Super Nintendo, which once saw me and my best friend skiving off work for a week in order to complete it. The game was utterly marvellous, but after completing it, I started eyeing up my pretty new GBA in a way which had it feeling somewhat uneasy.
Surely, I reasoned, there must be some more useful, geeky, and altogether Ant-like purpose to which you might be put? After faffing about on
the internet for a happy couple of hours, I determined that the GBA internals were quite well documented, that all the tools necessary were available for free, and that the additional outlay was minimal.
Assembling the hardware
For starters, you’re going to need a GBA SP, or even the old GBA, available from the likes of Dixon’s. The SP will set you back about 80 quid, and I’ve seen the regular GBA going for around 50. All we need in addition to this little setup is a programming cable, and optionally a FLASH cartridge.
The programming cable I opted for was a Flash2Advance Linker, available from Divineo for £24.95. I also picked up a 256Mb flash card for about a tonne, although there’s a 128Mbit version available for £79. The flash cartridge is entirely optional though, as the GBA will boot from a remote host via the cable.
The official Nintendo development environment for the GBA costs big money, but fortunately there are a number of free development environments
out there, and a veritable plethora of supporting tools, including graphics and sound conversion utilities and emulators for just about every platform under the sun, including the XBox, and Java (you’ll encounter the Java emulator shortly).
I opted for the HAM development environment http://www.ngine.de. It’s available in both windows and linux variants, and even has a visual IDE if you like that sort of thing. Personally, I’m a vim man, but each to their own. HAM is basically a cross-compiler tool chain, a target-resident library which you can use in your own programs, a sound library which plays MOD (tracker) files, and a bunch of other useful stuff. I also downloaded the VirtualBoy Advance emulator, which again is available for many platforms. The emulator allows you to quickly prototype applications without having to download them to the actual hardware.
The HAM devkit comes with extensive documentation and several example projects. I used these, and some online tutorials to get going. I also made extensive references to CowBite’s Virtual Hardware Specifications which describe the hardware in great detail.
HAM provides a library of well documented functions which make it fantastically easy to develop code for the GBA. The meat of this library
deals with graphical functions as you might expect. The GBA supports up to four simultaneous alpha-blended graphics layers, and a wide variety of functions for mucking about with them.
An example application
After a bit of initial experimentation, I decided to try my hand at a UKHA application for the GBA, to see what was really involved. What I was
after was a menu system that would display the status of various common home automation elements, and issue commands to them as appropriate. My idea was to have a structured menu environment, linked to something like a xAP backend to do the donkey work over the GBA’s serial port. I’ll be honest and confess up front that I didn’t quite get there, thanks to the deadline for submitting this article. What I did achieve was a smoke and mirrors demo of most of the graphical side of things, complete with thumping techno soundtrack! All it needs is some additional work to generate menus on the fly, and a xAP bridge or equivalent to do the communications with the rest of the system. Here’s a screenshot:
Ok, so it’s not pretty, but the screenshot doesn’t really do it justice. Refer to the emulated version below, or the AVI. This demo allows you to navigate around the screen with the directional pad, change the state devices with the A & B buttons, and swap between menu pages with the L and R buttons (OK, so there’s only one menu page at the moment….)
All this was achieved in the space of about two days, and just over 500 lines of code. To be honest, the majority of the time invested was spent faffing about in Photoshop and the GIMP to get the images in the right format for the GBA to understand. Programming for the GBA is peculiar in that it turns the normal programming experience on it’s head: doing stuff like fancy rotating & scaling alpha-blended graphics is a piece of cake, but doing simple text output is significantly trickier. The font I used was shamelessly lifted from the Linux Console Project, and a better alternative could be had with a little time expended. Similarly, the graphics are somewhat plain as I was in a rush to get something running.
My sources are available here. Please note that neither the C source code nor the makefile or professional-grade: I’d be embarrassed to churn out something like that in my day job. Rather, the source code has grown organically as I’ve experimented!
I’m hoping that if this article generates sufficient interest, we can get a project underway to recode something more suitable which can be used “off the shelf” by the UKHA populace in general.
Running code on the target hardware
The best way to play with this demo is to download one of the emulators (see links below) and load it up. I used VisualBoy Advance extensively
while developing, but there’s nothing like seeing it run on the actual hardware. For this you have two options: you can either “bootstrap” the code
so that it’s downloaded by the GBA’s BIOS over the serial link each time it’s turned on, or you can program it to a flash cartridge and run it like any other application. The relevant software comes with the link cable, and is a trivial drag and drop affair.
Try it out!
If you’ve got Java enabled, you can experiment with the fruits of my labours below. The picture of the console below is the cheaper, inferior
standard GameBoy. I couldn’t find a skin for the new GameBoy SP. Note also that you don’t get sound, but then being Java, I’m amazed that it works at all. For the full multimedia experience, download one of the emulators listed below, and try my application in that.
(In this emulator, you need to use the cursor keys on your keypad to emulate the directional pad, the ‘R’ key for the A button, the ‘T’ key for the B button, the ‘E’ key for the ‘L’ button, and the ‘Y’ key for the ‘R’ button. Press ‘Z’ to reset.)
Clearly this little beasty has considerable potential as an HA controller. It could be mounted to the wall fairly easily as it is, and when
closed would be not much larger than a standard light switch. The unit only requires two connections: the serial cable and a power supply, although it will run from its internal battery quite happily. It might even be possible to use a standard non-SP GBA if you have good direct lighting, although in that case I’d recommend a custom case mod, as I certainly wouldn’t want the purple monstrosity above bolted to my walls.
GBA programming is both quick to learn and rapid to prototype given a little software knowledge. The tools to do it are widely available,
well supported, and most importantly, free If there’s sufficient interest in the project, I hope to do a follow-up article in which I will advance the demo above to a more useful stage, incorporating a generic menu definition parser and a xAP or xPL back end, as well as in depth coverage of the various serial communications modes offered by the GBA.
All in all, for an outlay of a hundred pounds, you can’t really go wrong. I’d recommend Metroid Fusion while you’re at it. If you start to tinker with a GBA, or have any further questions, contact me via the mailing list.
comprehensive review of the GBA-SP, including internal shots – www.lik-sang.com
extensive GBA Hardware reference document
- the HAM development environment – http://www.ngine.de
- Divineo, purveyor of many a fine console
- Virtual Boy Advance, the best (IMHO) emulator http://vboy.emuhq.com
- Boycott Advance, another emulator http://boycottadvance.emuunlim.com
- Aaron Roger’s excellent HAM tutorial http://www.aaronrogers.com/ham/
- GBA programmers’ tools utilities, and reference – http://www.gbadev.org
- more programmers’ stuff – www.gbaemu.com
- www.devrs.com/gba/ – more programmers’