6.6.1.7 ColorSenseController with Touch Remote using Extended Light

BLE_Legacy_dvt_Xref4.1.2.2 BLE Legacy Advertisements

BLE_Exteneded_Advt_Xref 4.1.2.3 BLE Extended Advertisements

BLE_Custom_service_Xref 4.1.2.7 BLE Custom service

BLE_Sensor_touch_Xref 4.2.1 BLE Sensor with Touch

WBZ351 Curisotiy Board

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

Peripherals (Used, On-Board): | UART-USB Converter|

Introduction

This tutorial will help users to create a low power enabled color sense controller integrated with Touch application which can get connected with a Extended Light and report the touch values.

Prerequisites :

Hardware Required

Tool Qty
WBZ351 Curiosity Boards 2
Micro USB cable 2
Personal Computer 1
QT7 Xplained pro 1

SDK Setup

- Getting Started with Software Development

Terminal Software

- TeraTerm

Programming the precompiled hex file or Application Example

The Color Sense is an end device application. The Color Sense application works by getting connected with a router device(Extended Light). So, to successfully execute this demo, it is mandatory to have a extended light application set up prior to running the color-sense application.

  1. First program the WBZ351Curiosity board with Extended Light which can act as Zigbee Gateway/Router. The details regarding the extended light application including programing steps is provided TBA(Provide the link to Extended Light page). Gather the information regarding the extended light application, and program the application to one of the curiosity board.

  2. Program another WBZ351 Curiosity board with ColorSenseController application. Follow the steps mentioned below to program the curiosity board with ColorSenseController application.

Programming the hex file using MPLABX IPE

  1. Precompiled Hex file is located in "<Harmony Content Path>\wireless_apps_pic32cxbz3_wbz35\apps\zigbee\colorsensecontroller" folder

  2. To flash the hex file using IPE, follow the steps mentioned here

Caution: Users should choose the correct Device and Tool information

Programming the Application using MPLABX IDE

Follow the steps below to run a precompiled application example.

Prerequisites

  1. Install MPLAB X IDE

  2. Install XC32 Compiler

  3. 3.5 Install Device Family Part Pack

  4. Install MCC Plugin

  5. 3.3 Install Harmony 3 Dependencies

Open, Build and Program an existing application example

  1. Connect Curiosity Board to the PC using usb cable

  2. Open MPLAB X IDE

  3. Select File > Open Project

  4. Browse to project location: "<Harmony content path>\wireless_apps_pic32cxbz3_wbz35\apps\zigbee\colorsensecontroller\\firmware"Information related to the workings of the application example are available in readme.md file available in the colorsensecontroller folder
  5. Open Project Properties

    • Select WBZ351 Curiosity Board as hardware tool for programming

    • Ensure correct DFP is selected as mentioned in the Tools and Harmony Components

  6. Select XC32 compiler

  7. Select option Build Project in IDE to compile the application example

  8. Select option Run Project in IDE to program the target – the onboard debugger will program the example application

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

Demo Description

This application demonstrate the working of Zigbee ColoeSenseController end device joining to Zigbee Router (Extended Light) . After joining, colorsensecontroller device will start ZCL attribute reporting of sLED ON/OFF, and LED Brightness Level.

Application Zigbee Logical Device Type Functionality
Extended Light Router Device capable of controlling and monitoring other devices. It is typically a mains-powered device like a personal computer
ColorSenseController End Device Reports sensor data such as LED ON/OFF, and LED Brightness Level.

The application demonstration required to have a extended light application up and running in the vicinity. which can act as Zigbee Gateway/Router. The Color Sense Controller application here can act as Zigbee end device.

Demo Steps: Commissioning0.

The Zigbee ColorSenseController can be connected to a zigbee network.

Note: Color Sense Controller does not have console log so just program coloer sense to the curiosity351 board and open tera term for extended light for the connection eshtablishment as shown below.

Joining ColorSenseController with WBZ351Extended Light Router

# Hardware & Software Setup

  1. Supply power to WBZ351 Curiosity Board consisting of Extended Light application by connecting a USB cable.

  2. The application activity is shown as "Console Log" through on-board UART-USB converter
    • Open Terminal(eg: Tera Term) with the setup as shown below to see the log
    • On the PC side virtual COM port connection that corresponds to the board shall have following settings:
      • BAUD RATE: 115200 (as configured in SERCOM configuration)
      • PARITY: None
      • DATA BITS: 8
      • STOP BITS: 1
      • FLOW CONTROL: None
      Additionally, local echo and sending line ends with line feeds shall be enabled in the PC serial terminal application.
  3. Make the serial terminal ready and then press the reset button on the curiosity board. Below log will be displayed.

# Network Formation (Router - (Extended Light))

  1. Once the board is powered on and serial terminal setup is done, the board is ready to be operated as a router. It is responsible for initially forming the network and then, via the Trust Centre functionality, managing which other devices are allowed to join the network and distributing security keys to those that are allowed to join.

  2. Input command : resetToFN and look for the below logs for successful zigbee network formation on CI. It will open up the network for other zigbee devices to join for first 180 seconds from the first powerON.

  • Case1: If a near by device is trying to join a network, and sees Extended Light then will join the network as shown in below log.

    The commisioning procedure will last for 180 secods. In case no other devices are there in vicinity and at the endo of 180 seconds, the below log will be displayed

    Once after the Commissioning Procedure is complete press QT7 Button2 to ON/OFF the Green LED use slider to control the Brightness of the LED. Log's will be displayed as below under the Extended Light Tera Term Console.

