In the first edition of the book, there is no code for Project 3, Negotiating in Bluetooth. The project just describes how to use the blueSMiRF radio. With the BlueSMiRF v.2 radios from Spark Fun, the principles are the same, but the commands are different, because the BlueSMiRF v.2 is based on a different Bluetooth Radio (see this post for more). The full list of AT commands for this radio is online here. What follows is an update to Project 3, Negotiating in Bluetooth”
To ask the BlueSMiRF v.2 radio for its firmware version, you type +++\r, and the radio will respond with
OK
Then type:
ATI\r
The \r is a carriage return. The radio will reply as follows:
1SPP - Ver: 1.2.4
The version number may be changed depending on your radio, of course. To search for new radios, first type
AT+BTCAN\r
This cancels any current commands. Then type
AT+BTINQ=10\r
This tells the radio to search for new devices for ten seconds. You can use a different number if you prefer. I found 10 seconds was adequate. The list it returns will look like this:
+BTINQ: 0016CB2A2BF0, 10210C +BTINQ: 001CD6ACD9A0, 5A020C +BTINQ: COMPLETE
To connect to the one that represents your computer, match the Bluteooth address to your computer’s Bluetooth address. You can get the name of a remote device by typing
AT+BTRNM=address\r
Pick one of the addresses from the inquiry list and try it. You’ll get something like this:
+BTRNM: 0016CB2A2BF0, "tigoemacbook"
Now that you’ve found your computer, get a list of its services by typing
AT+BTSDP=0016CB2A2BF0\r
You’ll get a list like this:
+BTSDP: 1, 1.0, "Bluetooth-PDA-Sync", 1 +BTSDP: 1, 1.0, "SerialPort - 1", 3 +BTSDP: 7, 1.0, "OBEX Object Push", 10 +BTSDP: COMPLETE
You might have to define a Bluetooth serial port for your machine first. The Bluetooth control panel for your computer will have an option to add a serial port. Follow the instructions for your operating system on how to do this. In the list above, SerialPort -1 is the serial port, and the port number is 3. To connect to it, type
AT+BTCLT=address, port\r
For this specific case, you’d type
AT+BTCLT=0016CB2A2BF0,3\r
The radio would respond
OK
Your computer might ask for a passkey. Don’t give one, and the radio should connect. Then open the serial port that’s connected to your computer’s Bluetooth radio as described in the book, and you should be able to send data from the BlueSMiRF to your computer.
To get out of data mode on the BlueSMiRF v.2, type
+++\r
This will break the link with your computer and you’ll get the NO CARRIER message. To return to data mode, you need to reconnect using the sequence above.