Lab 2 - How to Integrate A Temperature Sensor to an MPLAB® X IDE Project

Last modified by Microchip on 2025/07/07 14:22

Introduction

This guide outlines the process of integrating MikroElektronika's Temp&Hum 13 Click board™ sensor into an MPLAB® X IDE project using the SAM9X75 Early Access Wireless Curiosity Kit. The Temp&Hum 13 Click board can measure humidity levels ranging from 0 to 100 percent RH and temperatures ranging from -40°C to +125°C, with the typical accuracy of ±2% RH and ±0.3°C. It provides processed and calibrated measurement values over the I2C interface. 

You will learn how to set up the hardware connection via mikroBUS™, configure I2C communication and add the necessary driver and application code to read temperature and humidity data from the sensor. 

This application allows users to monitor real-time environmental data directly from the development board using a terminal program such as Tera Term, PuTTY, or the MPLAB Data Visualizer.

Back to top

Prerequisites

Follow these steps:

Back to top

Add Project Graph and Develop an MPLAB Harmony Application

Follow the steps in Lab 1 to create an MPLAB X IDE project.

The next step after launching MPLAB Code Configurator (MCC) is to add the BSP to the project graph. To do this go to Device Resources, expand Board Support Packages (BSPs) and then add SAM9X75 Curiosity BSP.

Add BSP​​​​​

Back to Top


The Temp&Hum 13 Click board is connected to the SAM9X75 Curiosity Development Board via the mikroBUS interface, using the I²C communication protocol.

According to the SAM9X75-Curiosity User Guide, the mikroBUS I2C is interfaced to the SAM9X75 Curiosity board via Flexcom7_I00 and Flexcom7_I01:
Flexcom

Back to Top


The next step is to add I2C to the project graph. From the Device Resources pane, expand Driver, and add I2C to the project graph.

Click Yes to confirm the activation of the HarmonyCore component and No to FreeRTOS®.
Add I2C to project graph

​​​

Back to Top


Add dependency for I2C as FLEXCOM7 to the Project Graph. Right-click on I2C, click and add Available Satisfiers, then choose FLEXCOM7.

Add FLEXCOM7

The project graph appears as shown:
Project Graph 1

Back to Top


The next step is to add the Debug Console to the project graph. To do this, click Device Resources > Peripherals > DBGU.
Add Debug to the project graph

Back to Top


Add the pin configurations. To do this, go to Project Graph > Plugins > Pin Configuration.
Pin Config
​​

Back to Top


As per the following SAM9X75 Curiosity diagram, the debug console is connected to PA27 and PA26.Hardware Connection

Similarly, configure PC0 and PC1 to FLEXCOM7 for I2C communication mentioned in Step 1.

Now configure these pins as shown in the accompanying image:

Pin Configuration

Back to Top


Verify the configurations. For DBGU the Baud Rate should be 115,200 and for FLEXCOM7 the Clock Speed (Hz) (frequency) should be 400,000.
Configurations

 

Back to Top


Save and then click Generate Code. This will generate code for all the Device Resources (I2C and Debug) that have been added in the project graph.

Generated Code

Back to Top


Up to this point, you used MCC to configure and generate code to initialize the device (SAM9X75). Refer to the initialization.c file in project_directory/src/config to find that all the device resources added in the project graph were initialized.

All that is left is for you to do is write the application code in the main.c and app.c file (source file for the Temperature and Humidity sensor).

Information

Documentation for each of the peripheral libraries or driver libraries can be accessed as follows:

Back to Top


APIs used for this application are as follows:

  • FLEXCOM7_TWI_ErrorGet
  • FLEXCOM7_TWI_IsBusy
  • FLEXCOM7_TWI_WriteRead
  • DBGU_Write
  • DBGU_TransmitComplete 

Back to Top


Back to Top


To debug this application, complete Steps 1-13 from Lab 7. When you run the application from MPLAB X IDE, you can observe the debug output console message as shown in the acompanying image:Debug Console Output

This completes the integration of the Temp&Hum13 Click board to an MPLAB X IDE project.

Back to Top


To boot the application from a microSD® card, follow these steps:

Create the harmony.bin file by following the steps in Lab 7

Now copy the generated harmony.bin file from your project directory and the boot.bin file to the microSD card.

Insert the microSD card into the SD card J14 slot. Power the board on. Press the rest button (sw3) on the board.

Observe the temperature and humidity value read from the Temp&Hum13 Click board displayed on the console as mentioned in the previous step.

Back to Top

Summary

In this training, you developed, configured and built an MPLAB Harmony v3 application to read real-time temperature and humidity sensor values and print them in the debug console on the SAM9X75 Early Access Wireless Curiosity Kit. 

Back to Top

Learn More

Back to Top