Connected Field Services, Dynamics 365, IOT

Let’s Blink with the MXChip

Introduction

In my previous two articles, I covered how to connect the MXChip Dev-Kit to Azure IoT Central and how to create Alerts in Azure IoT Central. If you haven’t gone through them yet, you can go have look at the below links

  • Getting Started with Azure IoT Central – Connecting the MX Chip: Link
  • Creating an Alert in Azure IoT Central – Link

In this article, we look at how we can get started with writing custom firmware to the MXChip DevKit.

The MX chip is a well know Microcontroller / Devkit for anyone who has been working with Azure IoT. I first came across the MX Chip in one of the Microsoft Boot Camps hosted by Ben Volmer couple you years ago which showcased how to link the MX Chip with Dynamics 365 Connected Field Services to receive Telemetry data from the device to D365.

The MX Chip is a Microcontroller that has

  • A Processor to compute instructions
  • Memory to store instructions
  • I/O Input / Output ports to receive and output instructions.
  • An LCD to display information
  • Audio interface
  • WIFI InterfaceMore Information on the MX Chip can be found in the following URL: Link

More Information on the MX Chip can be found in the following URL: Link

The MX Chip is an Arduino based Microcontroller. More information about Arduino based Microcontroller can be found in the below URL:   Link

Information to the MXChip can be programmed via different interfaces in this article we are going to look at two of those interfaces.

  1. Arduino IDE
  2. Visual Studio Code

So let’s look at how we can get the MX Chip connected to these interfaces

Arduino Interface

Connecting to this interface is very straightforward

Step 1: Download and Install the Arduino IDE from URL: Link

Step 2: Connect the MX Chip to the USB Port in your PC

Step 3:  Go to the Board Manager in the Arduino IDE

Step 4: Search for the MX Chipboard in the Board Manager and install the board on the IDE

Step 5:  Search and select for the MX Chip from the Board List

Visual Studio Code

When it comes to connecting the MX Chip to the Visual Studio IDE there are few steps involved and all the steps can be found in the following URL: Link

Lets Blink.

Now that we have connected the MX Chip to the PC and an IDE, let’s look at writing our very first program on the MX Chip.  For this example, I am going to use the Arduino IDE. We are going to look at a simple program called “Blink”.What this program will do is Turn On and Off a LED light in the MX Chip.   

Step 1: Go to the Arduino IDE click File -> Go to Example -> Basic. This will load a sample code of the blink program to the IDE

Let’s look the program. There are to parts as “Setup” and “Loop” .

void setup () {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}
 
// the loop function runs over and over again forever
void loop () {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}
// the setup function runs once when you press reset or power the board

void setup ()

Basically, the Setup section will run once every time you turn on or Reset the MXChip  (On Load).

Next we have a pinMode() function . What this function does is it configures the specified pin to behave either as an input or an output.

Syntax

pinMode(pin, mode)

  • pin: the Arduino pin number to set the mode of.
  • mode: INPUT, OUTPUT, or INPUT_PULLUP.

If our example inside the Setup section we have “pinMode(LED_BUILTIN, OUTPUT)” which is basically telling the MX Chip that there is a LED called ” LED_BUILTIN ” which has instructions to output a certain value which is defined in the Loop section. What the Output will do is it will set a Positive 5V (or 3.3V on 3.3V boards) which will Turn on the LED or a Negative 0V Voltage which will Turn off the LED to the defined Pin. How the Positive and the Negative voltages are set to the Pin? We will look at that in the Loop Part

void loop ()

The Loop part will run forever until the MX Chip is turned off. Inside the Loop part, there is another function as digitalWrite(). What this function does is write a HIGH or a LOW value to a digital pin.

Syntax

digitalWrite(pin, value)

Parameters

pin: the Arduino pin number.
value: HIGH or LOW.

Because the pin has been configured as an OUTPUT with pinMode() in the Setup section, its voltage will be set to the corresponding value: 5V (or 3.3V on 3 .3V boards) for HIGH, 0V (ground) for LOW. So if we look at the digitalWrite() function in our sample code “digitalWrite(LED_BUILTIN, HIGH)” it basically tells the MX Chip to set the LED_BUILTIN to High which is a + voltage which will Turn on the LED and wait for 1 second (1000 milliseconds ) using the delay() function and then do digitalWrite(LED_BUILTIN, LOW) which is going to set the LED_BUILTIN to Low which is a – voltage which will Turn off the LED.

By running this code inside the loop the LED will keep blinking hence its called Blink.

As always I hope this article will become useful in your Azure IoT journey. Have fun and let me know if you have any questions.

Tagged , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.