Skip to content


Something that’s been intriguing me for a couple of days now is the possibility of integrating classic electronics directly into Lego. A quick prototype kind of thing where you can just clip things in and out and have them work.

Now, I could fork out a sizeable amount of cash and get a Mindstorms NXT 2.0, or, I could use the Lego I already have, my dremel and some paperclips lying around to make things happen..

I’ve got an Arduino, so I would like to break that out directly into Lego. My first obvious question is how to modify a brick with simple materials easily on hand (and a high-speed, teensy tiny drill press) and get them to be quickly stackable to build a circuit out of them.

I’ve seen a solution out there, using small nails and then clipping wires onto them, I’m not sure I like that approach though – way too many fickle wires to worry about..

A couple of minutes at the workbench, fiddling, and here’s what I came up with – Holes on top and on the sides, bend paperclip, and voila. It’s kinda springy too! I’ll let the pictures do the talking:

Top view:

Bottom View:

Two clipped together, has a sturdy electrical connection:

So will see where this ends up!

PS. Yes, I’m mauling my spare MegaBlocks which I consider aliens to my collection first 🙂 No sense in experimenting with the real thing just yet!

Microprocessors.. Part 1

Frans (my youngest brother) has me suddenly hooked on microprocessors, and now I have a whole design in my head.. Thus a project is born.. Not sure what to call it yet, but the name that seems to stick in my head is ‘Raven’, so we’ll see how it pans out?

From the top – My dad gave me a ‘Fundamental Electronics’ handbook so I can get to grips with the basics and not lose my head in a random electrical explosion, and Frans gave me an Atmel AVR STK500 board with an Atmega48 processor to mess with.

My end goal of my project is this : Build a modular rapid prototyping system, where I can slap in components like wifi, flashdisks, gps’es, motors, etc together via a unified interface (USB seems a logical choice) and quickly code something (in java, of course) to make it all work together.

As far as rapid prototyping languages go, assembler is definitely out of the question with C not far behind.. My choice of language is obviously Java, so I have my eyes fixed on a Sun SPOT – The $750 price tag isn’t going to happen plus getting it here is going to prove painful, so another solution is required.

After a bit of research, I found the Squawk VM, which (hey, surprise) is used on the Sun SPOT – perfect for the job. Now I need to find a chip that can support it – the ARM920T is what the SPOT uses, so something based on that design should work with the least amount of hassles.

Googling somewhat finally turned up the Atmel AT91RM9200, based on the ARM920T it looks perfect for the job – now I just have to source it from an electronics company closeby and maybe find a development board for it, else I’ll have to figure out how to get it programmed manually. fun.

