3.1.3 Smart Wireless Thermostat on PIC32CZ CA90 Curiosity Ultra Development Board

Download

Description

This wireless thermostat application uses Bluetooth Low Energy 5.2 and Wi-Fi technology to collect real-time temperature data from two BLE sensor nodes. It allows users to easily set and control the temperature, creating a pleasant environment by adjusting the heating or cooling system to their desired level through an intuitive BLE central node acting as a wireless thermostat that connects to the end nodes over BLE and acts as the temperature control panel. The collected temperature is also streamed through the Wi-Fi Gateway node to the AWS IoT cloud for monitoring. This solution includes four projects to demonstrate a Wireless Thermostat.

This project employs the RNBD451 BLE module to create multi-link BLE connections with two peripheral nodes. Once connected, the central node functions as a GATT client, periodically requesting real-time temperature data from the peripheral GATT servers(peripherals) and displaying it on a 4.3-inch maXTouch graphics display. Users can set and send temperature threshold limits to the BLE peripheral nodes using the GUI. Furthermore, the central application transmits the gathered temperature data to the WFI32 IoT gateway via UART for real-time monitoring on the AWS cloud.

This application operates as a GATT server using the RNBD451 BLE module. It periodically collects temperature data from the IO/1 Xplained Pro board and updates the temperature characteristic value whenever the temperature changes. The node waits for the connection request from the central node. Once connected, it sends temperature data in response to read requests from the GATT client(central node) and can receive and implement threshold limit values from the central node. An onboard LED turns on whenever the temperature exceeds the designated limit.

This application uses ADC to read the analog output from the onboard MCP9700A temperature Sensor. Once connected to central node over BLE, it periodically sends the temperature characteristic value to the central node upon request. It can also receive and set threshold limit values from the central node, with an onboard LED illuminating when the temperature surpasses the defined cutoff

This application acts as bridge between the central node and the AWS cloud. It periodically receives the BLE end nodes temperature data from the central over UART and publishes the same over MQTT to the AWS IoT cloud for constant monitoring.

Modules/Technology Used

Hardware Used

Software/Tools Used

The projects have been verified to work with the following versions of software tools:

Because Microchip regularly updates tools, occasionally issue(s) could be discovered while using the newer versions of the tools. If the project does not seem to work and version incompatibility is suspected. It is recommended to double-check and use the same versions that the project was tested with. To download original version of MPLAB Harmony v3 packages, refer to document How to Use the MPLAB Harmony v3 Project Manifest Feature (DS90003305).

Hardware Setup

PIC32CZ CA90 Thermostat Central Node
  • Connect the 565 LCD Adapter Graphics Card to the Graphics connector of the PIC32CZ CA90 Curiosity Ultra Development Board.

  • Connect the 4.3” WQVGA maXTouch Display module to the 565 LCD Adapter Graphics Card of the PIC32CZ CA90 Curiosity Ultra Development Board.

  • Make sure the jumper J2 of the RNBD451 Add On Board has the cap mounted between J(2-1) and J(2-2) to be powered by the mikroBUS header.

  • Connect the jumper wire from PC08 on EXT1 for SERCOM UART TX to communicate with the Wi-Fi Gateway.

  • Connect the PIC32CZ CA90 Curiosity Ultra Development Board to the Host PC as a USB Device through a Type-A male to micro-B USB cable connected to Micro-B USB (Debug USB) port

  • Power the PIC32CZ CA90 Curiosity Ultra Development Board through the Barrel connector using the wall-mount 9V power supply provided in the kit, or Power supply with any Voltage (6.5-14V DC) and Current (> 750 mA) range.

PIC32CM LS60 Thermostat Peripheral Node 1
  • Connect the RNBD Add-on board to the mikroBUS header on the PIC32CMLS60 Curiosity Pro Evaluation Kit.

  • Make sure the jumper J2 of the RNBD451 Add On Board has the cap mounted between J(2-1) and J(2-2) to be powered by the mikroBUS header.

  • Connect the I/O1 Xplained Pro Extension Kit to the EXT2 in the PIC32CM LS60 Curiosity Pro Evaluation Kit.

  • Connect the PIC32CM LS60 Curiosity Pro Evaluation Kit to the Host PC as a USB Device through a Type-A male to micro-B USB cable connected to Micro-B USB (Debug USB) port

WBZ451 Thermostat Peripheral Node 2
  • Connect the WBZ451 Curiosity board to the Host PC as a USB Device through a Type-A male to micro-B USB cable connected to Micro-B Debug USB port(J7).

