Thursday, October 18, 2007

Squeak and NXT

So Lukas Renggli has long since written some code to make Squeak talk to a Mindstorms NXT brick via Bluetooth. Of course, I wanted to try that. (On a Mac.)

Installing the Squeak code from Lukas' Monticello repository was the easy part. After some trial and error, some e-mail exchange with Lukas, some googling, and eventually some help from here and there, I got it running after all.

In summary, the thing works by mapping the Bluetooth device to a file in /dev. Once you know how to do it, it's easy: after the NXT has been added to the known Bluetooth devices, the "Devices" section of the Bluetooth configuration needs to be visited, and NXT needs to be configured to be a "Dev B" device with an "RS232" port. That is mapped to /dev/tty.NXT-DevB-1.

To get things communicating, the device must be opened, which is (weirdly enough) done by
issuing something like cat /dev/tty.NXT-DevB-1 - actually, this will connect the Mac to the NXT (as the symbols on both boxes' screens will indicate).

Now is the time to go back to the Squeak image, and after initialising the NXT communication tools with NxtConnection initialize, a simple "print it" on NxtSerialConnection new connect; battery will yield 8045 (which is the current battery voltage in millivolts, according to Lukas' code documentation).

Just killing the cat in the terminal will terminate the Bluetooth connection.

Great fun.

Lukas told me that he never got past implementing ping and battery status request, but extending the code should be within my reach. I think I'm going to need it. Stay tuned...

No comments:

Post a Comment