Lab 3 - How to Integrate the RNBD Module to MPLAB® X IDE to Establish Bluetooth® Communication
Introduction
This guide explains how to integrate the RNBD451 Bluetooth® module into projects using MPLAB® X IDE to enable wireless communication over Bluetooth with the SAM9X75 Curiosity Wireless Kit. This application is ideal for developers working with SAM MPUs aiming to establish Bluetooth connectivity within embedded applications.
To develop this thermostat application, the RNBD451 Add-on Board is used. The RNBD451 Add-on Board is an efficient, low-cost development platform to evaluate and demonstrate the features, capabilities, and interfaces of our RNBD451PE Bluetooth LE module. The Add-on Board is compliant with the mikroBUS™ standard and includes an on-board MCP2200 USB-to-UART converter, enabling out-of-box evaluation with no other hardware requirements.
This application allows users to send and receive messages between the SAM9X75 Curiosity Wireless Kit and a mobile phone using the Microchip Bluetooth Data (MBD) mobile application via Bluetooth.
Prerequisites
Follow the steps mentioned below :
- Hardware Setup - SAM9X75 Curiosity Wireless Kit-based IoT Thermostat Application
- Lab 1 - How to Create an MPLAB X IDE Project
- Lab 2 - How to Integrate Temperature Sensor to MPLAB X IDE Project
- If the RNBD Add-on Board is in HCI mode, change it to data mode by following the steps in the "Step-by-Step Guide to Set Up RNBD Module for Data Mode" section
- RNBD451 Bluetooth® Low Energy Module User’s Guide
Add Project Graph and Develop an MPLAB Harmony Application
The next step is to add RNBD to the project graph. To do this, from the Device Resources pane, expand Wireless > BLE and add RNBD to the Project Graph.
The RNBD Add-on Board is connected to the mikroBUS connector and communicates via Universal Asynchronous Receiver Transmitter (UART). For this thermostat application, the RNBD board is connected along with the Temp&Hum13 click on the mikroBUS using Mikroe Shuttle click. Refer to the hardware setup for more details.
From the "SAM9X75-Curiosity User Guide", note that the mikroBUS UART is interfaced to the SAM9X75 Curiosity board via FLEXCOM1_RXD and FLEXCOM7_TXD as shown in the accompanying image:
Now add the dependency to RNBD UART as FLEXCOM1. Right-click on RNBD UART, and select Available Satisfiers > FLEXCOM1 to add FLEXCOM1 to the Project Graph.
Verify the Configuration Options. For FLEXCOM1, the Baud Rate should be 115,200.
From the configuration option for RNBD, ensure Select Module Type is set to RNBD as shown in the accompanying image.
Add the pin configurations. To do this, go to Project Graph > Plugins > Pin Configuration.
For SAM9X75 Curiosity Wireless Kit, the RNBD board is connected to FLEXCOM1 via UART pins PA28 and PA29. Configure PA28 as BLE_TX and PA29 as BLE_RX as shown in the accompanying image:
Save and then click the Generate button. This will generate code for all the device resources for RNBD that have been added in the project graph.
Up to this point you used MPLAB Code Configurator (MCC) to configure and generate code to initialize the device (SAMA9X75). All that is left is for you to do is to write the application code in the main.c and app.c file.
Documentation for each of the peripheral libraries or driver libraries can be accessed as follows:
- FLEXCOM peripheral library APIs description and usage, see "2.47 Flexible Serial Communication Controller (FLEXCOM)"
- BSP library APIs can be found in bsp.h
- Debug peripheral library APIs description and usage, see "2.27 Debug Unit (DBGU)"
- RNBD library APIs can be found in rnbd.h
In this example, the temperature and humidity value read from the Temp&Hum 13 Click will be updated on the MBD mobile application when the user requests.
The example application source file for the RNBD Add-on Board used in the thermostat application.
APIs used for this application are as follows:
- RNBD_EnterCmdMode();
- RNBD_SetName(DevName,strlen(DevName)); // Device Name set to SAM9X75 Thermostat
- RNBD_RebootCmd();
- RNBD_EnterDataMode();
- RNBD_SetAsyncMessageHandler(..);
- RNBD_Read()
- RNBD_DataReady()
The source file can be downloaded and added to the project as shown in the accompanying image:
Similarly, the header file can be added as shown in the accompanying image:
The app_rnbd_task should be called periodically to receive/transmit messages from the MBD mobile application. (Refer to the sample app.c file.)
Now build the code.
While building, if you are getting error messages as shown in the accompanying image...
Add rnbd.h to the MPLAB X IDE project as shown in the accompanying image:
Refer to the sample application files.
The SAM9X75 Curiosity RNBD device name is set as SAM9X75THERMOSTAT.
Refer to the sample application project.
To debug this application, follow the steps 1-13 in Lab 7.
The debug log will be as shown in the accompanying image:
Now to connect to SAM9X75 Curiosity via Bluetooth use the Microchip Bluetooth Data (MBD) mobile application.
On your Apple® device, locate the App Store® icon and download Microchip Bluetooth Data (MBD).
Install the MBD application on your mobile phone and launch the MBD mobile application.
The SAM9X75 Curiosity board device name is set to SAM9X75THERMOSTAT.
Now scan, connect, and establish communication with the SAM9X75THERMOSTAT from the mobile application.
When you are sending the message as status from your mobile application, the temperature and humidity value read from the Temp&Hum13 Click will be received in your mobile application as shown:
To boot the application from microSD™ card follow the these steps:
Create harmony.bin file by following the steps 14 in Lab 7.
Now copy the generated harmony.bin from your project directory and boot.bin to the microSD card.
Insert the microSD card into the SD card J14 slot. Power the board on. Press the reset button (sw3) on the board.
Observe the output 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 to the debug console as well as to the MBD mobile application via Bluetooth, upon a status request from the MBD app to the Thermostat application running on the SAM9X75-Curiosity Kit.
Lean More
- SAM9X75 Curiosity Wireless Kit - IoT Thermostat Application Using Embedded Wizard GUI+ WINCS02+ RNBD+ MQTT Training With Hands-on Labs
- 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 MPLAB® Harmony Application
- Lab 8 - Running the Pre-built MPLAB® Harmony IoT Application From the SD Card