Getting started with nxt-python

nxt-python is a great way to get started programming the Lego Mindstorms NXT brick in a familiar language. As usual, the best way to get started with a new piece of software like this is to modify a working example. Save this file to a convenient location (ideally, in a folder where you'll keep your work for this course). Now turn on your NXT brick and use the arrow buttons to find the Settings (with a picture of a wrench). In Settings, move to NXT Version. At the bottom of the version info is the MAC address for your NXT brick, labeled as ID. In your favorite editor (IDLE, vi, jEdit, whatever), open the nxt_beep.py program that you just downloaded, change the ID to this number. You will have to put colons between successive pairs of digits. Once you've made this modification, you should be able to run this program like any other Python program (python nxt_beep.py). The first time you run the program, the NXT brick will give you a password to enter into your computer. Once the program is running, you'll hear a one-second beep at 440 Hz (A above middle C). If you run into problems, make sure that you have a Bluetooth adapter ("dongle") installed on your computer. You can check this by issuing the lsusb ("list USB devices") command in Linux. If there's an adapter on your machine, it should appear in the list. If you don't have one, let me know, and I'll install one on your computer.

Once you've got this simple example working, it's time to start modifying it to implement the program you created using the Mindstorms graphical software. As with any well-documented Python package, you can learn about the capabilities of nxt python using pydoc: pydoc nxt will give you an overview of the package contents; then you can do; e.g. pydoc nxt.brick will tell you the methods you can call on a brick object, pydoc nxt.sensor will tell you all about the sensor package, etc.