5.2.1 BLE Sensor

PIC32-BZ6 Curiosity Board

Devices (Device): PIC322051BZ62132(MCU) on PIC32WM-BZ6204UE module

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

PIC32-BZ6 Curiosity Board

Figure 5-162. PIC32-BZ6 Curiosity Board Top View
Figure 5-163. Hardware Block Diagram - Curiosity Board

Hardware Required

Table 5-34. Hardware Prerequisites
S. No.

Tool

Quantity

1

PIC32-BZ6 Curiosity Board

1

2

Micro usb cable

1

3

Android/iOS Smartphone

1

Software

To install Tera Term tool, refer to the Tera Term web page in Reference Documentation from Related Links.

Smartphone App

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

Programming the Precompiled Hex file or Application Example

Using MPLAB® X IPE:

  1. Import and program the precompiled hex file: <Harmony Content Path>\wireless_apps_pic32_bz6\apps\ble\advanced_applications\ble_sensor\precompiled_hex\ble_sensor.X.production.signed.hex.

  2. For detailed steps, refer to Programming a Device in MPLAB® IPE in Reference Documentation from Related Links.
    Note: Ensure to choose the correct Device and Tool information.

Using MPLAB® X IDE:

  1. Perform the following the steps mentioned in Running a Precompiled Example. For more information, refer to Running a Precompiled Application Example from Related Links.
  2. Open and program the application example ble_sensor.x located in <Harmony Content Path>\wireless_apps_pic32_bz6\apps\ble\advanced_applications\ble_sensor\firmware.

  3. For more details on how to find the Harmony Content Path, refer to Installing the MCC Plugin from Related Links.

Demo Description

This application demonstrates the capability of PIC32WM-BZ6204UE 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 PIC32-BZ6 device will also report the temperature data periodically to mobile phone through BLE.
  1. The PIC32WM-BZ6204UE 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 GREEN On/Off status, for more information refer to Protocol Exchange from Related Links.

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

    • Application is supported by iOS and Android 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 change to any color from the mobile app color wheel.

  5. From the PIC32WM-BZ6204UE module the following actions can be performed:

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

      • When the “USR BTN2 Button” is pressed and released the RGB LED is switched On with default color GREEN or the last stored color

      • When the “USR BTN2 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

Testing

  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 PIC32-BZ6 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 PIC32-BZ6 Curiosity Board User's Guide.

    2. The User LED (blue (D5)) 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 (Example: Tera Term) to look for these logs - UART baud settings: 115200 8-N-1 without flow control.
  5. Monitor LED state and Temperature from MBD Mobile App:
    1. PIC32-BZ6 Curiosity Board starts in advertisement mode to advertise its presence on a smartphone and to allow access to 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 5-164. .
  6. Control RGB LED state On/Off as well as brightness from MBD App:
    1. Click the device that shows up after initiating a scan to establish a connection with PIC32WM-BZ6204UE module.

    2. The User blue LED becomes solid once connection is established between the smartphone and PIC32WM-BZ6204UE module.

    3. Controls the GREEN LED state On/Off.

    4. User can change the RGB LED color using the color wheel in the MBD app.

    5. Controls the brightness of RGB LED when the LED is “On”.

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

    1. Press the reset button on PIC32-BZ6 Curiosity Board

    2. Initiating a “Scan” on Smartphone App

Upon successful disconnection, the PIC32WM-BZ6204UE module starts in Advertisement.

Protocol Exchange

The communication protocol exchange between BLE sensor mobile app (BLE central) and PIC32WM-BZ6204UE module (BLE peripheral) is explained in Protocol Exchange, for more information refer to Protocol Exchange from Related Links.