MxChip - My First Look and First Project

     So I was fortunate enough to be selected for the preview of the MXCHIP IoT DevKit . This is Microsoft's entry into the IoT hardware space. It is a credit card sized IoT device with an array of built-in sensors, an OLED Screen, a Microphone and even two buttons throw in for good measure. It has 25 external GPIO pins on the edge connector of the board, allowing you to connect to external sensors and actuators.  It is interesting that they decided to make it Arduino based, I suspect to take advantage of the vast existing code and sensor base.  They even made sure you could program it with both Visual Studio 2017 and Visual Studio Code. Both require you to have the Arduino Extensions installed.

     Fortunately as part of the setup Visual Studio Code and the extensions are in the initial download package. If you go to the Prepare Environment section of the Getting Started  page you will see what a great job they did in helping you set up the chip and your development environment.  As you can see they include everything you need in order to start using the MXCHIP.

Once you have downloaded and extracted the zip file, you run the install.cmd as an Administrator. If all goes well, in about 10 minutes you will be ready to go. One thing to keep in mind, as you see above it states that it relies on Arduino IDE. I have found that in Visual Studio 2017, you must load the libraries in the Arduino IDE first in order for them to work correctly. It looks like the fixed this for Visual Studio Code, thankfully.

     So now that we have briefly discussed the MXCHIP and the development environment, lets dig in and take the Chip out for a spin. As you can see from the list below, the list of sensors is quite impressive.

  • EMW3166 Wifi module with 256K SRAM,1M+2M Byte SPI Flash
  • Codec,with ,microphone and earphone socket
  • OLED,128×64
  • 2 user button
  • 1 RGB light
  • 3 working status indicator
  • Security encryption chip
  • Infrared emitter
  • Motion sensor
  • Magnetometer sensor
  • Atmospheric pressure sensor
  • Temperature and humidity sensor
  • Connecting finger extension interface

  I decided I wanted to try something different. I noticed that the MXCHIP has a magnetometer as one of it's many senors. A magnetometer measures magnetic forces, especially the earth's magnetism. So if you can measure the earth's magnetism, then you can measure direction. So i decided I would create my own MXCHIP compass. You will take the X and Y axis values you get from the magnetometer and convert that to direction. Now let's get one thing straight, I am not mathematically inclined by any means. I am however, very gifted when it comes to looking things up on my favorite search engine. A simple search turned up a formula for calculating direction.

float Getheading(double x, double y) 
{
  float head = atan2(y, x); // Slope Y, Slope X
  return head;
}

This is great, but there is one thing missing. Magnetic Declination. So according to Wikipedia, "Magnetic declination  or variation is the angle on the horizontal plane between magnetic north (the direction the north end of a compass needle points, corresponding to the direction of the Earth's magnetic field lines) and true north (the direction along a meridian towards the geographic North Pole). This angle varies depending on position on the Earth's surface, and changes over time." Basically its the correction you must make for the difference between True north and the geographic north pole. Without this correction your direction will be considerably off. I came up with a nice function that calculates declination. It uses the buttons on the MXCHIP. When you press the A button it switches from East to West declination. When you press the B button it increases the degrees of variation. If you are showing West declination, pressing the A button will switch to East and reset the degrees to 1. Below is a snippet of code that show the code for the buttons.

  if( IsButtonClicked(USER_BUTTON_A))
  {
      if(decDir == 'W')
        decDir = 'E';
      else
        decDir = 'W';

      snprintf(buff, 128,"Dir: %c, Deg:%d ",decDir,decDeg);
      Screen.print(buff);

      decDeg = 1;
      SetDeclination(decDeg,decDir);
  }

  if( IsButtonClicked(USER_BUTTON_B))
  {
     decDeg += 1;
     snprintf(buff, 128,"Dir: %c, Deg:%d ",decDir,decDeg);
     Screen.print(buff);      

     SetDeclination(decDeg,decDir);
  
  }       

Finally the code that sets the declination is as follows

void SetDeclination(int declination_degs , char declination_dir )
{
    // Convert declination to decimal degrees
    switch(declination_dir)
    {
      // North and East are positive   
      case 'E': 
         declination_offset_radians = declination_degs  * (M_PI / 180);
        break;
        
      // South and West are negative    
      case 'W':
        declination_offset_radians =  0 - ( declination_degs  * (M_PI / 180) ) ;
        break;
    } 

    Serial.printf("Deg:" + declination_degs);
    Serial.printf("Dir:" + declination_dir);
   
}

Put it all together and you have a working compass. Not the most glamorous of projects, but it shows some of the capabilities of the MXCHIP. I plan to extend this project and turn it into a game. I want to demonstrate the capabilities of Azure and the two way communication with IoT devices, so i am going to add the MQTT protocol and setup two way communication with the MXCHIP. I will send a direction to the chip and then the user will move until the light on the chip stops flashing. I am also working on incorporating the motion detector on the chip to capture distance traveled as well. I will take the telemetry into Azure and then display the path traveled on a map. Still a few weeks away, but stay tuned.

     So that is a small glimpse into the new MXCHIP. From what I have seen I am quite impressed. Not only does it come packed with sensors, it also is quite easy to develop. Microsoft was wise in making the development platform Arduino. This opens a vast array of code and sensors. It also shortens the learning curve. If you have any experience with IoT devices, you have worked with the Arduino IDE and code. The on board capabilities are impressive and they also included room to grow. The chip has 25 GPIO ports on a expansion connection at the bottom.

     With the Expansion connector you can add any Arduino compatible sensor to the chip. This opens up an endless list of possible projects and use cases. So before the MXCHIP, you had to purchase the sensors separately, find the fritzing diagram to figure out how to wire them and then hope you have the correct drivers to make it work. Now with the chip, you have all that in one place.

     This is the first post in a series I plan to write on the Microsoft MXCHIP DevKit. I will post all the source code to this and future post here. If you want to get into this phenomenon we call IoT, the Microsoft MXCHIP is a great place to start. Please stay tuned for my next post where we will demonstrate two way communication between Azure and the MXCHIP.