Skip to content

Bluetooth Low Energy TinyShield (ST) Tutorial

This tutorial will cover the basic operation of the BLE TinyShield using a standard TinyDuino and a Bluetooth-enabled device, such as a smartphone or tablet. To communicate with the stack, we will use the nRF UART v2.0 Android application and the nRF Connect iOS application. Click the link to download the application to your mobile device before starting the tutorial.

Once that is finished, we will start by adding files to our Arduino environment.

To learn more about the TinyDuino Platform, click here


Description

Our new Bluetooth Low Energy (BLE) TinyShield combines both master and slave modes into one module! This TinyShield allows you to connect your TinyDuino system to any compatible iOS or Android device using Bluetooth Low Energy (also known as Bluetooth Smart and Bluetooth 4.1). This technology is great for low power sensors and accessories and works with most modern phones. This shield acts as a drop-in hardware and software replacement for NRF8001 (Nordic) TinyShield projects. Unlike previous BLE TinyShields, your Arduino sketch code can modify your module's connection parameters directly.

This TinyShield is based around the BlueNRG-MSchipset by STMicroelectronics, which comes in the SPBTLE-RF module. The TinyShield also includes power supply and level shifters on the board, so you can run your TinyDuino from 3.0V – 5V.

Since the SPBTLE-RF module supports both master and slave modes, you can communicate both with a Bluetooth LE device (i.e. a smartphone) and another BLE TinyShield or other BLE module with slave mode. If you have one of our previous BLE models, a BlueGiga or a Nordic, it can communicate with those as well.

To see what other TinyShields are compatible with this TinyShield, see the TinyShield Compatibility Matrix

Technical Details ST SPBTLE-RF Specs:
  • Fully Bluetooth v4.1 compliant
    • Supports master and slave modes
    • Multiple modes supported simultaneously
  • Integrated Bluetooth Smart stack
    • GAP, ATT/GATT, SM, L2CAP, LL, RFPHY
    • Bluetooth Smart profiles
  • Radio performance
    • Integrated chip antenna
    • TX power: +4 dBm
    • Receiver sensitivity: -88 dBm
    • Range: up to 20m
TinyDuino Power Requirements
  • Voltage: 3.0V - 5.5V 
  • Current:
    • Transmit: 10.9mA (+4 dBm)
    • Receive: 7.3mA (Standard mode)
    • Down to 8.7µA average for 1s connection interval
    • Down to 14.5µA average for 500ms connection interval
    • Down to 26.1µA average for 250ms connection interval
    • Down to 119.9µA average for 50ms connection interval
    • Deep Sleep Mode: 1.7µA
    • Due to the low current, this board can be run using the TinyDuino coin cell option
Pins Used

SPI Interface used

  • 2 - SPI_IRQ: This signal is the interrupt output from the SPBTLE-RF to the TinyDuino.
  • 9 - BT_RESET: This signal is the reset signal to the SPBTLE-RF.
  • 10 - SPI_CS: This signal is the SPI chip select for the SPBTLE-RF.
  • 11 - MOSI: This signal is the serial SPI data out of the TinyDuino and into the radio transceiver.
  • 12 - MISO: This signal is the serial SPI data out of the radio transceiver and into the TinyDuino.
  • 13 - SPI_CLK: This signal is the serial SPI clock out of the TinyDuino and into the radio transceiver.
Dimensions
  • 20mm x 20mm (.787 inches x .787 inches)
  • Max Height (from lower bottom TinyShield Connector to upper top TinyShield Connector): 5.11mm (0.201 inches)
  • Weight: 1.49 grams (0.053 ounces)

Notes

  • The interrupt signal can be changed from pin 2 to pin 3 by removing resistor R2 and soldering it to position R3.

Materials

TinyZero and Bluetooth Low Energy TinyShield

Hardware

Software

  • Arduino IDE
  • STBLE library Example Program (This zip folder contains both the library and the example program we will be using)
  • A phone application that can interface with Bluetooth objects:
    • Android: nRF UART v2.0
    • iOS: nRF Connect
    • You can look for a different app, these were just the easiest (and free-est) we could find and test.

Hardware Assembly

All you have to do here is attach your processor board to the Bluetooth Low Energy TinyShield, as well as plugging in an optional battery if you intend to go wireless with your project:


Installing the STBLE Library

Click here to download STBLE.zip and the example program. After completing the download, open the Arduino IDE.

Select Sketch > Include Library > Add .ZIP Library. Navigate to your Downloads folder and select the folder STBLE.zip. Select "Open." The IDE should display a message that the library was added successfully.


Upload the Example Code

Restart the Arduino IDE (close it and reopen). Select File > Examples > STBLE > UARTPassThrough. This should open the code below:

