среда, 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.

Vital function monitoring


While working on our exam project, we decided to make a blog and share some ideas that helped us during our work. Our assignment was to make hardware configuration which measures heartbeat (puls), and body temperature. Hardware components which are included into solution are:

1) Arduino LilyPad chip
2) Heartbeat sensor
3) Temperature sensor
4) Bluetooth module (Bluetooth Bee + XBee Shield)
5) Devices that use Android OS (great thanks to our mentor from the faculty who provided us Asus Eee Pad Transformer TF101 to work on it and test software solution during project)

Arduino LilyPad chip

Basic hardware part of our configuration is Arduino LilyPad chip, which can be seen on picture 1.

Picture 1. LilyPad Ardino Simple Board

This is the LilyPad Arduino Simple Board. It's controlled by an ATmega328 with the Arduino bootloader. It has fewer pins than the LilyPad Arduino Main Board, a built in power supply socket, and an on/off switch. Any of our LiPo batteries can be plugged right into the socket. The Simple board is designed to streamline your next sewable project by keeping things simple and giving you more room to work  and eliminating the need to sew a power supply. Some other usefull information about LilyPad chip may be found on  http://arduino.cc/en/Guide/ArduinoLilyPad

HeartBeat sensor

Function of this module is to measure heart pulse. During our work we have found several solutions and finally decided for this:


Picture 2. Hardware arhitectureof heartbeat sensor

The sensor uses two simple components, an IR LED and an IR phototransistor. Both components are powered by the Arduino's 5V output and one analogue input reads the voltage across the phototransistor.

1) 10KOhm resistor
2) 220Ohm resistor
3) IR LED(ZD1945)
4) IR Phototransistor(ZD1950)
The main idea is that when your heart beats you have a quick fast rush of blood into tiny blood vessels close to your skin which makes it less transparent. This effect is easiest to observe on your finger tips or earlobe. So the IR emitter and phototransistor are placed next to each other (not much light goes through the side of the emitter!) and I put my finger on top. Light from the IR emitter illuminates my skin and is reflected into the phototransistor.

The phototransistor is connected to the Arduino in a similar way to a potentiometer. One lead is connected to +5V and the other to ground. The +5V lead is also connected to an analogue input on the Arduino. When the phototransistor receives more IR light it becomes more resistive and a lower voltage is detected by the analogue input.

More information about this, can be found at this address:

Temperature sensor

Function of this module is to measure body temperature. Image of this temperature sensor is on picture 3.

Picture 3. LilyPad Temperature Sensor 

Detecting temperature changes has never been easier. The MCP9700 is a small thermistor type temperature sensor. This sensor will output 0.5V at 0 degrees C, 0.75V at 25 C, and 10mV per degree C. Doing an analog to digital conversion on the signal line will allow you to establish the local ambient temperature. Detect physical touch based on body heat and ambient conditions with this small sensor.

LilyPad is a wearable e-textile technology developed by Leah Buechley and cooperatively designed by Leah and SparkFun. Each LilyPad was creatively designed to have large connecting pads to allow them to be sewn into clothing. Various input, output, power, and sensor boards are available. They're even washable!
More detail information (for example Datasheet, prices and users reviews, etc.) may be found on 

Bluetooth modul

Bluetooth Bee is a simple breakout board for the Bluetooth Module, which designed to DIP model (http://www.sparkfun.com/products/8550), compatible with existing Xbee sockets, designed for transparent wireless serial connection setup. Bluetooth Bee can be configured to Master, Slave or Loopback three different modes(HC-06 just be Master/Slave, coulud be customized), and it will connect to or be connected by other devices that support SPP protocol per configuration, and it is a suitable substitute for most applications. Bluetooth Bee is an easy to use Bluetooth SPP (Serial Port Protocol) module, designed for transparent wireless serial connection setup. This is a fully qualified Bluetooth V2.0+EDR (Enhanced Data Rate) 3Mbps modulation with complete 2.4GHz radio transceiver. It uses CSR Bluecore4-external single chip Bluetooth system with CMOS technology and with AFH (Adaptive Frequency Hopping). 
  • HC-03/HC-05 could be configured to Master/Slave by user.
  • HC-04/HC-06 just be Master or Slave when the factory, cann't be configured by user.
Model: Bluetooth Bee - Base on HC-05
Picture 4. Bluetooth Bee module serial HC-05

XBee shield

The XBee shield provides 3 optional hardware interface, which determine how the shield’s serial communication connects to the serial communication between microcontroller (ATmega8 or ATmega168) and FTDI USB-to-serial chip on the Arduino board. So it is necessary to explain the XBee shield work mode first.

The XBee shield has 4 row jumpers figure2. DIN corresponds with Bluetooth Bee’s RX, DOUT corresponds with Bluetooth Bee’s TX, TX_H corresponds with Arduino’s TX(D0), RX_H corresponds with Arduino’s RX(D1), D2 corresponds with Arduino’s D2, D3 corresponds with Arduino’s D3. We select work mode by DIN and DOUT freedom match with TX_H, TX_H, D2, D3.

 Picture 5. Schematic of XBee Shield

Bluetooth Bee direct use Arduino main board’s UART(TX/RX) connect to PC. If you want find out more information about this, visit (http://www.seeedstudio.com/wiki/Bluetooth_Bee).
Schematic - How to connect Bluetooth Bee with Xbee shield

 Picture 6. Whole Bluetooth moduls connected


Well, that's all for our first post. In the next post we will try to explain software application which is run on devices connected to hardware configuration, also we will try to post an image which shows how Android Lilypad chip, temperature sensor, heartbeat sensor and bluetooth modul are connected to each other and make whole hardware part of our project.