pbLua Bluetooth on Mac OS
pbLua Bluetooth on Mac OS
August 2009
Bluetooth communication between the NXT and a computer can be difficult to get working. On Mac OS X Leopard bluetooth communication is handled a little differently than on a PC. I needed a BT connection between my LEGO turtle drawing robot and the Mac so that the drawing would not be snagged by the USB cable. Here is a tutorial on how I set up Bluetooth between my Mac and NXT in pbLua.
I am running Mac OS X Leopard 10.5.8 on a 2009 MacBook Pro, connected to a NXT 1.0 running pbLua beta 18a.
Getting Started
There are two sides to the Bluetooth communication process; setting up the NXT and setting up the Mac to pair to the NXT. The initial part of this process requires that the USB cable between the Mac and the NXT is connected and that you are at a pbLua prompt in a terminal window. For more on how to get USB communication to the NXT working see my previous tutorial.
Ralph’s tutorial on Bluetooth communication in pbLua is our first stop. He explains the process of establishing a BT connection down using the pbLua API to control the BT radio chip on the NXT. At the pbLua prompt on your NXT type:
> nxt.BtPower(1)
> nxt.BtFactoryReset()
> nxt.BtPower(1)
> nxt.BtSetName("turtle")
> nxt.BtSetPIN("1234")
The NXT Bluetooth radio is now turned on, the name of the NXT is set to “turtle” and the pairing PIN is set to the digits 1234. So far so good.
On the Mac
Next we need to enable Bluetooth on the Mac and create a serial port (equivalent to a Windows COM port) to communicate with the NXT.
Disconnect the USB cable from the NXT
Power off the NXT
Power on the NXT
Select the BT Console on the NXT screen by pressing the grey button on the NXT, then pressing the orange button
The NXT screen displays “Wait for connect” and some other status information
Turn on Bluetooth on your Mac:
Select “Set up Bluetooth Device” in the Bluetooth pulldown menu:
The Bluetooth Setup Assistant dialog will open:
Click Continue and select “Any device”...
Click Continue, and the NXT should be detected after some time scanning...
Click Continue and the Mac will attempt to gather some information about the NXT. As the NXT does not offer any services (other than serial ports) this list will come up empty...
Click Continue and ignore the warning message it gives you...
Click Continue and we are done with the initial setup phase.
Note how the dialog tells us that a “computer serial port” was created. As you recall from my tutorial on getting the NXT to work with a Mac all communication on a UNIX-like system such as Mac OS is based around tty devices in the /dev directory. These are equivalent to COM ports in Windows.
We have to assign a name to the serial port used to communicate with the NXT. Open System Preferences and select “Bluetooth”...
Then select the NXT (in this case named “turtle”) and click on the gear pull-down button beside the + and -; and select “Edit serial ports...”
Click the “+” button under the list to add a new serial port entry for the NXT. In this example it is called turtle-DevB-1. Once you click Apply a new device is created in the /dev directory that represents a serial link to the NXT. Open up Terminal and list the contents of /dev:
Now we can communicate directly with the NXT via Bluetooth as if it were attached via the USB port. Start up minicom in another Terminal window and set the path to the serial device to be /dev/tty.turtle-DevB-1:
And you’re done! The transmission speed to the NXT seems to be a little slower than the USB cable; but it works!
Last updated 24 August, 2009
All content © 2008, 2009 Mark Crosbie mark@mastincrosbie.com
LEGO® is a trademark of the LEGO Group of companies which does not sponsor, authorize or endorse this site. This site, its owner and contents are in no way affiliated with or endorsed by the LEGO Group. For more please read the LEGO Fair Play policy.