Implementing MikroElektronika Click board support on Azure Sphere MT3620
This blog uses the Azure sphere MT3620 Starter KitAzure sphere MT3620 Starter Kit to implement support for a several MikroE Click boards. There are actually over 650+ mikroBUS(tm) boards (referred to as click-boards) with all types of sensors (see https://www.mikroe.com/click for a complete list). For the demonstration programs discussed in this blog, support is limited to the boards listed in the Sensor Evaluation using MikroE Click Boards blog.
Overview
The MT3620 Starter Kit was chosen because it supports two MikroE click-board sockets as well as several on-board sensors. With the variety of possible sensors, the goal was to demonstrate the different I/O interfaces using standard library of ANSI C library functions. The library I am using supports the following click-boards:
- BAROMETER ClickBAROMETER Click -- uses the I2C interface for interactions
- FLAME ClickFLAME Click -- uses Binary I/O for interrupt input and ADC inputs
- LIGHTRANGER ClickLIGHTRANGER Click -- uses the I2C interface.
- OLED-B Click OLED-B Click -- uses the SPI and Binary I/O interfaces.
- RELAY ClickRELAY Click -- uses Binary I/O interfaces
- TEMP&HUM ClickTEMP&HUM Click -- uses the I2C interface
- LCD MINI ClickLCD MINI Click -- uses a combination of SPI and Binary I/O interfaces
Some click-boards, like the relay-click, are simple Binary I/O while others, like the LCD Mini click, involve multiple SPI bus and Binary I/O interactions. In the demonstration program discussions, any unique interface attributes will be highlighted.
Development Platform
When developing for the Azure Sphere Starter Kit, a Windows 10 (version 1607 or later) PC with Visual Studio, and the Azure Sphere SDK will be utilized. Once the development environment is installed the Starter Kit is connected via USB. The entire development environment is extensively discussed on on the Microsoft web-site (https://docs.microsoft.com/en-us/azure-sphere/app-development/development-environment) but to briefly mention it, you need to ensure that:
1. The development PC has GIT installed (https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) so you can retrieve copies of the software.
2. Visual Studio is installed--can be either the Enterprise, Professional, or Community; use version 16.04 or later which can be installed from https://visualstudio.microsoft.com/
3. The Azure Sphere SDK is installed from https://docs.microsoft.com/en-us/azure-sphere/install/install.
In earlier releases of the Azure Sphere SDK, not all the capabilities of the MT3620 were exposed in the SDK but over time, additional capabilities have been implemented and released. To get an up-to-date status on what is currently support and what isn't, see the Microsoft support page at https://docs.microsoft.com/en-us/azure-sphere/hardware/mt3620-product-status as some click-boards may use capabilities that are not available.
An example of this is the Flame Click. This click-board will generate an interrupt signal when a preset threshold is passed and an analog voltage is passed to an ADC so you can determine the exact level that the IR sensor is detecting. Only the latest Sphere SDK pre-release has support for the ADC.
Another aspect to be aware of is that when developing software for Sphere you can not use C++ because the Azure Sphere SDK only supports development in C (https://docs.microsoft.com/en-us/azure-sphere/resources/release-notes-1905). Though Visual Studio does not generate an error if you add C++ source files to an Azure Sphere project, it will not build correctly because the Sphere SDK will not support it. This is why all the click-board library software is written in ANSI C.
Demonstration click-board Repository
To utilize the click-board library, all you need to do is include the repository (https://github.com/Avnet/clickmodules) into your project. The click-board demo project already has this repository included so it will include the latest version of click-board software. You can obtain the source code by cloning the project using the command:
git clone --recurse https://github.com/Avnet/clickboard_demos
The '--recurse' part of the command tells github to include the click-board library submodule. Without it, the latest version of that submodule/library will not be pulled and the project will fail to build.
Demonstration Programs
click_demo program
The 'click_demo' project can exercise three of the click boards--the Barometer Click, Temp&Hum Click, and OLED-B Click.
Barometer and Temp&Hum click board
Default operation is to utilize the Barometer and Temp&Hum clicks. You can install these two click-boards in any order you desire because the attached boards are queried to determine who is present on the board. When the demonstration program starts, it queries for each potential click-board and if the response is correct, that board is signaled as present and utilized with output being routed to the Visual Studio output window.
OLED-B click board
The OLED-B click board must be mounted in Slot #1 of the Starter Kit. This is because Binary I/O control is tied to specific pins associated with Slot #1. The SPI bus is routed to both sockets but the Binary I/O's are unique for each socket. Additionally, the startup command line arguments (in app_manifest.json) must be modified to signal to the program to run the OLED-B test by setting "CmdArgs" to "-t". After this is done and the program compiled/run, the OLED-B will display program execution:
flame_demo program
The software for this demonstration program assumed the Flame Click board is inserted into Slot #1. The click board only requires access to the AN (analog) and INT (interrupt) pins but I used slot #1 when developing it. Additionally, though the Sphere SDK will eventually support the ADC, when this software was developed, it didn't so the functionality for reading the ADC hasn't been incorporated into the demo program.
When the program is compiled and run, it will monitor the INT pin for flame/fire detection and display a message when it is or isn't seen. You can force the transition by varying the potentiometer that is on the Flame Click board. When the demo is run, its output is:
lcdmini_demo
This demo uses the LCD mini click to continuously output values read from the LSM6DSO that is on-board the Sphere board every second. It is required to be inserted into Slot #2 for proper operation.
In addition to the data output on the LCD mini display, it is also printed to the output window:
relay_demo
The Relay click board cycles the two on-board relays through a series of combinations on/off states. Essentially, it counts from 0 to 3 using the Relay LED's to indicate which relay is active and which is not. For this demo program to operate correctly, the Relay-Click needs to be placed in Slot #2. When compiled and run, the following output is provided:
As the program is run, you will see and hear the relays open/close and the LED indicating the relay state will either illuminate or go-dark.
tof_demo
The TOF (time of flight) demo uses the LightRanger 2 click-board. This click incorporates an ST VL53L0X Time-of-Flight laser-ranging module. The code for driving this sensor is originally provided by ST Microelectronics and was adapted. This board uses the I2C interface for communications so it can be placed in either Starter Kit mikroBUS socket.
There are a number of different tests that can be run:
- Continuous Ranging
- Single Ranging
- High Accuracy
- High Speed
- Long Range
The desired test to be run is specified by editing the app_manifest.json file and placing a -1, -2, -3, -4, or -5 in the "CmdArgs" field. You can also modify the duration of the test (it has a default time of 30 seconds). Once the test begins running, its output is similar to:
The Device Information is read from the VL53L0X device during startup and once the testing begins, the data is displayed to the user and the total duration of the run is displayed.
Conclusion
The intention of these demonstration programs is to provide a library of code that has been written such that it can be used unchanged across multiple hardware platforms. Though the demo code in this blog is written for the Azure sphere MT3620 Starter KitAzure sphere MT3620 Starter Kit, the same code can be used on the AT&T Starter KitAT&T Starter Kit when used with Breakout CarrierBreakout Carrier, the Ultra96 Development BoardUltra96 Development Board with the Click MezzanineClick Mezzanine, or the NXP FRDM-K64F with a click SHIELD. In fact, the demonstration code is included in the repository for each of these platforms.
The only limitation to note is that the Ultra96 ability to operate with the click-boards is dependent on the PetaLinux BSP implementation. As this is a new platform, the BSP does not currently support all the different pin functions that the click-boards utilize, so at this time, support for I2C and SPI in slot #1 of the Ultra96 Click Mezzanine is the most reliable solution. As the BSP matures, support for the second mikroBUS slot and a greater variety of click-boards can be achieved.
As always, please provide any feedback and/or comments. If you have code you would like to add to this repository, we welcome your contribution, please submit a pull-request on the github repository and we will get it added. It would be ideal if we could keep this Avnet repository of click-boards growing to support all that MikroElektronika provides.
Top Comments