Alcides Fonseca

40.197958, -8.408312

Lego Mindstorms NXT

Last week I borrowed a Lego Mindstorms NXT Educational Set from the Physics Department to use in the last class I’m giving to 13 year old kids about programming with Python.

First of all, I dealed with the hardware and spend about one hour assembling bricks like I used to do…. 10 years ago. Lego rocks! Since I hadn’t much time to spend with it, I followed the Tripod model, but in the end I realized I didn’t had the extended set, so I started to invent, like it is supposed to! Here’s the final result:

Now the software: I could let kids use the programming GUI, but I don’t like it very much, and the purpose of the whole course was about coding, so I wanted Python. Since the robot cannot run Python itself, I was running the program in my macbook that would remote control it.

The “NXT Python library is really helpful”, but OS X requires a little hack on the bluetooth module, so this page explains it all.

So I did two programs: One to remote control the NXT with my Wiimote. With the arrow keys, I can control it’s moves, the minus/plus allows me to control the speed, which is very useful when turning! And when it bumps something, The wiimote rumbles and lights up the LEDs for each active sensor.

The second program, just makes the robot wander around and when bumps something, he turns a bit. That’s enough for it to spend some time by itself :)

You can download the source code (with all the necessary libraries, that you must sudo python install inside each dir).