BGLib on the BLE-Shield v1.0.0

Hello everyone,

I should have done this earlier, but good things need some time. As you might know, Jeff Rowberg @SectorFej as a BGLib Implementation created and published on github: https://github.com/jrowberg/bglib which runs on Arduino. You need a special firmware for the BLE112 module to be flashed which is available on his github repository as well. The BLE112 needs to be wired to the Arduino as he describes in his Arduino Sample sketches:

// BLE112 module connections:
// - BLE P0_4 -> Arduino Digital Pin 2 
// (BLE TX -> Arduino soft RX)
// - BLE P0_5 -> Arduino Digital Pin 3
// (BLE RX -> Arduino soft TX)

People which are using my BLE-Shield and doing some BGScript development on the BLE-Shield will see that this is the same UART wiring the BLE-Shield uses to communicate with the Arduino. So it is 100% compatible with Jeff’s implementation. Since the BLE-Shield is not using any hardware wakeup or host wakeup lines, you need to use the firmware “BGLib_U1A1P_38400_noflow” and flash it to the BLE-Shield v1.0.0

Please be aware of the fact, that the Bluegiga’s  Bluetooth Smart v.1.1.1 Software Development Kit needs a License Key for old BLE112 modules to be set while flashing the firmware. You can easily request this license key using the BLE Update application provided by Bluegiga. The illustration below shows a BLE-Shield, where I already added the License to. If you have a Shield without the license, please get one while contacting Bluegiga’s support.

Without the license key you will be able to flash the firmware, but the radio of the BLE112 is turned off 🙁

What you now have to do is, download the Arduino folder from Jeff’s github Repository and place it into your sketches library folder as described on the following link: http://arduino.cc/en/Guide/Libraries

Now open your Arduino IDE.

Select File -> Examples -> BGLib -> Examples -> BGLib_scanner

In the first lines of code where the SoftwareSerial class is initilalized make sure that you are using pin 2 and 3:

SoftwareSerial bleSerialPort(2, 3); // RX, TX

and make sure that the BLE-Shields S1 switch is set to Tx2/Rx3 Position.

Look in the setup() method and simply remove or comment out these lines:

// ONLY enable these if you are using the <wakeup_pin> 
// parameter in your firmware's hardware.xml file
ble112.onBeforeTXCommand = onBeforeTXCommand;
ble112.onTXCommandComplete = onTXCommandComplete;

If you leave them in, the sketch will NOT work, since the Firmware of the shield and the wiring of the Shield does not support the wakeup pin.

I’m using the BLE-Shield with the BGLib firmware on an Arduino UNO.

Lets compile and take a look at the console. If you set the baudrate to 115200 you should see the following:

BLE112 BGAPI Scanner Demo
Operations Menu:
0) Reset BLE112 module
1) Say hello to the BLE112 and wait for response
2) Toggle scanning for advertising BLE devices
Command?

Try 1) first in order to test the proper communication with the Stack:

--> system_hello
<-- system_hello

Ok, looks good. If you encounter a timeout, please press the reset button on the Shield once and try again.

If you select option 2), the Shield starts to discover….

--> gap_set_scan_parameters: { scan_interval: 0xC8, 
                                  scan_window: 0xC8, 
                                  active: 1 }
<-- gap_set_scan_parameters: { result: 0 }
--> gap_discover: { mode: 2 (GENERIC) }
<-- gap_discover: { result: 0 }
### gap_scan_response: { rssi: -59, packet_type: 0, 
                         sender: D5F7656277FD, 
                         address_type: 1, bond: FF, 
                         data: 0201060408734E66 }
.
.
.
.

Well and that’s it. BGLib is setup and running on the BLE-Shield v1.0.0. I already started to implement an Arduino Library for the BLE-Shield in order to make the use of BGLib an easy task for you. Stay tuned!

Thanks for reading,

Michael.