среда, 16. новембар 2011.

Bluetooth Mate Silver review




Hello gangsters, welcome to our post No.2. Our first idea was to write in this post about software part of our project which includes some detailed information about Android application but changes have occured and we will leave that for post number 3. So, all of you who have been visiting our blog, days and nights in couple last weeks be patient just a little more. We hope to write about that in a week or two.

Some changes have happend with our bluetooth component. They are:
- For our project we continue to work with Bluetooth Bee module.
- For our diploma thesis we need to use Bluetooth Mate Silver module (http://www.sparkfun.com/products/10393 ).

So, as you may assume, this time our main topic is to describe Bluetooth Mate Silver.

Bluetooth Mate Silver

Hardware Explanation

First, hold the Bluetooth Mate in you hands and feel the power that courses through it. Flip it over and get a good look at the entire device. Now back to the top. A major chunk of the Mate is Roving Network's RN-42 Bluetooth module. The RN-42 is the brains of the device, it's what handles all the nasty Bluetooth protocol, so you don't have to, and it's what you'll talk to over a hard-wired serial connection. Much more on the RN-42 later. The blue rectangle connected to the RN-42 is an antenna, just keep in mind that the antenna's there, don't go trying to interfere with it.



Next to the RN-42 are a number of voltage regulators, transistors, resistors, etc. which are all used to shift the voltages that come into and go out of the RN-42. The voltages that go into the RN-42 can't stray too far from 3.3V, so we've put all that level-shifting circuitry on there so you can use it at a more Arduino-accessible 5V. Enveloped by the level-shifting stuff are twoLEDs that indicate the status of the Bluetooth Mate. Never forget the importance of Blinkies! The green 'Connect' LED will illuminate when a wireless connection is formed, and the red 'Stat' LED blinks at varying speeds to indicate the state of the RN-42.




Finally, the main, six-pin header of the Bluetooth Mate has everything you'll need to power the device, and send and receive data. Labels on the bottom of the board read 'GND', 'CTS-I', 'VCC', 'TX-O', 'RX-I', and 'RTS-O'. GND and VCC are your power pins, RX-I and TX-O are the receive and transmit lines, and RTS-O and CTS-I are flow control signals, which can really be ignored in most applications.


With the Mate flipped over, you may also notice a seventh through-hole floating in the middle of the board labeled 'PIO6'. Hopefully you can forever ignore this pin, as its main function involves resetting the Bluetooth Mate to its factory defaults. If your Mate ever finds itself in an unknown state, follow the directions below to reset it.

Assembly

Happily, most of the assembly is done for you; you don't need to learn how to solder SMD components just yet. However, before you can begin using the Bluetooth Mate, you'll need to solder something into the six plated-through-holes to form a good, solid electrical connection. What you solder into the holes depends mostly on what you're going to connect the Mate to. If I'm going to connect my Mate to an Arduino Pro, I usually like to throw a right-angle female header on there. Another good option, which makes the Mate breadboard-compatible, is male-headers. A third, ever-reliable option is to solder wires directly to the holes. If you do go with wires make sure you don't short any of them together.



Powering the Bluetooth Mate

The Bluetooth Mate was designed to work seamlessly in both 3.3V and 5V systems. The voltage supplied to the VCC/GND pins can be anywhere between 3.3V and 8V. Voltages on the input serial and control signals (RX-I and CTS-I) can be anywhere between 3.3V and 5V. The output signals (TX-O and RTS-O) will range from 0V for a 'LOW' logic level, and VCC for a 'HIGH'. That means if you power the Mate at 6V, the TX and RTS signals will output up to 6V. The current consumption of the Mate depends on what it's doing at the time. Current consumption can be as low as 0.026mA when the device is asleep, and as high as 50mA when data is being transmitted.

Connecting to the Bluetooth Mate

There's two subjects we need to cover in this section. Two separate devices are required to use the Bluetooth Mate: one is hardwired directly to the Mate, and the second is another Bluetooth device that can speak to the Mate wirelessly.

First, the hardwire-connected device. The Bluetooth Mate communicates via an asynchronousserial stream at speeds between 9600 bps and 115200 bps. By default the baud rate will be set to 115200 bps, and you'll rarely need to change that baud rate. This is a TTL-level serialsignal, make sure you don't confuse that with RS-232, voltages should be between 3.3V and 5V. There are loads of devices you could hardwire to the Bluetooth Mate. An Arduino Pro (or the Mini version) is a great option, specifically because the Mate was designed to interface directly with the 6-pin FTDI header. Keep your mind open, though; the Mate will work with just about any microcontroller or device that has a serial port.




Commanding the Bluetooth Mate

Control of the Bluetooth Mate is achieved through a series of AT commands, all of which are documented in the RN-42 Advanced User Manual. I'd encourage you to read through that and the RN-42 datasheet, both are delightful reads! The commands are split into five categories: set, get, change, action, and GPIO commands. The datasheet details everyone of these commands, I'd recommend at least skimming over Appendix B of the User Manual, beginning on page 29.
Backtracking a bit though, before you can send any commands, you first need to entercommand mode. This is done by sending the Mate the default configuration detect string of "$$$" (without the quotes). However, there is one little obstacle to watch out for when entering command mode in the configuration timer. The config timer begins counting as soon as the Bluetooth Mate is turned on, and once it's done counting, you'll be unable to enter config mode unless you cycle power. By default the config timer is set to 60 seconds, however this can be adjusted, or even turned off (that's the ticket).
With a little ingenuity, we can use the Arduino as a medium between us and the Bluetooth Mate to send and receive commands. Here's a small sketch that relays data between the Arduino Serial Monitor and a Bluetooth Mate. Connect the Bluetooth Mate to the Arduino as follows:








The sketch makes use of the NewSoftSerial library, which you can download here. Once downloaded, unzip the library into the "libraries" folder, where all of your Arduino sketches are saved. After extracting the library, restart Arduino if you've already got it running.
At the beginning of the sketch, the Arduino enters the command mode string, and temporarily changes the Bluetooth Mate's baud rate to 9600 bps. Remember this is temporary, so when power is cycled, the Mate will default back to 115200 bps. The code for this is handy, and could be used for any command that you automatically want to send from the Arduino to the Mate.


The loop of the sketch simply checks to see if either the Bluetooth Mate or the Serial Monitor have sent any data to the Arduino. If so, it'll relay the data sent from one device to the other.




With the code uploaded, and everything hooked up accordingly, open up the Serial Monitor. Make sure the baud rate is set to 9600. One final annoyance means you'll have to fudge around with the dropdown menu to the left of the baud rate selection as well. It should initially be set to “No line ending”. First, let's enter command mode by typing “$$$” (without the quotes), and click “Send”. You should see the Bluetooth Mate respond with “CMD”, and you'll notice the red Stat LED blinking much faster, this all indicates that the Mate is in command mode.




Once you're in command mode, you'll again need to fudge with the “No line ending” dropdown, change that to “Newline”. The basis of all this is that the RN-42 module expects a newline character after every command, except for the command mode string. Annoying, but we'll deal.

Now let's try entering a command. The GET commands are a good place to start, they'll display settings, status, or other information that might be helpful. Try sending the Display basic settings command by typing “D”, and pressing “Send”. This will trigger a response from the Bluetooth Mate that details, among other things, the baud rate settings, the name, and the address (BTA) of the device. The address is something you should take note of, it can either be gotten from this command, or by taking a gander at the module's label, next to the “MAC NO”. Each Bluetooth Mate has a unique address which can't be changed. Try sending the other get commands, and see what information you can retrieve from the Mate.



After sending the “D” command, you may have noticed your Bluetooth Mate has it's own name, in addition to the address. Unlike the address, this name can be changed to whatever you'd like. By default it'll be RN42-XXXX, where XXXX is the last four digits of the address. Let's give a SET command a whirl, by providing your Bluetooth Mate with its own unique name. The SN,name command is used to set the name of the Bluetooth Mate, where name  is any set of up to 20 characters. Think up a unique name, and assign it to your Mate. After sending the SN command, the mate should respond with an “AOK”. Now if you send the D command, you should see your new name listed next to the “BTName” setting.


Be careful with the SET commands, only change something if you're sure it won't negatively affect the Mate, or your ability to communicate with it. If you change something you don't think you should have, send the “SF, 1” command to reset everything back to its default. Another handy command, if you're lazy like me, is "ST,0", which turns the config timer off. Remember that any setting you modify will be saved to the Bluetooth Mate's memory, and will be retained upon loss of power.

Finally, it's time for some action. Among other things the Bluetooth Mate's ACTION commands can be used to find other bluetooth devices, connect to them, and disconnect from them. Usually after entering command mode, I like to send the inquiry scan (I,name,COD) command to see what other bluetooth modules are out there. COD  (class of device) in the inquiry command is optional, and I never use it. Time is the number of seconds the Mate will take to look for other modules, which defaults to 10. If you just type “I” and click send, the Mate should respond with a “Inquiry, COD=0”, and then after ten seconds it'll respond with any bluetooth modules it found. If it found any modules, it will print their information as BT address, BT name, COD.



If you found any modules, you can try sending the connect command (C,name) to connect to one of them. My Bluetooth Mate found my BlueDongle USB Modem, as well as someone's computer. By sending the C,00066602D50B command, I can try to connect to the BlueDongle. After sending the connect command, the Mate will respond with “TRYING”. “TRYING” will be followed by either “CONNECT failed”, the meaning of which should be pretty apparent, or the connection will be successful! After a successful connection any characters sent from one bluetooth device will be sent to the other, and vice-versa. To disconnect, you'll need to re-enter command mode (don't forget to set to “No new line”), and send the “K,” command.

Нема коментара:

Постави коментар