Developing this Application from scratch using MPLAB Code Configurator

This section intented to showcase the complete application development from the scratch including the individual component and its dependency inclusion.

Tip New users of MPLAB Code Configurator are recommended to go through the overview
  1. Create a new MCC Harmony Project -- TBA for instructions

  2. Add "Color Sense Controller" device type to the project and accept all the dependencies

    Accept all the component auto-activation and attachment auto-connect confirmation.

    Confirm "Yes" for the Attachment Auto-Connect requests

  3. After the inclusion of the dependent components, the final project graph looks like

  4. Add "Touch" device type to the project and accept all the dependencies
    Hardware Used:
    • QT7 Xplained Pro kit is an extension board here
    Steps to be followed for Touch Configuration:
    • Click here for QT7 Touch Configuration
    Note: In order to use Touch CVD Peripheral with WBZ351 Curiosity Board remove the below mentioned Resistors in order to make Touch work. The Impact of the removed resistor will affect the Red & Blue functionality, only Green LED is used for the demo purpose.
    Table 6-12. 
    S.No Resistor to be Removed from WBZ351 Curiosity Board for Touch Functionality
    1 R3 (PB4 –> Touch Button2)
    2 R91 (PB1 –> CVD5 TouchSlider Y-Line3)
    3 R92 (PB0 –> CVD4 RED LED )
    4 R93 (PB2 –> CVD6 TouchSlider Y-Line4)
    5 R95 (PB5 –> CVD1 TouchSlider Y-Line2 & BLUE LED)
    6 R99 (PB1 –> CVD5 TouchSlider Y-Line3)

    Click here for GREEN LED Control from QT7 Touch Button/Slider

  5. System Clock Configuration and SOSC selection selection during sleep mode

    System Clock Selection

    SOSC clock configuration

    Note: Even after enabling and selecting the SOSC as backup source in the clock configuration. The LPCLK and RTC clock still show as 0Hz. This is a known issue which will be resolved in upcoming MCC release. For the time being, to fix this issue, a manual application code modification is necessary. The required change will be discussed in the next section.
  6. Generate Code

    Now all the required components has been added to the project and necessary configuration modification is made. The next step is to generate the application code.

Manual Application code edit

This section talks about the mandatory code modifications that needs to be incorporated inorder to implement the sleep mode functionality.

Step 1: app_user_edits.c

  • Some of the Harmony 3 generated files cannot be fully configured by the MPLABX Code Configurator. This file contains the instructions for the user to modify these files.

    Follow the instruction mentioned on the app_user_edits.c file and after completing the required edits, comment out or remove the #error line

Step 2: plib_gpio.c

  • Code Changes for Sleep functionality

    Add the below code inside the GPIO_Intitialize function

    void GPIO_Initialize ( void )
    {
     /* Disable JTAG since at least one of its pins is configured for Non-JTAG function */
        CFG_REGS->CFG_CFGCON0CLR = CFG_CFGCON0_JTAGEN_Msk;    
    //All pubs are defined as input after a reset.
        GPIOA_REGS->GPIO_TRISSET = 0xFFFF; //Set all pins as input
        GPIOA_REGS->GPIO_CNPUSET = 0x7FF3; //Except PA2 (QSPI Data), PA3, the others are pulled up
        GPIOA_REGS->GPIO_CNPDSET = 0x0008; //RPA3 is Pulled down: SERCOM 0-RTS
        /*  PB  */
        GPIOB_REGS->GPIO_ANSELSET = 0x0040; //PB6 ANSEL for Temp sensor
        GPIOB_REGS->GPIO_TRISSET = 0xFFFF;  //Set all pins as input
        GPIOB_REGS->GPIO_CNPUSET = 0x3D96;  //Pull up: PRB 1, 2, 4, 7, 8, 10, 11, 12 , 13
        GPIOB_REGS->GPIO_CNPDSET = 0x0029;  //Pull down RB0,3,5 for LED
              /* PORTA Initialization */
        /* PORTB Initialization */
        /* PPS Input Remapping */
        /* PPS Output Remapping */
    }
    
  • Step 3:Step 4 - Plib_rtc.h

    • Default Generated: #define RTC_COUNTER_CLOCK_FREQUENCY (0U / (1UL << (0x1U - 1U)))
    • Replace to: #define RTC_COUNTER_CLOCK_FREQUENCY (32768U / (1UL << (0x1U - 1U)))
  • Step 4: zigbeeAppDeviceSelect.h

    • Default Generated: #define CS_UID 0xbef //Unique Identifier (UID) determining the device extended address
    • Change to a unique value: #define CS_UID 0x123bee //Unique Identifier (UID) determining the device extended address

    Reason:By default the Co-Ordinator is also having same value. In a network the UID value should be unique