Fun with the Mindstorms NXT and OpenSCADA
April 16th, 2007 by jensMany of you might know Lego Mindstorms. Those who don’t should have a look at it, you are really missing something
The new NXT version of Lego Mindstorms has quite some interesting features: a 32bit CPU, bluetooth and USB connectivity, new sensors (like ultrasonic distance measuring), an open source firmware and lots more. Of course this screams for some OpenSCADA integration
… so here it is: MindstormsProject

The first step was to establish the connection with “the brick”. The main controller allows connections from USB or bluetooth. Instead of re-implementing the whole protocol the NXT firmware uses we adapted the “iCommand” library of the LJOS Project (link). Although the library suffers from several problems it was a good start. First of all there were some issues with the Java Comm implementation RXTX (http://users.frii.com/jarvi/rxtx). Using bluetooth and the rfcomm device /dev/rfcomm0 establishing a connection was quite mixture of: it works, it works not, it generates a kernel panic. Next was the lack of OO-ness in the iCommand library. Since most methods where static only one connection could be created at a time. Also error handling was a big problem. But by re-organizing the code in an OO manner and refactoring the connection class to an interface and two implementations (RXTX and LibUSB) many of these issues could be solved.
The LibUSB wrapper is a tiny JNI library that wraps around “libusb” and “libusbpp”. It provides basic functionality for communicating with USB devices. There is also a win32 version of that library but we used Linux for this test so we did not try it.
Based on a working NXT connection we created an OpenSCADA DA Server which hooks up the NXT to OpenSCADA providing sensor input values to data items. For the moment only the ultrasonic sensor is hooked up. But the rest is only a matter of available free time or contributions

Posted in Screenshots, Atlantis, Mindstorms |