Back to reality, I’ve had to clean up my garage somewhat and I still need to order a semi-decent soldering iron and multimeter (probably from somewhere like, put up some shelving and source some organizers and bunches of components.

I’ve downloaded the datasheets and software (AVR Studio 4 and WinAVR) for my AVR STK500 and coded a little bit-runner.. the 8 LED’s simply flash down (in binary) to the number of the button you pressed.. quite simple, except for the weird peculiarity that the high 2-bits are on PORTC and the low 6-bits are on PORTB… I’m thinking there’s some kind of mis-wiring, if you ask me.. but anyhow, here’s my source code :


int main() {
	DDRB = 0xFF; // Output LED's
	DDRC = 0xFF; // Output LED's
	DDRD = 0x00; // Input buttons

	PORTB = 0xFF; // Set the default lights (0 = on and 1 = off)

	int pressed = 0xFF; // Set the default run value

	int gotoState = 0xFF;
	while (1) {
		// If a button is pressed, run to it
		if (PIND != 0xFF) {
			gotoState = PIND;

		// While we're not at the last pressed button, run to it
		if (pressed  gotoState) {
			pressed --;

		// Wait a little, else everything happens instantly!

		// Update the LED's according to the pressed value.
		PORTC = 0xFF & (pressed >> 6);
		PORTB = 0xFF & pressed;

Going forward, I’m going to start sourcing all the components for my end-project, start doing a little more formal design-work (so that this becomes a lot less of a blur) and hunt for a victim lone calculator whose LED screen I can steal.. maybe I’ll get myself a full little LCD, but I’m not sure how much I can fit into 4k – i’ll have to figure out how to extend the execution size somewhat, i think, but lets see what pans out..

Till next time!

Phun Challenge: Factory

First off: whoever hasn’t got Phun – download it here! It’s a very cool 2D physics simulator.

I built an interesting challenge in Phun last night,  Download it here, and now I’m curious to see what solutions people could come up with to make this work, so I’ve decided to issue it as a competition with a small reward of R200 (approx $26) for the best solution.

Objective : Successfully and completely assemble as many of the 5 objects as illustrated in the orange zone example and place them in the demarcated delivery bays. This means you have to move the original pieces to the bays, they have to be attached together correctly and be placed right-side-up.

The simplified rules are :

– Don’t touch yellow area
– Of the existing items you only modify RED gear
– Don’t try looking for loopholes. 😛

The extended rules are :

– You may not work in, or modify anything in the demarcated yellow areas – Those areas have to be exactly identical in your solution as the original state.
– You may not move or modify any existing items/hinges except the RED gear.
– You can create whatever you wish and attach to the background or floor plane.
– At no point is your solution allowed to interfere with the orange (example) area.
– I will be the sole judge of the winner, so you’ll be disqualified if I consider something cheating 🙂
– If you submit multiple entries, I’ll only be testing the last one I receive.

Update: No closing date – if you’re the first to send me a solution, I’ll edit this post and you get the R200 (via pocit –

After the closing date, I will choose a winner on the best, valid submitted solution – A solution is valid if it gets at least 1 properly assembled object into a delivery bay at least once in the 10 times I run it.

I will be scoring each entry based on the amount of fully correct objects are assembled and placed correctly into the delivery bays over 10 tries (getting all 5 in all 10 runs = max score) – if there is more than 1 solution that can do that, I will tie-break it by the entry that is the most amazing and goes the extra mile – I favour faster, cleaner and more stable solutions.

Good luck and have fun!

How IDE’s could simplify Generics and Annotations in Java

This blog entry by Michael Nygard got me thinking, what Michael says is quite true, Java is getting a little rough with all the compiler typesafety ‘help’ we’re getting. Most of the pain is mitigated by all the friendly IDE help these days.. Seriously, I only ever type Map<String, List<String>> in once when I need it.. The rest propagates through the method declarations, instance creation and field declarations through alt+enter (or, ctrl+1, in eclipse)

My thought is that the major problem Michael is outlining is in the view of the java code.. Since IDE’s have full control of the view, we’re in full control to simplify somewhat.. Let’s take an example piece of code :

A bit of a contrived example, purely just to view some code with both generics and annotations. This kind of code is fairly commonplace though, just more prolific – so it gets much messier real fast. What would we prefer to see while working with the code though? I imagine the IDE could easily compress it to something like (ignore the errors for now 😛 ) :

I can easily imagine it expanding as you move your cursor, or move over it when you’re interested in the actual detail, and it feels a lot simpler than the previous code listing.. The IDE could easily take it a step further by displaying it as subscript – kinda like so (excuse my slightly inconsistent photoshopping) :

I think, however, that all of this info can just disappear though, into a seperate editable popup so that the extra compiler hints and functionality is edited in a separate popup (properly keyboard editable though – you might need to spend some time figuring out what feels correct) :

Again, excuse my quick photoshopping here.. I went all the way here and added icons for the ‘private’ and ‘public’ keywords as well – that may be a little overkill, but my point here is that we don’t need to stick to plain two-dimensional text in editors any more.. In my opinion, once you’re done writing the code, and want to glance it over, you don’t necessarily want to have all the in-depth information in your face all the time.. Which is what attracts people to dynamically typed languages in the first place (well, for me anyhow).

Using the IDE to clear up your view of the code a bit could be a nice bridge between compiler type-safety and code brevity for maintenance.. I’m sure it could open up a whole can of interesting squishy things that you could do, but I’ll leave that as an exercise for you 🙂

As a sidenote – this kind of functionality is one of the reasons I’m taking a liking to Groovy where, in its essence, it expands easier-to-read shorthand to the full java shebang (in the compiled class file)..

Getting setup for some Netbeans development

And this means some serious reading to be done (prepare for a bit of a link-fest) :

My starting point is within the Community part of the Netbeans site – there is quite a bit that goes on here but it’s fairly straightforward. After a little digging I find some useful Guidelines, the most notable of which (to me) is the Code Conventions.

Luckily, the Netbeans Code Conventions follows the Sun Code Conventions for Java, which I’ve been following for as long as I remember 🙂 Take special note on the “How to Write Doc Comments for Javadoc” – It contains some really neat info.

With the basic coding guidelines out of the way, the next thing to do is to get the Netbeans source code and get it compiled. To setup Mercurial, I need to download the Mercurial Client. I personally opt for TortoiseHg since I have experience with good old TortoiseCVS and TortoiseSVN – The shell integration is great when things outside IDE’s give hassles and I am personally not a fan of the command line.

Moving on, After installing TortoiseHg and restarting my machine, I just follow the steps outlined here and here to properly get my Mercurial setup inside Netbeans 6.1Beta. And then wait for the clone to happen. This will take a while since, and I quote, “A clone can take anywhere between 1 and 5 hours to complete depending on connectivity”. I’m downloading it over iBurst, so it will likely take 10 hours.. More to come.. 🙂

Automated build using NetBeans 6 Beta2, Ant and jUnit

There seem to be a lot of advice out there, telling you that you should setup an automated nightly build process, yet very little on how to. I’ve just finished setting it up at work and feel like sharing, both so that others can benefit and so I don’t forget what I’ve done 🙂

I have to stress this : Please note that while I’m using NetBeans 6, you should be able to adapt this approach to your environment with ease if you use ant. NetBeans is only doing a lot of ant generating for this, not too much else.

First up, we need to look at what we want to achieve. In my case, I wanted to have my setup automatically do the following, in order, every night :

  1. Update all my automated project sources from CVS
  2. Compile and package everything
  3. Run all the unit tests
  4. Generate an HTML report on the unit tests and publish it.
  5. Send me an email with the build log and write the build log, viewable from my browser

Our target intfrastructure is that any developer who can run the ant build.xml file can work on projects, so that we can deploy on our Linux box without any external NetBeans dependancies. Since everything is meant to run automatically and with as little hassle as possible.

In NetBeans 6 (probably prior versions also), you define reusable Libraries in the IDE as the primary way to add jars to your project. It’s quite a nice way of handling it, since there’s no messy copy and pasting jars into lib folders, relinking javadocs and sources, etc.

This immediately raises an issue though – how do you ensure that all developers have the required libraries in the right locations if they’re not unified in the project/lib folder? If you have a peek at the nbproject/ file, you’ll see that the libraries are defined in there using a relative path. So…

Step 1: Structure your project folder

The answer happens to be fairly simple :

+ Projects
+ Project1
+ Project2
+ Libraries

I’ve simply put the Libraries folder next to the Project1 and Project2 folders, so the Libraries will be referred to as ../Libraries/Guice-1.0/guice-1.0.jar, etc from the projects 🙂 Note two current bugs in NB6b2 though :

1) When you move libraries around and relink them, NetBeans seems to keep an internal definition and doesn’t update the file. Maybe it was just my instance, but when you check it out on your development box, it suddenly can’t find the libraries if you’ve been moving them.

2) In my case, when I checked my Libraries folder into CVS, it checked the jars in as text files instead of binary. There’s no way to check this within NetBeans, but I discovered some funny END header error was thanks to a corrupt jar. Since linux uses different line breaks than windows.

Which bring me to how we want to import the projects into CVS. My structure at the moment is exactly as above, a Project/ folder and all the Projects and our Library folder under it. That lets us directly check out Projects with minimal hassles. I know there are other ways, but this was mine 😛

Step 2: Add a build project

Onto the meat, I then added a build project inside our Projects folder (next to Libraries) which purely handles all the automated fluff. I made it a java project so that I could later add ant task definitions, should I find I need to.

Inside that, I edited the build.xml and overrode the -post-jar target in the nbproject/build-impl.xml by adding :

<property location=”../” name=”projects.root” />
<target name=”-post-jar”>


(Sidenote: Each consecutive piece will fit into the ellipses 😉 )

You’ll see that I’ve defined a projects.root helper property – this just keeps things clean, and makes things a little more flexible for the future.

Step 3: Add our CVS update

Now that we’ve got our build hook, let’s tackle our first issue, cvs updating and add :

<cvs command=”update -d” dest=”${projects.root}” />

The -d simply ensures that any new folders also get pulled through.. and that’s all we need to the cvs side 🙂

Step 4: Get the compiling, packaging AND testing handled

Next up, let’s get all our subprojects compiled, packaged and tested. Lucky for us, If you’ve created your projects in NetBeans, the ant scripts are already prepared, so we just need to add the following to our build/build.xml :

<ant dir=”${projects.root}/Project1″ inheritall=”false”/>
<ant dir=”${projects.root}/Project2″ inheritall=”false”/>

(Sidenote: In my actual setup, i have ${projects.root}/Group1/Project1, because I like my projects grouped nicely, so this setup accommodates that too, should you want it)

And that’s that, running ant in the build project should compile, package and test your projects. Also, since we’re using NetBeans here, the result xml of your tests will be in ${projects.root}/[project]/${build.test.results.dir} for each project.

If you didn’t use NetBeans to create your project – Alas alack! Run around in squares and scream at the bottom of your lungs.. Then go to NetBeans and download NB6b2, create a project and dig through their nbproject/build-impl.xml to see how they do it so you can replicate it.. Of course, you could just adapt the rest of this article to your environment.

Step 5: Generate a single HTML report out of all the results

Now comes a fair bit of ant xml, we need to use the junitreport task of ant to generate the html, but first, let’s define a destination for it :

<property location=”${build.test.results.dir}/html” name=”build.test.results.dir.html” />
<mkdir dir=”${build.test.results.dir.html}” />

Since we want this whole lot as self contained as possible, we’ll put the generated html into the build/test/results/html folder.

Then, the junitreport tag :

<junitreport todir=”${build.test.results.dir.html}”>

<report format=”frames” todir=”${build.test.results.dir.html}” />

No rocket science here – just setting the junitreport destination and format, now lets add in our source xml files (the output from the junit tests) :

<fileset dir=”${projects.root}/Project1/${build.test.results.dir}”>
<include name=”*.xml” />

<fileset dir=”${projects.root}/Project2/${build.test.results.dir}”>
<include name=”*.xml” />

If you save and run the ant build now, it should give you a neat html report of your unit test results under build/test/results/html. 🙂

Step 6: Email me the success or failure of the build

Since I want to know if the build has failed or not every night, I’d like to have it email me the results nightly. I have to confess though, I haven’t gotten this entirely right just yet, I have to override the -post-tests do disable the NetBeans junit failure in each project, which works fine but all mail is sent to me as ‘Build success’ 😦 Any hints welcome.

Anyhow, I digress, create a file in your build project and add the following to it :

There are a couple more options you can add, check the MailLogger in the ant manual – but for now, this will do.

Now add a line just above where you define the projects.root property in your build/build.xml file :

<property file=”” />

This will import the properties in the file into your ant script. Finally, when you run ant, you need to tell it to use the MailLogger :

ant -logger

Step 7: Write the log of the results somewhere accessible by a browser

To do this, simply add the following to your (underneath the MailLogger properties) :


This points the XmlLogger to where you want the output written to. A big note here though : This path is the only path that is relative to your current working directory when you run ant. It’s a pain, but you have to run ant in your build project just for this to work. Using an absolute path is out of the question since we want to stay platform independant.

Now, in order to actually see a sane view of the log.xml, go hunt ANT_HOME/etc folder for a log.xsl file, copy that into the root of your build project (next to The reason for this is simple, we need to be able to clean the test folder up by deleting it and have no recovery issues. So, now we have to add this to the build.xml to move the log.xsl to next to the log.xml :

<copy todir=”${build.test.results.dir}”>
<fileset file=”log.xsl” />
<fileset file=”index.html” />

I’ve also added an index.html to give me handy links to the log.xsl and the reports. You can do that if you like.. or not.. whatever.. I also added the following, in case the XmlLogger gives me grief by not wanting to overwrite files :

<delete file=”${build.test.results.dir}/log.xml” />

Now, we just need to run ant like so, in the build project :

ant -logger -listener

Step 8: Setup the nightly cron

Lucky for me, there is a handy /etc/cron.daily on my development box that runs all the shell scripts in there daily, so this does the trick (/etc/cron.daily/nightly_build) :

cd /usr/local/src/Projects/build
ant -logger -listener

Step 9: Enjoy

And that’s all there is to it! OK, I need to iron out the ‘Build success’ issue, but for now at least I have something up and running, testing all my code and keeping it all neat and tidy. I like that 🙂 There’s some extra things I’d like to do when I have time, like making the build/build.xml declare a macro that builds each report seperately, and then link each project through the index.htm. Mostly so that adding another project in there will only be one line of code (well, two, if you count the link in index.htm)

Hope you found this useful, I had fun setting this up 🙂

Powered by ScribeFire.

You have time for one question for James Gosling. What’ll it be?

Last year May at the Sun Tech Days, something is still bothering me a bit : I was sitting in the front row of the main hall just before James Gosling (father of java, in case you don’t know..) was going to do his keynote – James sat about 2-3 seats from me waiting for Reg to finish up his part, there was only empty seats between us, and I looked at him and smiled, he smiled back.. a minute or so passed and he went up to do his keynote thingy.

Now, I don’t idolize people and pretty much treat everyone as equals, we’re all just human beings at the end of the day, but across from me sat a guy with such a vast knowledge of just about everything java.. What would you ask him if you had just one question and maybe a minute for the reply??

I ponder that every now and then and still can’t come up with an answer… I don’t know what question I’d ask even if we were left alone for a few minutes, and that goes for any of the experts at sun and the guys doing the whole tech days thing. I could have approached them at any point, but what would I say? I have no clue..

The problem is this : Every question about java is pretty much ruled out, since a simple google search will 9/10 turn up the answer in 5 seconds with the other 1/10 taking maybe 10 seconds, so every single question I can think of is a stupid question. Perhaps one could start a discussion about things like abstract classes vs interface, dependency injection or maybe even touch on some concurrency issues – but everything is way more thoroughly explained and discussed in books and forums!

It’s a conundrum. I would want to rather spend a week or so with them, working on a real-world project (from scratch, preferably) so I can sap out as much of their knowledge and experience as possible. But ye. Like that’s gonna happen!

%d bloggers like this: