Skip to content

microchip-pic-avr-solutions/pic32cz8110ca90208-cult-enviro-sense-ai-mplab-mcc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Microchip Technologies Inc.

EnviroSense AI: Edge Intelligence for Environmental Monitoring with PIC32CZ CA90

Introduction

This application demonstrates an EnviroSense AI system for real-time environmental condition classification using a VEML7700 Ambient Light Sensor (ALS) and a BME680 sensor for temperature and humidity measurement. The sensor readings are continuously acquired over I2C and used as inputs to an embedded SensiML-trained machine learning model running on the microcontroller.

The demo supports both data monitoring and machine learning operation. In one configuration, raw ALS, humidity, and temperature values can be streamed to a host PC for real-time graph plotting and analysis. In the machine learning configuration, the sensor readings are grouped into fixed windows and processed locally on the device to classify the surrounding environmental condition into one of the several labels: Cool_Humid, Humid, Normal, Rainy, Sunny, or Unknown. The measured sensor values and the corresponding classification result are also displayed on an external graphical display for direct user observation.

This demo provides a compact platform for evaluating edge AI in environmental sensing applications through sensor interfacing, live data collection, visualization, on-device inference, and environmental condition classification.


Figure 1. Block Diagram

Modules and Technologies Used:

  • Peripheral Modules

    • PORT
    • SERCOM0 - I2C
    • SERCOM1 - UART
    • SERCOM5 - I2C
    • EVSYS
    • EIC
    • TCC0
    • TCC9
    • EBI
  • Board Support Packages

    • PIC32CZ CA90 Curiosity Ultra BSP
  • Drivers

    • I2C Driver
  • System Services

    • Time
    • CONSOLE
    • DEBUG
    • Input System Service
  • Middleware libraries

    • Harmony Core
  • Graphics

    • GFx Core LE
    • LE LCC
    • Legato Graphics w/ PDA TM4301B Display
    • Max Touch Controller
    • PDA TM4301B
    • Legato


Figure 2. Project Graph


Figure 3. Project Graph - Gfx

Related Documentation:

Software Used:

Hardware Used:

Hardware Modification:

  • Connect a pull-up resistor of 5.1 kOhm between the DISP test point to 3.3V of the 565 Adapter Board. For more information, refer to this article

  • Connect the Peltier Module onto the Cooling System

  • Connect one Motor Speed Regulator to Power Supply and Fan

  • Connect another Motor Speed Regulator to the power supply and to the Peltier module (Cooling system)

  • Solder the BME680 sensor and the Ambient Light sensor onto the ProtoClick

BME680 wire ProtoClick pin
Red VCC
Black GND
Yellow SDA
Green SCL


Figure 4. MikroBUS - Sensor Interface

Hardware Setup:

  • Mount the Modified Protoclick (with ALS and BME680) on the Arduino extension on the PIC32CZ CA90 Curiosity Ultra Evaluation Board

  • Assemble the chamber with all the hardware

    • Place the Humidifer and the Cooling system inside the chamber

    • Place the power supply, motor speed regulators, PIC32CZ CA90 Curiosity Ultra Evaluation board and the graphics display (High-Performance 4.3" WQVGA Display Module with MAXTOUCH® Technology)

  • Connect the WQVGA display module to the PIC32CZ CA90 Curiosity Ultra Evaluation board, using the GFx connector, as shown below.


Figure 5. Hardware Setup - 1

  • 1 - Graphics Connector
  • 2 - Modified ProtoClick
  • 3 - Motor Speed Regulator 1 (for Fan control)
  • 4 - Motor Speed Regulator 2 (for Peltier control)


Figure 6. Hardware Setup - 2

How to Program the .hex File

The pre-built .hex file can be programmed by following the steps below:

  • Open MPLAB® X IDE
  • Close any opened projects in IDE
  • Go to File > Import > Hex/ELF File
  • In the Import Image File window, at Step 1 - Create Pre-built Project, click the Browse button to select the pre-built .hex file.
  • Select Device - "PIC32CZ8110CA90208"
  • Ensure the proper tool is selected under Hardware Tool
  • Click the Next button
  • In the Import Image File window, at Step 2 - Select Project Name and Folder, select the appropriate project name and folder
  • Click the Finish button
  • In MPLAB® X IDE, click the Make and Program Device button. The device will get programmed in short time.
  • Follow the steps in the Running the Demo section below.

Running the Demo:

Collection of Samples:

  • Open the Data Visualizer plug-in in MPLAB X IDE. The connected COM port will be displayed under Serial Ports, in the Connections section


Figure 7. Opening Data Visualizer


Figure 8. MPLAB Data Visualizer Interface

  • Click New variable streamer, as shown below


Figure 9. Serial Port Stream Setup

  • Configure the Variable Streamer name, all the required variables and the corresponding type of the variables, as shown below


Figure 10. Variable Streamer Configuration Panel

  • Select New axis per variable in the How to Plot section to visualize the above three parameters in a separate axis


Figure 11. Variable Plot Selection Options

  • The plotted values can be seen in the Time Plot section


Figure 12. Live Sensor Data Plot

  • The timeline can be zoomed in or out, as shown below. In this example, the timeline is 80s.


Figure 13. Time Window Zoom Controls

  • Click the location symbol to add a vertical cursor to the graph (two vertical cursors need to be added)


Figure 14. Vertical Cursor Tool

  • The vertical cursors can be kept in the below mentioned positions


Figure 15. Dual Cursor Measurement View

**Note:** The position of the vertical cursors determines the number of samples collected.
  • Click the below mentioned icon to collect data


Figure 16. Data Snapshot Export Control

  • The below window mentions the duration by window start and window end timelines


Figure 17. Snapshot Source Selection Panel

  • Uncheck the Include timestamps and Allow scientific notation under CSV options and Data value format, respectively. Also change the Sample lines to 100.


Figure 18. CSV Snapshot Format Settings

  • Save the collected .CSV file to your computer.

    Note: Collect as many samples as possible; the more samples, the more training for the model, increasing thus the accuracy.

Training the model:

  • After collecting all the data samples, open the ML Suite in MPLAB X IDE and login into ML Suite

  • The home page for the MPLAB ML Model Builder is shown below


Figure 19. Opening MPLAB ML Suite


Figure 20. ML Builder Dashboard

  • Click Create Project to create a new model to train


Figure 21. Project Creation


Figure 22. Create Project

  • Click the below highlighted icon to open the Project


Figure 23. Opening the Enviro Sense Project

  • The main page for the Enviro_Sense model will look as shown below


Figure 24. Enviro Sense Project Overview

  • Go to Project Settings under Project Summary and add labels as shown below

    • Click Add Label to add a label as shown below


Figure 25. Adding New Segment Labels


Figure 26. Creation of a Label

  • Add the required labels for the model to train


Figure 27. Viewing Segment Label List

  • Go to Data Manager and import all the collected data samples (.CSV files)


Figure 28. Importing Sensor Capture Data


Figure 29. Choosing Capture File Upload


Figure 30. Confirmation of Uploaded Capture Files


Figure 31. Completing Capture File Import

  • Open a .CSV file and click the + or + Create icon to select which part of the graph must be used to add a segment of data


Figure 32. Creation of a Data Segment

Note: This segment tells the model the particular data to be considered in order to train the model

  • Select the appropriate label for the segmented data and click Save to save the particular segment of data


Figure 33. Selecting Segment Label Category

Note: In this example project, 100 samples are taken in each of the .CSV files; the number of samples can be customized, it does not need to be 100.

  • Do the same for all the collected data sets.

  • Once the segments have been created for all the collected data sets, go to Prepare Data and click Create Query to create a query.


Figure 34. Opening Prepare Data Page

  • Configure the query as shown below and click Save


Figure 35. Creating a Data Query

  • Click Rebuild as shown below and check if the status is Cached


Figure 36. Viewing Cached Query Status

  • Click Build Model and select Create Pipeline


Figure 37. Creating a Model Pipeline

  • Click Next, enter the pipeline name and query and click Create Pipeline


Figure 38. Selecting Pipeline AutoML Option


Figure 39. Creating EnviroSense Pipeline

  • Follow the steps shown in the below images:


Figure 40. Reviewing Pipeline Creation Settings


Figure 41. Configuring Windowing Segmenter


Figure 42. Feature Extraction Methods

  • Once the configuration of the pipeline has completed, click Run Pipeline

  • Once the pipeline run has completed successfully, five models will be generated as shown below.


Figure 43. Pipeline Training Results

  • Next, go to Explore Model and download the model with highest accuracy and with PME classifier


Figure 44. Model Selection for Download

  • Click MPLAB XC 32 and Select


Figure 45. MPLAB XC32 Target Selection

  • Choose the processor used (PIC32CZ8110CA90208, in this case) and click Download


Figure 46. Knowledge Pack Download Settings

  • Follow the below steps for downloading the knowledge pack file


Figure 47. Inference Folder Save Location


Figure 48. Knowledge Pack Add Prompt 1


Figure 49. Knowledge Pack Add Prompt 2

Adding knowledge pack to the project:

  • In MPLAB X IDE, go to Projects > Firmware > Inference and check whether the Knowledge Pack .zip file is available. If it is not available, copy the downloaded Knowledge Pack .zip file into Created Project > Firmware > Inference.


Figure 50. Knowledge Pack Files Menu

Note: Rename the .zip file to "knowledgepack"

  • Extract the contents of the knowledge pack file and delete the original .zip file, retaining only the extracted files for clarity.

  • In MPLAB X IDE, under Projects, right click Header Files and do the following steps:


Figure 51. Existing Items Folder


Figure 52. Source File Folder Dialog


Figure 53. Header Folder Selection Window


Figure 54. Project Source Folder List

  • Do the same for Source Files too, but change the file type, as shown below:


Figure 55. C Source Folder Selection

  • Right click Libraries, and then click Add Library/Object File


Figure 56. Library and Object File Menu

  • Go to Project > Firmware > Inference > Knowledge Pack > Firmware > mplabm > Lib > libmplabml.a and add the libmplabml.a file.


Figure 57. Library Object File Selection

  • This is how the file structure will look like once the knowledge pack files and library files have been added


Figure 58. Folder Structures after adding the Knowledge Pack Files

Note: The empty folders from the knowledge pack file can be removed by right clicking on those particular files and selecting Remove From Project.


Figure 59. Library Folder Removal Menu

  • Once all the above steps are completed, the output will be displayed as shown below.


Figure 60. Output - Cool_Humid


Figure 61. Output - Rainy


Figure 62. Output - Normal

Conclusion

The EnviroSense AI demo integrates environmental sensors, embedded machine learning, data streaming, and graphical visualization on a Microchip platform to enable real-time environmental condition monitoring and classification. By using the VEML7700 Ambient Light Sensor and BME680 for temperature and humidity sensing, the system captures live environmental data and applies an on-device SensiML-trained model to classify conditions such as Cool_Humid, Humid, Normal, Rainy, Sunny, and Unknown. Its modular software structure supports both raw data visualization and embedded inference, while external display integration improves the user interaction and system observability. This makes the demo a practical foundation for edge AI development in smart environmental monitoring and intelligent sensing applications.

About

The EnviroSense demo uses the Ambient Light Sensor (ALS) and BME680 (humidity, temperature) to collect real-time data, run an embedded ML model, and output live weather labels: Cool_Humid, Humid, Normal, Rainy, Sunny, Unknown.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages