0% found this document useful (0 votes)
66 views60 pages

Bluefruit LE Connect For iOS and Android: Created by Collin Cunningham

Blue-tooth user guide

Uploaded by

Louis Bellanca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views60 pages

Bluefruit LE Connect For iOS and Android: Created by Collin Cunningham

Blue-tooth user guide

Uploaded by

Louis Bellanca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

Bluefruit LE Connect for iOS and Android

Created by Collin Cunningham

Last updated on 2020-02-04 09:42:18 AM UTC


Installation and Setup

The Bluefruit LE Connect app provides iOS & Android devices with a variety of tools to communicate with Bluefruit LE
devices. These tools cover basic communication and info reporting as well as more project specific uses such as
Arduino Pin Control and a Color Picker.

The iOS app is a free download from Apple's App Store (https://adafru.it/ddu). It requires iOS 11.3 or later and works on
iPhones, iPads, and iPod Touches.

The Android app is a free download from the Google Play Store (https://adafru.it/f4G). It requires Android 4.4 or later.

The app is compatible with these BLE devices from Adafruit, and possibly more:

Bluefruit LE nRF8001 Breakout (http://adafru.it/1697)


Bluefruit LE Friend (http://adafru.it/2267)
Flora Wearable Bluefruit LE Module (http://adafru.it/2487)
Adafruit Bluefruit LE SPI Friend (http://adafru.it/2633)
Adafruit Bluefruit LE Micro (http://adafru.it/2661)
Adafruit Feather 32u4 Bluefruit LE (https://adafru.it/keO)
Adafruit Feather M0 Bluefruit LE (https://adafru.it/t6a)
Adafruit Feather nRF52 Bluefruit LE - nRF52832 (https://adafru.it/vAx)
Adafruit Feather nRF52840 Express (https://adafru.it/DLQ)

First off - install the app from one of the App stores listed above if you haven't already.

Enable Bluetooth
If Bluetooth is disabled on your device, enable it by going to Settings->Bluetooth on your iOS device, or the analogous
setting on your Android device.

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 4 of 62


Enable Location Services
If you plan to use the app to send location/GPS data to Bluefruit LE, enable Location Services. Enable it on iOS
using Settings->Privacy->Location Services.

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 5 of 62


Scan for
Devices
On launch, the app will automatically begin to scan for nearby Bluetooth LE devices. Devices are presented in a table
view in the order in which they were discovered.

Don't forget to turn on Bluetooth on your device! Airplane Mode turns off BLE.

iPhone
The following images depict the app when used on the iPhone. The Android app looks similar.

The device list will display all BLE devices discovered by the app (not just Bluefruit hardware) - so you may see a quite
a few "" entries for devices that don't advertise their name, as seen above.

To refresh the list and start a new scan, simply swipe down on the current list.
Each device's signal strength is displayed in the left side of its row.

If you tap on the device entry (not on Connect), you'll see more detail about a particular device:

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 6 of 62


iPad
The following images depict the app when used on the iPad

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 7 of 62


Tap the middle of a device's table row to reveal its relevant advertisement data.

Any device listed with a "Connect" button at the right can be accessed in Info mode.
Any device listed as "UART Capable" can be used with all modes - Info, UART, Pin I/O, & Controller.

To use the Bluefruit Connect app with your device it must be "UART capable"! All Adafruit BLE devices
implement the UART interface, but other devices may not

Connect
Tap the Connect button on the UART capable list entry you wish to use and choose a connection mode from the menu
that appears.

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 8 of 62


Troubleshooting

If you’re having trouble finding your Bluefruit device in the scanned peripherals list, ensure the board is powered and
not paired with any other BLE devices. If the problem persists, it could be due to caching issues in the iOS or Android
operating system. For a fix, try the following:

Cycle Bluetooth - Turn your mobile device’s Bluetooth radio off and on again in the Settings app.
Relaunch App - Quit the Bluetooth LE Connect app and restart it. (instructions for iOS (https://adafru.it/DMn) &
Android (https://adafru.it/DMo))
Cycle Power - Restart your mobile device by powering it off and restarting.

Doing one or both of the above solves most peripheral scanning issues. If you're still having trouble, try searching the
Adafruit Support forum (https://adafru.it/DMl) for your issue.

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 9 of 62


Features
Even though the Bluefruit Connect app only uses UART as the transport for sending and receiving data to/from your
BLE device, it has multiple interaction modes

Each of these modes can do different things and let you interact in a unique way.

Don't forget! All of these modes use the UART Service, but present the data in a different way. On the hardware side,
your firmware will have to know what it is expecting and sometimes may need to parse the data coming back from the
app.

For example, if using the Color Picker, the app will send the color data in a mini packet. If using the button controller,
you'll get button presses/releases in packets instead.

Available Modes:
Info (https://adafru.it/BYg)
UART Terminal Mode (https://adafru.it/xSF)
MQTT (https://adafru.it/yb7)
Plotter (https://adafru.it/xTa)
Controller (https://adafru.it/iCI) (Data Streaming (https://adafru.it/DN9), Control Pad (https://adafru.it/DN9), and
Color Picker (https://adafru.it/DN9))
AHRS/Calibration (https://adafru.it/Gge)

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 10 of 62


Updates (https://adafru.it/BYh)
Image Transfer (https://adafru.it/Gjc)

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 11 of 62


Info
Connecting to a peripheral in Info mode will display its Generic Attribute Profile (GATT) in the form of a table.

This mode is available for all connectable BLE devices and can be helpful for learning, troubleshooting, and
general curious snooping.
Tapping on a service row will reveal that service's included characteristics.

To learn more about Bluetooth Services & Characteristics, be sure to check out the Introduction to Bluetooth Low
Energy guide (https://adafru.it/iCp).

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 12 of 62


UART Terminal
The UART Terminal mode provides a classic 'serial terminal' interface for sending and receiving strings from a Bluefruit
LE device.

It's perfect for sending and receiving data without any interpretation.

Note: This mode can be used in conjunction with Bluefruit LE Friend's Command mode (https://adafru.it/iCO) to
configure or get additional info about the device.

Main Window

The main log window is in the middle, and will display data both received and, if Echo is on, sent.

Echo
Toggle the Echo switch in the settings the upper right to also display outgoing data sent from the app.

Data received from the remote BLE device appears in red.

Data sent from the app appears in blue.

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 13 of 62


ASCII / HEX
The display format of the log window can be controlled using the ASCII/Hex switch in settings in the upper right.

ASCII will do its best to translate the data to 8-bit human-viewable text characters.

Hex will give you 0xnn formatted bytes, still color coded.

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 14 of 62


Copy & Clear
Tapping Copy will copy all text from the log window to the iOS clipboard.

Tapping Clear will delete all text from the window.

Sending Strings

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 15 of 62


Tap the text field at the bottom of the screen to bring up the keyboard and begin composing a new string to
send.
Newline characters can be added using the return key.
Press the Send button to send the string over UART to your Bluefruit LE device.
To hide the keyboard, simply tap the log window while the keyboard is shown.

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 16 of 62


MQTT

MQTT stands for Message Queue Telemetry Transport. It's a protocol designed for low-bandwidth, high latency
networks. You can learn more about it here. (https://adafru.it/yqD)

The Bluefruit LE Connect App allows you to send and receive data using the MQTT protocol. For example - this can be
useful for making sensor readings from a Bluefruit device viewable on the web.

To access the MQTT settings, simply click the MQTT button in the top right corner of the UART Terminal.

Configuration
Firstly, you will need an adafruit.io (https://adafru.it/fJs) account in order to log and collect your data. You can make one
here (https://adafru.it/eZ8). To learn more about adafruit.io, check out the guide for it here (https://adafru.it/yqE).

Keep in mind that adafruit.io has a rate limit of 1Hz, so your project shouldn't send data faster than once per second.

Once you have your adafruit.io account set up, connect to your device using the Bluefruit LE Connect app and open the
UART mode. In the UART module, tap the "MQTT X" button at the top of the screen.

Under SERVER, enter "io.adafruit.com" as the server address and "1883" as the port.

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 17 of 62


Before filling in the necessary information, you will need to make 3 feeds on your adafruit.io account.

You can name them anything you like, but in this example will name the feed used to display data received by the
board as "rx"), and another used to display data entered through the app as "tx". We'll also have a third feed named
"output" which will display new data on the Bluefruit LE Connect app, called "output".

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 18 of 62


Under PUBLISH, enter in <username>/f/<respective feed name> for both UART RX and TX.

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 19 of 62


Under SUBSCRIBE, use your third output feed name as input.

Finally, under ADVANCED, use your adafruit.io username. Under Password, use your adafruit.io account's KEY. This can
be found under the settings of your adafruit.io account.

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 20 of 62


DO NOT USE YOUR ADAFRUIT.IO ACCOUNT PASSWORD. Simply use the generated key for your account.

Example
Here are some examples of feeds created using the Bluefruit LE Connect app in the same manor as described above.

Received Data

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 21 of 62


This is an example of an RX feed that presents data sent from an Adafruit Feather Bluefruit and is received by iPhone
using the Bluefruit LE Connect app via MQTT. The data is sent using an ASCII Numeric format similar to how plotter
data is sent. You can see the plotter feature here (https://adafru.it/xTa).

Written Data

This is an example of a TX feed that presents data sent from the Bluefruit LE Connect app to adafruit.io via MQTT.

Output Data

This is an example of an output feed that presents data created on adafruit.io sent to the Bluefruit LE Connect app via
MQTT

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 22 of 62


Plotter
The Plotter mode allows for users to visualize data received from Bluetooth LE compatible devices.

This data is sent from the Bluefruit device to the phone/tablet.

Feel free to test the plotting feature using this demo sketch (https://adafru.it/xTc)!

If you're running into issues sending data to the Plotter, try limiting throughput to 10 values per second.

Main Plotter View


The main plotter window does not display X and Y axes unless the Bluefruit Connect app receives the necessary data
to plot.

This is what the Bluefruit LE Connect app displays by default if there is no data to plot.

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 23 of 62


Once the required data is received, the plotting begins!

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 24 of 62


If your project utilizes multiple data streams, Bluefruit LE Connect will plot both for you! Above, notice that the graph on
the right shows a second set of data.

Formatting
The app interprets incoming numeric values in ASCII format. Separate data values should be followed by a comma or
tab character. Separate each set of values sent using a newline character or simply use ble.println() (which
automatically appends a newline char). This allows Bluefruit LE Connect to know when to plot the next set of values.

For example, a properly formatted stream of plotter values will look like this when viewed in the app's
UART terminal (https://adafru.it/xTd):

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 25 of 62


If you need to plot more data streams, simply add an additional comma followed by another numeric value.

A plot utilizing 3 data streams would look something like the picture shown below:

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 26 of 62


The plotter also supports landscape view!

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 27 of 62


AutoScroll and Plot Width

When switched on, AutoScroll will adjust the graph size and follow the most recent data collected by the Bluefruit LE
Connect app

When turned off, swipe left and right to scroll through your data. Use the Width slider to adjust the width of the graph.

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 28 of 62


Controller
The Controller mode provides a variety of ways to control your Bluefruit LE enabled project including Sensor Data,
Control Pad, & Color Picker.

This data is sent from the phone/tablet to the Bluefruit device.

Format for Sent Data


For an example of how to parse the data on Arduino, check out the BLE_Controller_Test code
on github (https://adafru.it/exz).

Each Controller data packet sent is prefixed with single byte char “!” (0x21) followed by a single byte char initial
for identification.
Sensor data values are encoded as floats of 4 byte length.
Each packet ends with a single byte checksum for validation.

Checksum
The single-byte checksum that appends each Controller data packet is calculated by adding all previous bytes of the
packet and then inverting the sum.

An example of how to use the checksum to validate a Controller packet can be found in the
BLE_Controller_Test (https://adafru.it/exz) Arduino sketch:

boolean checkCRC(uint8_t *buffer) {

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 29 of 62


uint8_t len = sizeof(buffer);
uint8_t crc = buffer[len-2];
uint8_t sum = 0;

for (int i = 0; i < (len-1); i++) {


sum += buffer[i];
}

Serial.print("CRC ");

if ((crc & ~sum) == 0) {


Serial.println("PASS");
return true;
}

else {
Serial.println("FAIL");
return false;
}

Sensors
The top section of the Controller table lists the available types of sensor data which can be streamed from your iOS
device. Tap the button at the right of each sensor row to begin streaming its relevant data.

All sensor data updates, except for Location, are sent out over BLE ten times per second.
Location updates are sent whenever GPS data changes, or every 30 seconds if no change occurs.

• Quaternion - sends iOS Device Motion data to describe device attitude. This data is derived from Accelerometer,
Gyro, and Magnetometer readings.

Prefix: !Q

Format:

[‘!’] [‘Q’] [float x] [float y] [float z] [float w] [CRC]

• Accelerometer - sends raw accelerometer data.

Prefix: !A

Format:

[‘!’] [‘A’] [float x] [float y] [float z] [CRC]

• Gyro - sends raw gyroscope data.

Prefix: !G

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 30 of 62


Format:

[‘!’] [‘G’] [float x] [float y] [float z] [CRC]

• Magnetometer - sends raw, uncalibrated magnetometer data.

Prefix: !M

Format:

[‘!’] [‘M’] [float x] [float y] [float z] [CRC]

• Location - sends GPS data, requires user permission before initial use.

Prefix: !L

Format:

[‘!’] [‘L’] [float lat.] [float long.] [float alt.] [CRC]

Control Pad

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 31 of 62


The Control Pad function provides a familiar momentary button interface for common control scenarios. Data is sent on
the press and release of each button. Each packet consists of 4 bytes, each representing a char value. The first two
chars identify the packet as a button message, the third specifies a button, and the fourth signifies either a press or
release.

Prefix: !B

Examples:

Button 4 pressed: [‘!’] [‘B’] [‘4’] [‘1’] [CRC]

Button 4 released: [‘!’] [‘B’] [‘4’] [‘0’] [CRC]

Button Up pressed: [‘!’] [‘B’] [‘5’] [‘1’] [CRC]

Button Down pressed: [‘!’] [‘B’] [‘6’] [‘1’] [CRC]

Button Left pressed: [‘!’] [‘B’] [‘7’] [‘1’] [CRC]

Button Right pressed: [‘!’] [‘B’] [‘8’] [‘1’] [CRC]

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 32 of 62


Note: Any activated sensor data streams will continue while using the Control Pad.

Color Picker

The Color Picker sends a color's RGB values to Bluefruit LE. This can be used to control the state of RGB LEDs such as
Neopixels (https://adafru.it/exA).

• Touch the color wheel to choose desired color

• Press Send to send the chosen color's red, green, and blue values to Bluefruit via UART in the following format:

Prefix: !C

Format:

[‘!’] [‘C’] [byte red] [byte green] [byte blue] [CRC]

Note: Any activated sensor data streams will continue while using the Color Picker.

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 33 of 62


AHRS/Calibration

This feature is still in development

The AHRS/Calibrarion feature allows you to generate and test calibration code for Magnetometer and Gyroscope
sensors connected to your NRF51 based Bluefruit LE device.

Process
Download and run this sketch on your NRF51 powered Bluefruit board:

https://adafru.it/A7T
https://adafru.it/A7T

Connect to your Bluefruit board using the calibration app and choose either Magnetometer or Gyroscope mode
depending on what sensor you'll be calibrating.

Keep rotating slowly in a sphere until you get decent coefficients (this can be a bit tricky and takes some trial and error
to get right).

Once you have data, note it down as shown in the USB example above.

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 34 of 62


Next download this sketch, and plug the mag co-efficient values into it:

https://adafru.it/A7U
https://adafru.it/A7U

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 35 of 62


Once the values are plugged in, upload the sketch to your Bluefruit board.

Testing
Connect to your Bluefruit board and run the '3D Visualisation' mode on the app. You will see a 3D model of a
bunny. Readings sent from your Bluefruit board should allow you to rotate the model by rotating your board.

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 36 of 62


Updates
The Updates features allows you to update the device firmware of your Bluefruit LE hardware over the air. This makes it
easy to keep your device firmware up to date.

Updating Firmware
You’ll first be presented with a list of compatible firmware versions. Choose the one you want to use (you'll usually want
the newest one at the top of the list).

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 37 of 62


You’ll then be asked to confirm the update process. After tapping Ok, the process will begin. Once the update process
is completed, the app will automatically disconnect from the device and the device will reboot.

Custom Firmware
You can also update your device with an your own unlisted firmware by tapping the Use Custom Firmware button.
You’ll be asked to locate the relevant file (iOS users can access files via iCloud) and then update process will begin as
above.

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 38 of 62


© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 39 of 62
Image Transfer

The Image Transfer mode allows you to select an image and transmit it over BLE. The interface also offers a number of
additional features for advanced users.

Data Format
Image data is sent from over BLE in the following format:

Single byte char “!” (0x21)


Single byte char 'I' (0x49)
Color space (uint8 16 for 16bits 565 or 24 for 24-bit 888)
Image width (uint16 little endian, 2 bytes)
Height (uint16 little endian, 2 bytes)
Pixel data encoded as "RGB 16bit 565” or "RGB 24-bit 888" depending on the Color Space selected
Single byte CRC

Choose Image

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 40 of 62


Tap the Choose Image button to select an image from your device’s photo library or capture a new one from the
camera. After selecting your image, use a pinch gesture to scale it for cropping within the white bounding box.

Bit Depth

This setting toggles between two color bit-depth settings: 16-bit & 24-bit. This value determines how many bits of data
are used to represent each pixel’s color value. A higher value allows for a greater range of colors, but uses more data
and time to transfer.

Resolution

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 41 of 62


The Resolution setting allow you to choose from a list of preset image resolutions designed to fit common displays.
Setting a resolution will update the selected image's pixellation as a preview.

Transfer Mode

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 42 of 62


The Transfer Mode setting determines how often the app will require a confirmation response from the Bluefruit
hardware before sending more data. Tapping the button offers three options:

Without Response (fastest, least reliable): App never waits for response before sending more data
With Response (slowest, most reliable): App always waits for response to before sending more data
Interleaved (customizable, varies): App sends a number of packets w/o response before sending one w response.
The default value of 50 offers a nice middle ground between speed and reliability.

Example code written for Circuit Playground Bluefruit + TFT Gizmo is only compatible with default Transfer
Mode of Interleaved [50:1]

Rotate & Send

The image can be rotated using the buttons on either side of the Send Image button.

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 43 of 62


Pressing Send Image will present a progress bar and begin sending data to the Bluefruit Hardware.

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 44 of 62


Pin I/O
This mode gives you a way to quickly control basic digital inputs and ouputs. You are given a menu of all the pins that
are available and you can set the direction and logic level. For some pins, you may also have PWM output & analog
inputs! You can do quite a bit just with this method of control

• Each row in the table represents a pin on your Arduino. Pin name and current state are displayed on the left side of
the cell, while pin value is displayed on the right.

• Tap a row to change the relevant pin's current mode and value.

• Tap the row a second time to hide its controls

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 45 of 62


Read through the Wiring (https://adafru.it/kCe), Configuration (https://adafru.it/kCf) and Usage (https://adafru.it/kCg)
pages for more details

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 46 of 62


Wiring Options
The Pin I/O mode lets you control an Arduino or compatible which is connected to a Bluefruit LE module.

You can use the nrf8001-based or nrf51822-based breakouts. However, the setup will vary slightly.

Let's start with wiring options

Arduino with Bluefruit LE Shield


If you are using the Bluefruit LE Shield then you have an
SPI-connected NRF51822 module. You can use this with
Atmega328 (Arduino UNO or compatible), ATmega32u4
(Arduino Leonardo, compatible) or ATSAMD21 (Arduino
Zero) Your pinouts are Hardware SPI, CS = 8, IRQ = 7,
RST = 4

Bluefruit Micro or Feather 32u4 Bluefruit


If you have a Bluefruit Micro or Feather 32u4 Bluefruit LE
then you have an ATmega32u4 chip with Hardware SPI,
CS = 8, IRQ = 7, RST = 4

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 47 of 62


Feather M0 Bluefruit LE
If you have a Feather M0 Bluefruit LE then you have an
ATSAMD21 chip with Hardware SPI, CS = 8, IRQ = 7,
RST = 4

Bluefruit LE SPI Friend


If you have a stand-alone module, you have a bit of
flexibility with wiring however we strongly recommend
Hardware SPI, CS = 8, IRQ = 7, RST = 4

You can use this with Atmega328 (Arduino UNO or


compatible), ATmega32u4 (Flora, Arduino Leonardo,
compatible) or ATSAMD21 (Arduino Zero) Your default
pinouts should be Hardware SPI, CS = 8, IRQ = 7, RST =
4

Bluefruit LE UART Friend


If you have a stand-alone UART module you have some
flexibility with wiring. However we suggest hardware
UART if possible. You will definitely need to use the flow
control CTS pin if you are not using hardware UART. You
will need to set up the MODE pin as well since Firmata
uses both command and data modes

You can use this with Atmega328 (Arduino UNO or


compatible), ATmega32u4 (Arduino Leonardo,
compatible) or ATSAMD21 (Arduino Zero

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 48 of 62


Flora BLE
This simplified UART friend is BLE for FLORA, its really
only intended for use with Hardware Serial, there's no
flow control.

You can use this ATmega32u4 (Flora) although in theory


you could wire it up to a different processor

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 49 of 62


Library and Config
Before loading Firmata BLE...
Make sure you have the basic tutorials working, that you can send/receive data via the UART with your wiring. If you
can't talk to the module and send/receive data via the basic UART demo, Firmata won't work!

Install Libraries
You'll want to start by installing the BLE Firmata library (https://adafru.it/fTO). Use the Library manager to find Adafruit
BLEFirmata and install it

Open Sketch and Configure


Restart the IDE and load the Adafruit_BLE_PinIO->BluefruitLE_nrf51822 sketch

At the top of the sketch is the Firmata configuration section, there's also Bluefruit LE pin configuration in the
BluefruitConfig.h tab

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 50 of 62


Bluefruit LE Config
Start by opening the BluefruitConfig.h tab. By default the sketch is set up for hardware SPI and CS = 8, IRQ = 7 and RST
= 4. This works by default for our Bluefruit Feathers.

You'll need to change your pins if you are using UART or different SPI pins.

Check out the generic "Configuration!" details for information on what every pin does. If you're using software serial, be
sure to set up flow control and a MODE pin. (https://adafru.it/kCT)

Then in the main sketch, if you're not using hardware SPI, uncomment the connection style you want

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 51 of 62


// Create the bluefruit object, either software serial...uncomment these lines
/*
SoftwareSerial bluefruitSS = SoftwareSerial(BLUEFRUIT_SWUART_TXD_PIN, BLUEFRUIT_SWUART_RXD_PIN);

Adafruit_BluefruitLE_UART ble(bluefruitSS, BLUEFRUIT_UART_MODE_PIN,


BLUEFRUIT_UART_CTS_PIN, BLUEFRUIT_UART_RTS_PIN);
*/

/* ...or hardware serial, which does not need the RTS/CTS pins. Uncomment this line */
// Adafruit_BluefruitLE_UART ble(BLUEFRUIT_HWSERIAL_NAME, BLUEFRUIT_UART_MODE_PIN);

/* ...hardware SPI, using SCK/MOSI/MISO hardware SPI pins and then user selected CS/IRQ/RST */
Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);

/* ...software SPI, using SCK/MOSI/MISO user-defined SPI pins and then user selected CS/IRQ/RST */
//Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_SCK, BLUEFRUIT_SPI_MISO,
// BLUEFRUIT_SPI_MOSI, BLUEFRUIT_SPI_CS,
// BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);

Firmata Debug Config


Next up in the main sketch there's a few settings you'll have to configure. First up is debug and serial details

// Change this to whatever is the Serial console you want, either Serial or SerialUSB
#define FIRMATADEBUG Serial
// Pause for Serial console before beginning?
#define WAITFORSERIAL true
// Print all BLE interactions?
#define VERBOSE_MODE false

The first setting FIRMATADEBUG is how output is printed. 99% of the time you'll be happy with Serial, but for Arduino
Zeros you may need to use SerialUSB for the native port.

WAITFORSERIAL determines whether the sketch waits for the Serial port to be opened before it runs. Set it to true
while debugging/testing and open up the serial console to kick off the sketch. Set to false once it's working great

VERBOSE_MODE allows you to see all of the data passing between the BLE module and App.

Available Pins Config


Below the debug config is where you can set up what pins are available for the Pin IO app to twiddle

/************** For Bluefruit Micro or Feather 32u4 Bluefruit ************/


//uint8_t boards_digitaliopins[] = {0,1,2,3,5,6,9,10,11,12,13,A0,A1,A2,A3,A4,A5};

/************** For UNO + nRF58122 SPI & shield ************/


//uint8_t boards_digitaliopins[] = {2, 3, 5, 6, 9, 10, A0, A1, A2, A3, A4, A5};

/************** For Bluefruit M0 Bluefruit ************/


//uint8_t boards_digitaliopins[] = {0,1,5,6,9,10,11,12,13,20,21,A0,A1,A2,A3,A4,A5};

You'll need to uncomment one of these lines. Also, they are set up by default for the SPI Bluefruit module, on pins 4, 7,
8. For that reason, the hardware SPI pins and 4,7,8 don't appear. If you are using different pins you can re-add those to

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 52 of 62


the list. If there are any other pins you don't want to show up in the app, remove those pins as well.

For the 32u4 and M0 examples, there's a lot of pins, & perhaps not all of them are necessary! You can have as few as
you like.

Below the setup lines you can see the way we tell Firmata which pins do what

#if defined(__AVR_ATmega328P__)
// Standard setup for UNO, no need to tweak
uint8_t boards_analogiopins[] = {A0, A1, A2, A3, A4, A5}; // A0 == digital 14, etc
uint8_t boards_pwmpins[] = {3, 5, 6, 9, 10, 11};
uint8_t boards_servopins[] = {9, 10};
uint8_t boards_i2cpins[] = {SDA, SCL};

Don't mess with these! Change only the digital IO pins array!

Upload and test


Once you're done compile and upload. Open up the serial console. You should see that the sketch was able to initialize
the Bluefruit LE module, reset it and print out some details about the BLE firmware. It will now wait for the app to
connect

If you dont see anything, check:

If you're using an ATSAMD21/M0 chip, do you have FIRMATADEBUG set to SerialUSB?


Do you have WAITFORSERIAL true?

Once you know everything is working, set "#define WAITFORSERIAL true" to false so you don't have to open
the serial console to have the Firmata code run!

Once you connect in Pin IO mode you can see a stream of commands that are received and acted upon

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 53 of 62


© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 54 of 62
Usage
The Pin IO capability basically lets you control the pins of the Arduino one by one. Its meant for basic prototyping and
control where you may not want to write a full app from scratch!

The app and sketch are also 'smart' in that when you connect, the app will query the Arduino what pins are available
and what they can do!

Initial Query
Make sure you have the most recent version of the app, and the correct configuration. During connection you'll see the
app Querying Pin Capabilities... It will then get the correct details and fill out the pin map

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 55 of 62


If the query fails, the app will default back to our old 'UNO' setup, which may not work well for you. Check debug output
for the Bluefruit firmata sketch, make sure you're running the latest version of the sketch

Digital Input
All of the pins default to digital inputs with built-in pullup resistors. This means that by default the pins read HIGH. When
a button is wired to the pin & pressed or the pin is shorted to ground, you will receive a LOW signal

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 56 of 62


Digital Output
You can also set the pins to digital outputs. This will let you set the pins HIGH (3V or 5V, depending on the
microcontroller voltage) or LOW (0V a.k.a ground). Great for turning on & off LEDs

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 57 of 62


You can also wire it up to a PowerSwitch Tail (http://adafru.it/268) which gives you a safe way to control appliances!

PWM Output
On some pins, there's PWM output available, you can dim or brighten an LED. You could also control a DC motor
through a driver, if it can be PWM controlled

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 58 of 62


Analog Input
There are also some pins that have Analog pin capability. You can read various sensors or potentiometers that are
wired to these pins. Its best to make sure you know how to get the analog sensor working first, using plain Arduino
code, before wiring it up for use with Pin IO

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 59 of 62


© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 60 of 62
Troubleshooting
If you’re having trouble finding your Bluefruit device in the scanned peripherals list, it could be due to caching isues in
the iOS or Android operating system. For a fix, try the following:

Cycle Bluetooth
Turn your mobile device’s Bluetooth radio off and on again via your device's Settings app.

Cycle Power
Restart your mobile device by powering it off and restarting.

Clear Bluetooth Cache


On iOS, go to Settings->Bluetooth, tap the i button, and tap forget device. For Android, instructions can be found
here (https://adafru.it/F6x).

© Adafruit Industries https://learn.adafruit.com/bluefruit-le-connect Page 61 of 62


© Adafruit Industries Last Updated: 2020-02-04 09:42:18 AM UTC Page 62 of 62

You might also like