/PIC32CXBZ2_WBZ45x_Zigbee_Home_Thermostat

"IoT Made Easy!" - Home Thermostat solution using Zigbee 3.0. The Home Thermostat enables us to set the temperature using a Thermostat Panel, get the current temperature through Multisensor and switch on/off the air conditioner based on the current and set temperature and control the set temperature using a Zigbee Coordinator.

Primary LanguageC

PIC32CXBZ2_WBZ45x Zigbee E-Paper Home Thermostat

"IoT Made Easy!"

Devices: | PIC32CXBZ2 | WBZ45x |
Features: | ZIGBEE | E-PAPER | TOUCH |

⚠ Disclaimer

THE SOFTWARE ARE PROVIDED "AS IS" AND GIVE A PATH FOR SELF-SUPPORT AND SELF-MAINTENANCE. This repository contains example code intended to help accelerate client product development.

For additional Microchip repos, see: https://github.com/Microchip-MPLAB-Harmony

Checkout the Technical support portal to access our knowledge base, community forums or submit support ticket requests.

Contents

  1. Introduction
  2. Bill of materials
  3. Hardware Setup
  4. Software Setup
  5. Harmony MCC Configuration
  6. Board Programming
  7. Run the demo
  8. Related Applications

1. Introduction

This example application enables us to develop a home thermostat device. This application requires a Zigbee Coordinator, Thermostat router and a sensor end-device. Alexa Echo or Combined Interface can be used as the Coordinator device. The Thermostat router uses an E-Paper Bundle 2 Display and an external touch interface ( ATtiny3217 Xplained Pro and T10 Xplained Pro kit ) with the WBZ451 Curiosity board to create a Zigbee Thermostat application. The touch interface enables us to set the temperature and Reset the device to factory new. The set temperature will be reported to the devices in the Zigbee network. The set temperature and the Zigbee console logs are shown on the E-PAPER display. The Multisensor device reports the current temperature to the device in the Zigbee network. Based on the set temperature and current temperature the AC is switched ON or switched OFF.Alt Text

Thermostat setup

Tip Go through the overview for understanding few key Zigbee 3.0 protocol concepts

2. Bill of materials

TOOLS QUANTITY
PIC32CX-BZ2 and WBZ451 Curiosity Development Board 1
E-Paper Bundle 2 1
ATtiny3217 Xplained Pro 1
T10 Xplained Pro Extension Kit 1

3. Hardware Setup

  • Connect the E-Paper Bundle 2 with the WBZ451 CURIOSITY BOARD using the below table.
WBZ451 E-PAPER Description WBZ451 E-PAPER Description
AN 15(BSY) BUSY PWM 16(D/C) Data/Command
RST 2(RST) RESET INT NC NC
CS 3(CS) CHIP SELECT RX NC NC
SCK 4(SCK) SPI CLOCK TX NC NC
MISO NC NC SCL NC NC
MOSI 6(MOSI) SERIAL DATA INPUT SDA NC NC
3.3V 7(3.3V) POWER SUPPLY 5V NC NC
GND 8(GND) GROUND GND 9(GND) GROUND
Note: PIN 15 (BSY) of E-PAPER should be connected with AN of WBZ451 !!
  • Connect T10 Extension header 3 (EXT3) to ATtiny3217 Xplained Pro Extension Header 1 (EXT1).
  • Connect the External 3 header of ATtiny3217 Xplained Pro touch interface with the WBZ451 Curiosity board using jumper wires as shown in the table below.
ATtiny3217 Xplained Pro+T10 Xplained Pro Description WBZ451 Description
PB3 UART-RX PA13(SDA) Sercom2-UART-TX
PB2 UART-TX PA14(SCL) Sercom2-UART-RX
5.0V IN Power supply 5V Power supply
GND Ground GND Ground
Note: Make sure to have common GND!

4. Software Setup

  • MPLAB X IDE

    • Version: 6.05
    • XC32 Compiler v4.10
    • MPLAB® Code Configurator v5.1.17
    • PIC32CX-BZ_DFP v1.0.107
    • MCC Harmony
      • csp version: v3.14.0
      • core version: v3.11.1
      • CMSIS-FreeRTOS: v10.4.6
      • wireless_pic32cxbz_wbz: v1.1.0
      • wireless_ble: v1.0.0
      • dev_packs: v3.14.0
      • wolfssl version: v4.7.0
      • crypto version: v3.7.6
      • wireless_zigbee version: v5.0.0
  • Any Serial Terminal application like TERA TERM terminal application

  • MPLAB X IPE v6.05

5. Harmony MCC Configuration

Getting started with Thermostat application with WBZ451 CURIOSITY BOARD.

Tip New users of MPLAB Code Configurator are recommended to go through the overview

Step 1 - Connect the WBZ451 CURIOSITY BOARD to the device/system using a micro-USB cable.

Step 2 - The project graph of the application is shown below.

  • From Device resources, go to wireless->drivers->zigbee->Device types and select THERMOSTAT. Accept Dependencies or satisfiers, select "Yes". Add UART components needed for console logs and commands. Right click on the "⬦" in Zigbee console and add the satisfier and in the same way add SERCOM0 to the USART console as shown below.

Thermostat

  • The SERCOM0 UART configuration is depicted as follows.

SERCOM0 USART

  • Select Wolfcrypt library and make sure that "Support random number generation" box is unchecked as shown below.

Wolfcrypt library

  • From Device resources, go to System services and select console. Right click on the "⬦" on the instance0 and select SERCOM2 to create a UART communication with the touch interface and the configurations are shown below.

