4.2.1.4 BLE Sensor App with RGB LED (without Touch)

WBZ351 Curiosity Board

Devices (Device): PIC32CX5109BZ31048(MCU) on WBZ351 module

Devices (Used, On-Board): Analog Temperature Sensor, RGB LED, User Button, User LED, USB-UART converter

Figure 4-57. WBZ351 Curiosity Board

Hardware Block Diagram - Curiosity Board

Hardware Required

Tool

Qty

WBZ351 Curiosity Board

1

Micro usb cable

1

Andrioid/iOS Smartphone

1

Hardware Modification

A simple hardware modification is needed to run this demo. WBZ351 Curiosity boards has on-board RGB LED on PB0, PB3, PB5 pins. But, these pins are multiplexed with CVD Touch functionality. Hence the connection to R and B LED's are disconnected by default on the board. Mount 0 ohm resistor or make the solder connection on R92 and R95 resistor position as shown below.

Note: If these resistors are mounted, PB0 and PB5 pins can not be used for CVD Touch input.

Software

Teraterm

Smrtphone App

Microchip Bluetooth Data (MBD) iOS/Android app available in stores

Programming the precompiled hex file or Application Example

Programming the hex file using MPLABX IPE

  1. Precompiled Hex file is located in "<Harmony Content Path>\wireless_apps_pic32cxbz3_wbz35\apps\ble\advanced_applications\ble_sensor_touch\precompiled_hex\ble_sensor_rgb.X.production.signed.hex" folder

  2. Follow the steps mentioned here

Caution: Users should choose the correct Device and Tool information

Programming the Application using MPLABX IDE

  1. Follow steps mentioned in of Running a Precompiled Example document

  2. Open the Application Example "ble_sensor_touch.x" located in "<Harmony Content Path>\wireless_apps_pic32cxbz3_wbz35\apps\ble\advanced_applications\ble_sensor_touch\firmware" using MPLABX IDE

  3. Comment out the ENABLE_TOUCH compile time switch in app.h to disable Touch functionality
  4. Program the application

<Harmony Content Path> how to find what is my Harmony Content Path

Demo Description

This application demonstrates the capability of WBZ351 module to connect to a mobile phone through Bluetooth Low Energy(BLE). The RGB LED on the Curiosity board can be controlled by mobile app. The WBZ351 device will also report the temperature data periodically to mobile phone through Bluetooth low energy (BLE).
  1. The WBZ351 module will be a BLE peripheral device and will advertise on startup. The user can initiate the connection through mobile application. The advertisement payload holds the temperature information and the RGB ON/OFF status.

  2. Uses "BLE Sensor" sub app from the Microchip Bluetooth Data (MBD) mobile app for BLE demonstration.

    • Application is supported by iOS and Andrioid OS

    • Available in respective app stores/play stores

  3. When Connected(ING) to the application the BLUE color "User LED" will turn on

    • Blinks the "User LED" with 500 ms blink interval when the device sending advertisement packets

    • Once connected, the "User LED" turns on solid

  4. From the Smartphone App the following actions can be performed

    • The RGB LED can be switched On/Off from MBD mobile app.

    • When LED is switched On, the RGB color can be changed from mobile app color wheel.

      • The RGB color value is received as HSV (Hue, Saturation, Value) from mobile app through TRPStransparent profile and service
      • The HSV value is converted to RGB equivalent value in the device. The corresponding PWM duty cycle for R,G,B will be calculated and the PWM pulse is provided on R,G,B LEDs.

  5. From the WBZ351 module the following actions can be performed

    • The RGB LED can be switched on/off by pressing the On board "User Button"

      • When the "User Button" is pressed and released the RGB LED is switched ON with default color GREEN or the last stored color

      • When the "User Button" is pressed and released again, then the RGB LED will be toggled from the previous state

    • Read the temperature sensor every 1 sec once and send the temperature value to mobile app when the temperature changes about 1 degree C

Demo

  1. Install the Microchip Bluetooth Data (MBD) Smartphone App

    1. iOS/Android users can search for “Microchip Bluetooth Data” App in App Store and install

    2. Enable Bluetooth on the Smartphone

  2. Launch the MBD Smartphone App

  3. Supply power to WBZ351 Curiosity Board

    1. Connect a USB cable to the kit or a 4.2V Li-ion/Li-Po Battery. For more information refer to the Power Supply section of the WBZ351 Curiosity Board User's Guide.

    2. The user-programmable blue LED starts blinking on the Curiosity Board when the board is in advertisement mode.

  4. UART Console Behavior

    1. The application activity is shown as "Console Log" through on board UART-USB converter
    2. Open Terminal (eg: Tera Term) to look for these logs - UART baud settings: 115200 8-N-1 without flow control
  5. Monitor RGB LED state and Temperature

    1. WBZ351 Curiosity Board starts in advertisement mode to advertise its presence on a smartphone and to allow access to RGB LED on/off state and temperature sensor data.

    2. Navigate through the Smartphone App as shown in the following figure to access the advertisement information.
      Figure 4-58. .
  6. Control RGB LED state on/off as well as intensity and color

    1. Click the device that shows up after initiating a scan to establish a connection with WBZ351 module.

    2. The user programmable blue LED becomes solid once connection is established between the smartphone and WBZ351 module

    3. Controls the RGB LED state on/off.

    4. Controls the color of RGB LED when the LED is “on”.

    5. Controls the intensity of RGB LED when the LED is “on”.

    6. Additional information
      Figure 4-59. .

  7. To disconnect the MBD Application running on your smart phone, you can do one of the following:

    1. Press the reset button on WBZ351 Curiosity Board

    2. Initiating a “Scan” on Smartphone App

Upon successful disconnection, the WBZ351 module starts in Advertisement Mode.

Protocol Exchange

The communication protocol exchange between BLE sensor mobile app (BLE central) and WBZ351 module (BLE peripheral) is explained here

Application Flow Diagram