Bluetooth - mozilla/project_haiku.iot GitHub Wiki

#Bluetooth

###Using BlueFruit LE SPI Shield

BlueFruit LE SPI Shield is a Bluetooth 4.0 BLE module from Adafruit that uses [nRF15822 ARM Cortex M0 core] (http://www.nordicsemi.com/eng/Products/Bluetooth-Smart-Bluetooth-low-energy/nRF51822) running at 16MHz.

All Adafruit Bluetooth modules are slave/peripheral only and are designed to work effectively with smartphone/computer as master module. There is no way for a BlueFruit module to detect other BlueFruit modules or central devices in range, they can only send their own advertising data out and wait for a connection request to come in.

We used HID Keyboard example with Android Phone and BLE SPI to test. After flashing Arduino with the example sketch here, go to your phone's Bluetooth settings to pair your device. Then open an application that accepts keyboard input (e.g. Google docs). See [demo video here] (https://www.youtube.com/watch?v=Jwpsn-43Zv8)

Once the BlueFruit Keyboard is connected to your Smart Phone, you can send text from serial monitor to your application on phone.

BlueFruit Shield SPI is designed for very short range and will work best in the 5-6 meter or less range for reliable communication. Complete list of AT commands available for Adafruit BLE modules inside [datasheet here] ( https://learn.adafruit.com/downloads/pdf/introducing-the-adafruit-bluefruit-spi-breakout.pdf)

Different chips are designed to run at different levels of maximum power, and type of transmitter. Each Bluetooth module will have a maximum amount of transmit power (AT+BLEPOWERLEVEL), like +4 dBm, and you can run up to that maximum (using more supplied power to the module). The higher the transmit power, the longer the range.

You need to be able to receive the signal from the other end. RF devices normally measure signal strength using RSSI, which stands for Received Signal Strength Indicator, which is measured in dBm.

Each module will have a corresponding receive sensitivity measured using AT+BLEGETRSSI command, -85 dBm is less powerful than -60 dBm. AT+BLEGETRSSI returns zero if its not connected to external device. This number is fixed for each module and not to be adjusted. A high transmit power with a bad receiver sensitivity doesn't help.

AT+BLEGETRSSI for Bluefruit SPI shield returns -101dBM indoors at distance of 6-8 meters. At distance of 1 meter AT+BLEGETRSSI showed -67 dBM. Increasing the AT+BLEPOWERLEVEL from 0 to 4 dBm showed improvement in range from 6 meters to 10 meters. The range is impacted by indoors, or outdoors with obstructions.

Bluetooth range between modules is influenced by many factors such as antenna orientation, the antenna design on the phone, transmit power on the sending node (slave), competing traffic in the same 2.4GHz bandwidth, obstacles between end points, etc.

Link to some of the [Bluegiga Bluetooth long range products] (http://www.mouser.com/new/Bluegiga-Technologies/bluegiga-ble121lr/ )

###Using [HC-05 ZS-040/GW-040] (http://www.amazon.com/Wireless-Bluetooth-Serial-Transceiver-Module/dp/B00INWZRNC?ie=UTF8&psc=1&redirect=true&ref_=oh_aui_detailpage_o00_s00) as master/slave

To explore bluetooth communication between devices as master slave, we used HC-05 module. HC-05 is Wireless Bluetooth Serial Transceiver Module that can be set as Slave or Master. We used two of these hooked to respective Arduino. The Arduino communicates with the HC-05 using the SoftwareSerial ports while the Arduino communicates with the user via the Serial Monitor.

Making these wireless bluetooth module communicate is a two step process

Step 1: Configure respective HC-05 module as slave and master in full AT mode

HC-05 works in two modes, full AT command mode where we can send AT commands to it and communication or data mode where it receives and transmits data to another bluetooth module.

By default all HC-05 modules are slave and when itโ€™s powered on it starts in communication mode. Using AT commands the module can be configured as we like.

ZS-040 can be changed into AT command mode by two ways a) pressing tiny switch next to EN pin before powering it on b) Ensuring Pin 34 is set to High. When HC-05 sees Pin 34 is in high state it automatically starts in Full AT mode.

Option a) goes into AT mode but not all AT command works e.g. AT+INQ that's required to search for all bluetooth devices works in full AT mode. That's why for configuring master bluetooth module I found it's useful to solder a jumper wire to pin 34 and connect it to Arduino GPIO pin 4 and set it to high inside [Arduino sketch here] (https://github.com/mozilla/smarthome.iot/tree/master/Bluetooth/HC-05-Bluetooth-Module/Setup_Master_Slave/BL-Master-Pair-SoftwareSerial-AT-Mode)

More details on [how to setup your HC-05] (http://www.martyncurrey.com/connecting-2-arduinos-by-bluetooth-using-a-hc-05-and-a-hc-06-pair-bind-and-link/) in a way that it always connect to the same HC-06 or another slave HC-05 using AT+PAIR, AT+BIND, and AT+LINK commands.

For slave device, instead of HC-06, we used HC-05 as slave device flashed with [sketch here] (https://github.com/mozilla/smarthome.iot/tree/master/Bluetooth/HC-05-Bluetooth-Module/Setup_Master_Slave/BL-Slave-Pair-SoftwareSerial).

Step 2: [Communicate using bluetooth as master and slave] (http://www.martyncurrey.com/arduino-to-arduino-by-bluetooth/)

With Step 1, Two HC-05 modules are setup to pair every time they are powered on. Now we can flash respective Arduino with the [sketches here] (https://github.com/mozilla/smarthome.iot/tree/master/Bluetooth/HC-05-Bluetooth-Module/Communicate_Master_Slave) where master Arduino sends LED on and off command to slave. See [demo video here] (https://youtu.be/-UDbLo075_Y)

HC-05 uses bluetooth 2.0 protocol standards and open area transmission distance using HC-05 master and slave found is max 10 meters.