Lab 2 - How to Integrate A Temperature Sensor to an MPLAB® X IDE Project
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.
Prerequisites
Follow these steps:
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.
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:
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 dependency for I2C as FLEXCOM7 to the Project Graph. Right-click on I2C, click and add Available Satisfiers, then choose FLEXCOM7.
The project graph appears as shown:
The next step is to add the Debug Console to the project graph. To do this, click Device Resources > Peripherals > DBGU.
Add the pin configurations. To do this, go to Project Graph > Plugins > Pin Configuration.
As per the following SAM9X75 Curiosity diagram, the debug console is connected to PA27 and PA26.
Similarly, configure PC0 and PC1 to FLEXCOM7 for I2C communication mentioned in Step 1.
Now configure these pins as shown in the accompanying image:
Verify the configurations. For DBGU the Baud Rate should be 115,200 and for FLEXCOM7 the Clock Speed (Hz) (frequency) should be 400,000.
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.
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).
APIs used for this application are as follows:
- FLEXCOM7_TWI_ErrorGet
- FLEXCOM7_TWI_IsBusy
- FLEXCOM7_TWI_WriteRead
- DBGU_Write
- DBGU_TransmitComplete
Download the sample application project.
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:
This completes the integration of the Temp&Hum13 Click board to an MPLAB X IDE project.
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.
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.
Learn More
- SAM9X75 Curiosity Wireless Kit - IoT Thermostat application using Embedded Wizard GUI+ WINCS02+ RNBD+ MQTT Training with Hands-on Labs
- Lab 3 - How to Integrate RNBD Module to an MPLAB X IDE to Establish Bluetooth® Communication
- Lab 4 - How to Integrate WIxCS02 M.2 Wi-Fi® Module Card to an MPLAB® X IDE Project to Establish Wi-Fi Communication
- Lab 5 - How to Integrate MQTT to an MPLAB X IDE Project to Publish and Subscribe Data To/From a Cloud Broker
- Lab 6 - How to Integrate an Embedded Wizard GUI Project With an MPLAB® X IDE Project
- Lab 7- Debugging and Testing the IoT Harmony Application
- Lab 8 - Running the Pre-built Harmony IoT Application From the SD Card