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.
- Download and install
Lightblue.
- You will also need PyObjC. If you're running Mac OS X v10.5 (Leopard),
PyObjC comes built-in. Otherwise, download and
install PyObjC yourself.
- Download and install
NXT_Python.
- Download bluetooth.py
- 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, enable Bluetooth on it, and run some NXT_Python
test program to make sure everything works. For example, the
mary.py program in the examples directory will play a tune
without requiring your to plug in any sensors or motors. The first time you do this, your NXT brick will probably tell you its passcode (default = 1234), and your Mac will prompt you for this passcode.