SERCOM2

  • From Device resources, go to Harmony->Peripherals->SERCOM and selct SERCOM1. Right click on the "⬦" on SPI and select SPI Driver. Accept Dependencies or satisfiers, select "Yes". The SERCOM1 configuration is depicted as follows.

SERCOM1 SPI

SPI DRIVER

  • From Device resources, go to Wireless->System services and select "APP_TIMER_SERVICE".

  • The SYSTEM configuration is depicted as follows.

System DEVCFG1

  • From project graph, go to Plugins->PIN configuration and configure as follows.

PIN Configuration

Step 4 - Generate the code.

  • After the code gets generated a Merge window will appear. Click on the arrow and merge all the files.

Step 5 - From the unzipped folder copy the folder click_routines(which contains the eink_bundle.h, eink_bundle_font.h, eink_bundle_image.h, eink_bundle.c, eink_bundle_font.c, eink_bundle_image.c) to the folder firmware/src under your MPLAB Harmony v3 application project and add the Header (eink_bundle.h, eink_bundle_font.h, eink_bundle_image.h) and Source file (eink_bundle.c, eink_bundle_font.c, eink_bundle_image.c).

  • In the project explorer, Right click on folder Header Files and add a sub folder click_routines by selecting “Add Existing Items from Folders…”

  • Click on “Add Folder…” button.

  • Select the “click_routines” folder and select “Files of Types” as Header Files.

  • Click on “Add” button to add the selected folder.

  • The eink bundle header files gets added to your project.

  • In the project explorer, Right click on folder Source Files and add a sub folder click_routines by selecting “Add Existing Items from Folders…”.

  • Click on “Add Folder…” button

  • Select the “click_routines” folder and select “Files of Types” as Source Files.

  • Click on “Add” button to add the selected folder

  • The eink bundle source files gets added to your project.
  • The click_routines folder contain an C source file eink_bundle.c. You could use eink_bundle.c as a reference to add E-Paper display functionality to your application.

Step 6 - In "app_user_edits.c", make sure the below code line is commented

  • "#error User action required - manually edit files as described here".

  • Go to source files->config->default->zigbee->z3device->thermostat->thThermostatUiConfCluster.c and comment line 90.

LCD_PRINT(0,10,"Temp = %d deg C",thThermostatClusterServerAttributes.localTemperature.value);
  • Go to header files->config->default->zigbee->z3device->common->include->z3Device.h, add the following code in the Includes section
#include "click_routines/eink_bundle/eink_bundle.h"
#include "click_routines/eink_bundle/eink_bundle_image.h"
#include "click_routines/eink_bundle/eink_bundle_font.h"
  • In "z3Device.h", replace the code in line 89 and 90 with the below code.
  #define LCD_INIT()                                  e_paper_initialize()
  #define LCD_PRINT(...)                              e_paper_print(__VA_ARGS__)

Step 7 - Replace the app.c, app_zigbee_handler.c, thThermostatCluster.c and app.h file.

Note This application repository should be cloned/downloaded to perform the following steps.
Path The application folder can be found in the following link
  • Copy the "app.c" and "app.h" files by navigating to the following path: "../firmware/src/"
  • Paste the files under source files in your project folder (...\firmware\src).
  • Copy the "app_zigbee_handler.c" and "app_timer.c" files by navigating to the following paths:
    • "../firmware/src/app_zigbee"
    • "../firmware/src/app_timer"
  • Paste the files under the respecive folders in your project folder .
  • Copy the "thThermostatCluster.c" file by navigating to the following path: "../firmware/src/config/default/zigbee/z3device/thermostat"
  • Paste the files under the respecive folders in your project folder .

Step 8 - Clean and build the project. To run the project, select "Make and program device" button.

Step 9 - The data is printed onto the tera term and E-Paper display.

  • Baud rate: 115200
  • Com port: COM USB serial port

Programming the ATTINY3217 XPRO with the T10 interface

  • Follow the steps provided under program the precompiled hex file section to program the ATtiny3217 Xplained Pro and T10 Xplained Pro interface.
  • The application hex file can be found by navigating to the following path:
    • "PIC32CXBZ2_WBZ45x_WINC1500_Zigbee_Wi-Fi_Smart_Thermostat/Thermostat_Zigbee_Panel/Hex/ATTiny3217_T10.hex"
  • The touch buttons are configured as follows.
    • Button1: To increase the set temperature
    • Button2: To decrease the set temperature
    • To reset the device to factory new press Button 1, 3 and 4 simultaneously for 3 seconds.

Programming the ZigBee Coordinator Device

  • The Zigbee coordinator application is available in this link. Follow the steps provided to program the Combined interface application.
Note This application can be used to create the centralized network.

Programming the ZigBee End Device

  • The Zigbee end-device application is available in this link. Follow the steps provided to program the Multisensor application.

6. Board Programming

Programming hex file:

Program the precompiled hex file using MPLAB X IPE

  • The Precompiled hex file is given in the hex folder. Follow the steps provided in the link to program the precompiled hex file using MPLABX IPE to program the pre-compiled hex image.

Build and program the application using MPLAB X IDE

The application folder can be found by navigating to the following path:

  • "WBZ451_E_PAPER_Zigbee_Thermostat\firmware\WBZ451_E_PAPER_ZIGBEE_THERMOSTAT.X"

Follow the steps provided in the link to Build and program the application.

7. Run the demo

  • After programming the board, the expected application behavior is shown in the below video. In this application the router reports the set temperature value to a coordinator device.

Demo

  • The Combined Interface application can also be used instead of Alexa to create the ZigBee network.

8. Related applications