WFI32 IoT Thermostat Wi-Fi Gateway

  • Connect the WFI32 IoT development board to the Host PC as a USB Device through a Type-A male to micro-B USB cable connected to PKOB4 Micro-B USB (Debug USB) (J200).
    Figure 3-1. Demo Hardware Setup

Pre-requisites

  • The WFI32E01PC module on the WFI32 IoT development board has an in-built Trust and Go (TNG) device. It is essential to upload the device certificate of the TNG device to the AWS IoT cloud for authenticated client TLS connection with the cloud platform.
  • Follow the procedure mentioned in Generate Device Certificate for extracting the certificate from the device.
  • Upon generation, the device certificate should be uploaded to the cloud. Refer to the Uploading Device Certificate to AWS IoT Cloud Service for more details about the procedure.
  • The configuration.h file of wfi32_iot.X project should be modified for connecting successfully to the AWS cloud.
    • Ensure that the WIFI SSID and WIFI Password is modified in the file by changing the SYS_WIFI_STA_SSID and SYS_WIFI_STA_PWD macros with the Wi-Fi credentials.
    • Also ensure that the aws endpoint and aws thing name are properly set in the SYS_MQTT_INDEX0_BROKER_NAME and SYS_MQTT_INDEX0_CLIENT_ID macros respectively. This depends on user-specific AWS account credentials. For more details check this page.

Programming Methods

  • The device can be programmed in two ways:
    • Refer Method 1: Programming using the prebuilt hex file.

    • Refer Method 2: Programming by building the application project.

  • Perform Prerequisites mentioned above, if not done already.

Method 1: Programming prebuilt hex file

  • Open MPLAB® X IDE.
  • Close all existing projects in IDE, if any project is opened.
  • Go to File -> Import -> Hex/ELF File.
  • In the Import Image File window,
    1. Create Prebuilt Project,
      • Click the Browse button to select the prebuilt hex file.
      • Select Device as PIC32CZ8110CA90208.
      • Ensure the proper tool is selected under Hardware Tool and click on Next button.
    2. Select Project Name and Folder,
      • Select appropriate project name and folder and click on Finish button
  • In MPLAB X IDE, click on Make and Program Device button to program the device.
  • Follow the steps in Running the Demo under PIC32CZ CA90 Central section below.
Note: Program the prebuilt hex files for other projects similarly, by choosing the respective devices and tool.

Method 2: Programming/Debugging the Application Project

PIC32CM LS60 Thermostat Peripheral Node 1
  • Open the project ls60_cprogroup.X in MPLAB® X IDE from pic32cz_ca90_wireless_thermostat/firmware/pic32cm_ls60_cpro_wt_node1 and set it as main project.
  • Open both Secure and Nonsecure projects inside the project group and set the Nonsecure project as the main project.
  • Ensure PIC32CM LS60 Curiosity Pro is selected as hardware tool to program/debug the application.
  • Build the code and program the device by clicking on the Make and Program Device button in MPLAB® X IDE tool bar.
  • Follow the steps in Running the Demo under PIC32CM LS60 Peripheral Node section below.
WBZ451 Thermostat Peripheral Node 2:
  • Open the project wbz451_curiosity.X in MPLAB® X IDE from pic32cz_ca90_wireless_thermostat/firmware/wbz451_curiosity_wt_node2 and set it as main project.
  • Ensure WBZ451 Curiosity board is selected as hardware tool to program/debug the application.
  • Build the code and program the device by clicking on the Make and Program Device button in MPLAB® X IDE tool bar.
  • Follow the steps in Running the Demo under WBZ451 Peripheral Node section below.
PIC32CZ CA90 Thermostat Central Node
  • Open the project pic32cz_ca90_cult.X in MPLAB® X IDE from pic32cz_ca90_wireless_thermostat/firmware/pic32cz_ca90_cult_wt_central and set it as main project.
  • Ensure PIC32CZ CA90 Curiosity Ultra is selected as hardware tool to program/debug the application.
  • Build the code and program the device by clicking on the Make and Program Device button in MPLAB® X IDE tool bar.
  • Follow the steps in Running the Demo under PIC32CZ CA90Central Node section below.
WFI32 IoT Wi-Fi Thermostat Gateway
  • Open the project wfi32_iot.X in MPLAB® X IDE from pic32cz_ca90_wireless_thermostat/firmware/wfi32_iot_wt_gateway and set it as main project.
  • Ensure WFI32 IoT board is selected as hardware tool to program/debug the application.
  • Build the code and program the device by clicking on the Make and Program Device button in MPLAB® X IDE tool bar.
  • Follow the steps in Running the Demo under WFI32 IoT Gateway section below.

Running the Demo

PIC32CZCA90 BLE Central Node
  • Power up the board. Ensure the 4.3" WQVGA maXTouch® Display Module is connected to the 565 LCD Adapter Graphics Card and press RESET button of the PIC32CZ CA90 Curiosity Ultra Development Board.
Screen 1: Home Screen
  • The home screen of the demo gets displayed on the 4.3” WQVGA maXTouch® Display Module.
  • Make sure that the BLE peripheral nodes, NODE 1 and NODE 2, are programmed with their respective application projects and both the nodes are ready to connect to the central node.
Note: Before proceeding to the next step, make sure the console messages shown on the peripheral Node 1 and Node 2 are as Node 1 Ready Status and Node 2 Ready Status.
  • Press the START button on the home screen.
Screen 2: Multi-Connect Screen
  • The central node starts to scan for the nearby BLE peripheral nodes. Scanning appears on the connect screen. Wait for a few seconds for the BLE scanning process to complete.
  • Once the scanning completes, the central initiates connection with BLE Node 1.
  • Upon successful connection with BLE node 1, a tick mark appears on the GUI as below and LED0 is turned on.
  • Similarly , the central node initiates another connection to BLE node 2.
  • Upon successfully connecting with the second node, a tick mark appears on the GUI ,as below, and the next screen appears that shows Preparing appears.
  • LED0 and LED1 are turned on with a successful multilink connection on the PIC32CZ CA90 Curiosity Ultra Development Board as below.
Screen 3: Multi Node Sensor Monitoring
  • This screen gets updated with node 1 and node 2 temperature data fetched in periodic intervals from the BLE peripheral devices.
    Note: The corresponding temperature can be viewed on the tera term console of nodes 1 and 2.
  • Press Set Limit button to assign threshold limit for the nodes to cutoff the heating or cooling unit. Once Set Limit is pressed the next screen appears.
    Note: Wait for a couple of seconds if the next screen does not appear immediately.
Screen 4: Temperature Control
  • Temperature limits can be set for each of the nodes using the ‘ᴧ’ (Increment) and ‘v’(Decrement) buttons.
  • To set threshold for node 1, adjust the temperature and press Enter.
  • Similarly, to set threshold for node 2, adjust the temperature for node 2 and press Enter.
    Note: Take into account that the limits for each node should be set individually. The nodes do not get updated simultaneously. To set threshold for both the nodes, change the limit in one node, press enter and then do the same for the other node.
  • Press Press to Go back to go to screen 3.

PIC32CM LS60 BLE Peripheral Node

  • Power up the board.
  • Open the Terminal application (Ex.:Tera term) on the computer.
  • Change the baud rate to 115200.
  • Press RESET button of the PIC32CM LS60 Curiosity Pro Evaluation Kit to run the application from the beginning.
  • The below console output will be displayed. The last message on Tera Term will be Connecting where the node waits for a BLE connection.
  • When the central node successfully connects (after pressing start onthe central node GUI), the green LED0 turns on indicating successful connection.
  • The measured temperature value prints on the console as below.
  • The BLE node also receives the temperature threshold values set on the central node as below.
  • LED1 (Red LED) on PIC32CM LS60 Curiosity Pro Evaluation Kit turns on whenever the current temperature is greater than the set limit.

WBZ451 BLE Peripheral Node

  • Power up the board.
  • Open the Terminal application (Ex.:Tera term) on the computer.
  • Change the baud rate to 115200.
  • Press RESET button to start over the application.
  • The device starts BLE advertisement and displays the current temperature in periodic intervals.
  • Once the connection with the central node is successful, it sends the current temperature value to the central node.
  • The BLE node also receives the temperature threshold values set on the central node.
  • The RGB LED(D6) of the WBZ451 Curiosity Development Board glows in Red when the current temperature exceeds the threshold set. In the above image the current temperature (31°C) is greater than the received threshold (22°C). The LED turns on in this scenario.

WFI32 IoT Wi-Fi Gateway Node

  • Power up the board.
  • Open the Terminal application (Ex.:Tera term) on the computer.
  • Change the baud rate to 115200 from Setup->Serial menu.
  • Press RESET button to run the application from the beginning.
  • The console displays TCP/IP stack initialization messages and the Gateway IP address gets assigned and displayed on successful connection with Wi-Fi AP. Wait for some time for the MQTT connection establishment as it may take some time.
  • Once the MQTT connection is established the device is ready to update the temperature received from the central node in AWS cloud periodically.
  • The device starts to publish the messages when the central nodeu pdates the temperature.
  • To view the messages published, log in to the AWS account and navigate to the AWS IoT Core service -> MQTT Test client, and subscribe to /pubTopic/. Furthermore, the following messages will be displayed:

Comments

Revision

  • v1.7.0 - Released demo application