Redbear BLE Nano (V1-V1.5) Custom Controls with pfodApp™
by Matthew Ford 15th November 2017
(originally posted 28th August 2017)
© Forward Computing and Control Pty. Ltd. NSW Australia
All rights reserved.
of these screens are hard coded into pfodApp (the Android app).
All the screens above are completely controlled by the code in your RedBear BLE Nano.
Update 15th November 2017 – Some BLE boards / software stacks deliver the same cmd twice in quick succession. Update to pfodApp V3.322+ and pfodParser V3.17+ to solve this. pfodApp V3.322+ adds a cmd sequence number and pfodParser V3.17+ filters out duplicate cmds.
The latest version of RedBear BLE Nano is V2. V2 uses a different chip from V1.5. See this webpage for RedBear BLE NanoV2 version of this project.
This tutorial covers custom controls for the RedBear BLE Nano V1 and V1.5 module. For RedBear BLE Nano V2 see this page.
tutorial is in two parts:-
The first part presents a “starter” sketch, that when loaded into your RedBear BLE Nano, will display an interactive graphic on pfodApp that will let you read the Analog and Digital inputs. Change the digital pins to outputs/PWM and set the output/PWM values.
The second part uses the free pfodDesigner to create custom multi-levels menus, plots and data logging that can be displayed on pfodApp. The pfodDesigner generates all the Android code needed for the RedBear BLE Nano. The general purpose pfodApp handles the user display and interaction on your Android mobile. The user display is completely controlled by the Android code you load into your Nano. No Android programming is required.
The animated GIF above shows the operation of the RedBear BLE Nano Starter Sketch.
run this sketch you need:-
RedBearLab BLE Nano Kit – BLE Nano module and programming module http://redbearlab.com/buy/ ~US $33 (NOTE: this has been discontinued and replaced by BLE Nano V2)
USB extension cable (optional but useful) – https://www.sparkfun.com/products/13309 ~US $2
pfodApp – Android app https://play.google.com/store/apps/details?id=au.com.forward.pfodApp ~US 10
Arduino IDE V1.8.4 – https://www.arduino.cc/en/Main/Software
and supporting libraries.
Install Arduino IDE V1.8.4 from https://www.arduino.cc/en/Main/Software
Add https://redbearlab.github.io/arduino/package_redbearlab_index.json to the Arduino Additional Boards Manager URLs (under File->Preferences) and then use the Arduino Board Manager to install the RedBear nRF51822 boards V1.0.8 ( filter your search to RedBear) See also http://redbearlab.com/getting-started-nrf51822
library. Open the Library Manager in the Arduino IDE and type
the search bar. Select BLEPeripheral
by Sandeep Mistry V0.4.0 and
You can try later versions of the BLEPeripherial library, but V0.4.0 is that one that has been tested here. A copy of that V0.4.0 arduino-BLEPeripheral-master.zip file is here in case later versions break something.
Manually download and the pfodParser.zip and pfodDwgControls.zip libraries from here and then use Arduino IDE menu option Sketch → Import Library → Add Library to install them.
Unzip this sketch RedbearBLENanoStarter.zip and its supporting classes to your Aduino Sketchbook location (shown in File → Preferences).
the Arduino IDE, select the BLE Nano board, (my board was V1.5) and
open the RedbearBLENanoStarter.ino
and compile and download to the BLE Nano module. To program it you
need to add the USB shield shown above (under the main board). While
the USB shield is designed to plug directly into your USB port, I
found that very inconvenient on my laptop so I add a USB
The BLE Nano now contains all the code necessary to draw the interactive graphic and process the user's inputs.
Install pfodApp on your Android Mobile. You will need a mobile with Android OS V4.4 or higher and one that supports Bluetooth Low Energy. Then create a BLE connection to your BLE Nano, as described in pfodAppForAndroidGettingStarted.pdf. Finally connect, and pfodApp will load the graphic shown above. Once the graphic is loaded, pfodApp caches it so next time the BLE Nano only needs to send the updates.
The sketch you have loaded uses pfodApp drawing primitives to draw the board outline and buttons and to define the user touch zones and actions. The Custom Arduino Controls for Android tutorial covers how to code your own custom controls and the Arduino101 Starter, controlled by Android/pfodApp tutorial describes how the Zoom and Pan works.
The next section describes how to use the free WISIWYG pfodDesigner to create multi-level menus to control the outputs and read and plot and log the analog inputs and generate all the code required for your RedBear BLE Nano.
Android app lets you create custom menus and then generates all the
code for your particular BLE module. pfodApp
is then used to display your custom menu on your Android mobile and
let you control your module.
No Android or Arduino coding is required.
The free pfodDesignerV2 is used to create the menu in a WISIWYG fashion and show you an accurate preview of how the menu will look on your mobile. The pfodDesignerV2 allows you to create menus and sub-menus with buttons and sliders optionally connected to I/O pins and generate the sketch code for you (see the pfodDesigner example tutorials) but the pfodDesignerV2 does not cover all the features pfodApp supports. See the pfodSpecification.pdf for a complete list including data logging and plotting, multi- and single- selections screens, sliders, text input, etc.
The tutorial Design a Custom menu to turn the Arduino Led on and off has step by step instructions for creating this menu using pfodDesignerV2. If you don't like the colours of font sizes or the text, you can easily edit them in pfodDesignerV2 to whatever you want and see a WYSIWYG (What You See Is What You Get) display of the designed menu.
There are two changes that you need to make for RedBear BLE Nano, set it as the Target for the code generator and swap the position of the On/Off labels since the Nano Led is active Low.
First you need to choose RedBear BLE Nano as the Target for the code generation. When you start a new menu or edit an existing menu, the top button shows the Target board. The default is Serial.
Click on the Target button to open the Target selections.
Choose Bluetooth Low Energy button and scroll down to find the RedBearLab BLE Nano option and click on it.
Then use the mobile's back button to exit the Target selections screen and return to the Edit Menu screen.
The RedBear BLE Nano has another difference. It's LED is active LOW. That is when the output from D13 is LOW the led is ON.
As you follow through the Design a Custom menu to turn the Arduino Led on and off tutorial to complete the menu design you will edit the LED Low/High button to On/Off for RedBear BLE Nano. However while this works, LOW == ON, it leaves the On on the left of the button slider. (as shown below)
To swap the ends of the slider so that On is on the right and Off on the left, scroll down to find the Swap Slider Ends option.
Click the Swap Slider Ends option and On / Off changes ends.
That completes the changes needed. You can now continue with the Design a Custom menu to turn the Arduino Led on and off tutorial to Generate the Code, transfer it to your computer and compile and download to your RedBear BLE Nano. A copy of the generate code sketch is here (BLENanoLedController.ino)
Then connect via pfodApp from your mobile to display the menu you have just designed and control the Led by either clicking anywhere in the button or sliding the slider.
Using the Led Controller as a basis, you can add more menu items for reading or controlling the other Digital pins and for reading, plotting and logging the Analog inputs, A3, A4 and A5. Check out the various pfodDesigner tutorials on using the various menu items. The How to Display Arduino Data on Android for Beginners tutorial covers creating plots.
The generated sketch is here (BLE_NanoController.ino)
As well as plotting the Analog values, the readings are also logged, in CSV format, to a file on your mobile for later use.
The pfodDesignerV2 only supports a sub-set of the screens that pfodApp supports. For a complete list see the pfodSpecification.pdf. The SampleRedBearBLENanoScreens.ino sketch includes additional screens supported by pfodApp but not included in the pfodDesigner. Most of the screens have no formatting to keep the messages clear and simple. The color selector under Sliders is an exception. You can add your own colours and font styles, using the pfodDesignerV2 as a guide. Also see the pfodDemo Android app for other examples.
The SampleRedBearBLENanoScreens.ino sketch needs the pfodParser.zip and pfodDwgControls.zip libraries to be installed first.
This tutorial has shown how you can easily
communicate with and control RedBearLab BLE Nano boards
No Android programming is required. pfodApp handles all of that.
No Arduino coding is required. The (free) pfodDesignerV2 generates complete sketches for this and a variety of other modules including ESP8266 and WiFi, Bluetooth and SMS shields.
Because there is no standard for a general purpose UART connection to a BLE device, pfodApp has pre-configured a number of the common BLE boards' connection parameters so you can use the same pfodApp for all of them.
AndroidTM is a trademark of Google Inc. For use of the Arduino name see http://arduino.cc/en/Main/FAQ
The General Purpose Android/Arduino Control App.
pfodDevice™ and pfodApp™ are trade marks of Forward Computing and Control Pty. Ltd.
Contact Forward Computing and Control by
©Copyright 1996-2020 Forward Computing and Control Pty. Ltd. ACN 003 669 994