Code
//-------------------------------------------------------------------------------
//  TinyCircuits ST BLE TinyShield UART Example Sketch
//  Last Updated 2 March 2016
//
//  This demo sets up the BlueNRG-MS chipset of the ST BLE module for compatiblity 
//  with Nordic's virtual UART connection, and can pass data between the Arduino
//  serial monitor and Nordic nRF UART V2.0 app or another compatible BLE
//  terminal. This example is written specifically to be fairly code compatible
//  with the Nordic NRF8001 example, with a replacement UART.ino file with
//  'aci_loop' and 'BLEsetup' functions to allow easy replacement. 
//
//  Written by Ben Rose, TinyCircuits http://tinycircuits.com
//
//-------------------------------------------------------------------------------


#include <SPI.h>
#include <STBLE.h>


//Debug output adds extra flash and memory requirements!
#ifndef BLE_DEBUG
#define BLE_DEBUG true
#endif

#if defined (ARDUINO_ARCH_AVR)
#define SerialMonitorInterface Serial
#elif defined(ARDUINO_ARCH_SAMD)
#define SerialMonitorInterface SerialUSB
#endif


uint8_t ble_rx_buffer[21];
uint8_t ble_rx_buffer_len = 0;
uint8_t ble_connection_state = false;
#define PIPE_UART_OVER_BTLE_UART_TX_TX 0

void setup() {
  SerialMonitorInterface.begin(9600);
  while (!SerialMonitorInterface); //This line will block until a serial monitor is opened with TinyScreen+!
  BLEsetup();
}


void loop() {
  aci_loop();//Process any ACI commands or events from the NRF8001- main BLE handler, must run often. Keep main loop short.
  if (ble_rx_buffer_len) {//Check if data is available
    SerialMonitorInterface.print(ble_rx_buffer_len);
    SerialMonitorInterface.print(" : ");
    SerialMonitorInterface.println((char*)ble_rx_buffer);
    ble_rx_buffer_len = 0;//clear afer reading
  }
  if (SerialMonitorInterface.available()) {//Check if serial input is available to send
    delay(10);//should catch input
    uint8_t sendBuffer[21];
    uint8_t sendLength = 0;
    while (SerialMonitorInterface.available() && sendLength < 19) {
      sendBuffer[sendLength] = SerialMonitorInterface.read();
      sendLength++;
    }
    if (SerialMonitorInterface.available()) {
      SerialMonitorInterface.print(F("Input truncated, dropped: "));
      if (SerialMonitorInterface.available()) {
        SerialMonitorInterface.write(SerialMonitorInterface.read());
      }
    }
    sendBuffer[sendLength] = '\0'; //Terminate string
    sendLength++;
    if (!lib_aci_send_data(PIPE_UART_OVER_BTLE_UART_TX_TX, (uint8_t*)sendBuffer, sendLength))
    {
      SerialMonitorInterface.println(F("TX dropped!"));
    }
  }
}

With your processor board plugged in and powered on, upload the code. Then, open the Serial Monitor. You can find the option to open the Serial Monitor under the Tools tab, or you can directly open it by pressing the magnifying glass icon in the upper right corner of the IDE.

Your Serial Monitor should display something like this:

Put your phone in Discovery Mode for Bluetooth, because it's time to send some data between your phone and the TinyDuino stack!


Using the Android app

Search for, and download the nRF UART v2.0 bluetooth app.

Open the nRF UART v2.0 application on your device. Enable Bluetooth connection.

Follow the images below to connect to the TinyDuino stack. The TinyShield should always appear as "BlueNRG."

Once the two devices connect, your Serial Monitor should display something similar to the image below. Let's send a number, like '54' to our nRF UART ap. Type it into the Serial Monitor and press Send.

The application should display the message "RX: 54."

Now, we'll send our TinyZero a number. Type '108' into the application text box and tap Send.

The Serial Monitor should display the number 108. The number preceding it with a colon indicates the number of characters that were sent. No more than 20 characters may be sent between the devices at once.


Using the iOS app

Search for, and download the application nRF Connect. Make sure your phone is in discovery mode (Bluetooth is on).

Open up nRF Connect.

What the nRF Connect app looks like (I will definitely get to those emails at some point)

With the code running on the TiynDuino stack, the BLE TinyShield is discoverable. You should be able to see it on your app. Your device should have the name BlueNRG, click CONNECT:

Opening Screen on nRF Connect

You should see a new line on the Serial Monitor that looks like "Connected to device:XX-XX-XX-XX-XX-XX". Now you can send commands to the servo with the app by selecting the UART Service, and then selecting the up arrow symbol on the Nordic UART RX option: 

The Devices and Characteristics pages on the nRF Connect app

With the text box open, you can now send commands with the app to the Bluetooth TinyShield. Try sending '800' and '2200':

Send text from app to hardware

The number preceding it with a colon indicates the number of characters that were sent. Only 20 characters may be sent between the two devices.

To send data from the TinyDuino stack to your phone, type into the Serial Monitor and press Send.

Now all you have to do is come up with a project that you can control from your phone!


Contact Us

If you have any questions or feedback, feel free to email us at info@tinycircuits.com or make a post on the forum.

Show us what you make by tagging @TinyCircuits on Instagram, Twitter, or Facebook so we can feature it!

Thanks for making with us!


Downloads