Python/Bluetooth Support for Lego Mindstorms NXT on Mac OS X
The file bluetooth.py
contains some Python glue code I wrote to allow
NXT-Python to run on Mac OS X without modification.
NXT-Python uses
the
PyBluez package, which (as of April 2008) runs on Linux and
(perhaps) Windows but not on Mac OS X. My
bluetooth.py implements just
the code from PyBluez/bluetooth.py that is needed by
NXT-Python.
Here's what you need to do:
Make sure that Python 2.4 or higher is running on your Mac.
You will also need PyObjC. If you're running Mac OS X v10.5
(Leopard) or higher,
PyObjC comes built-in. Otherwise, download and
install PyObjC yourself.
In your ~/.profile and/or ~/.bashrc files,
set the PYTHONPATH shell variable to the directory where you saved bluetooth.py. For example, my
~/.profile contains the line
export PYTHONPATH=~/nxt_lightblue_glue
The reason that you're not installing this package as a normal Python package is that it's
just a patch to avoid having to modify NXT Python.
Turn your NXT brick on and enable Bluetooth on it. Via
System Preferences or the Bluetooth icon at the top right of your monitor,
set up the NXT brick as a new Bluetooth device.
In your shell, cd to nxt-python-1.1 (or the directory
containing the current version). Launch Python and test your connection by
typing
>>> from nxt import locator
>>> s = locator.find_one_brick()
>>> c.play_tone(440, 500)
>>> s.close()
The find_one_brick command will probably tell you that USB
is unavailable and may produce a deprecation warning, but these can be safely
ignored.