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.

 

 

My IoT Journey

My  Internet of Things Journey

What is IoT ?

 

    So anyone who tells you they are an Expert when it comes to IoT are either flat out deceiving you or they are crazy. The subject has gotten so massive that it's nearly impossible to master it completely. I am on a journey to learn as much about this interesting subject as I can. I plan to document this journey, not only for your benefit, but so i have a reference to fall back upon.

     Let's start by trying to define the Internet of Things. If you do a search you get about as many definitions as there are beers on the wall. Everything from the super geek definition I found on Wikipedia to asking my not so techy friend over a beer.  According to Wikipedia, IoT is the inter-networking of physical devices embedded with sensors, software and connectivity which enables these devices to collect and exchange data. This is an excerpt from Wikipedia, but I think it hits the nail on the head. It’s a bunch of devices that can sense their surroundings, process the information, and share that information with the world. It’s not a coincidence that data is in this definition. Data is the key.  The devices collect and act on their surroundings, but it’s the data they generate that’s important.  So, think of the sensor I have sitting on my lanai collecting temperature and humidity. Sounds lame, but if you take that data and send it to a Weather service, now we have a weather station reporting real time data and saving that data to help in forecasting. Now suddenly, my temperature sensor is now an IoT device.  Now my device is helping my neighbors decide how hot it may get this week. That’s because I have been collecting data for months and we can analyze the data and make predictions. See, the data is the key.

     So now we have the official definition, here is my interpretation. In my opinion, IoT should be defined as the IO part and the Things part.The IO part is the input and output. It’s the exchange and collection of data from a device. It’s my distance sensor telling me when I am going to hit the curb while parking the car. It’s the sensor on the board collecting data. It’s the WiFi chip sending that data to the cloud.  The Things part is my temperature sensor, it’s a GPS collar on Daisy the farm cow telling me when she is in a family way, it’s a PH sensor alerting someone the PH is too high out on the farm. If you start thinking about it, Things that share data are all around us. They are even creeping into our kitchen. Who knew that my refrigerator could talk to me? What does it have to say, and how can I use that information. Well, it tells me I need to go buy milk and eggs. It has a sensor that sees when things are missing and acts on that information. It collects and processes. Suddenly my refrigerator is a Smart Device!  A device that collects and forwards data to be analyzed and acted upon.

      So how long have these IO things been around? I think it’s interesting to know they have been around longer than you think. The concept of a smart device has been around since 1982. A modified Coke machine at Carnegie Mellon University was the first connected appliance able to report its inventory and whether the newly loaded drinks were cold.  Between 1993 and 1996 we saw solutions like Microsoft’s at Work and Novell’s Nest. If you search you will find many other examples of the first IoT device, I just think this one is more real life.

  This is my attempt in this journey to define this gargantuan subject we call Internet of Things. I think this groundwork is important in order to move forward in my exploration of IoT. In my next post i will discuss the architecture, the common protocols used, and how we communicate with these devices. I am planning a series of posts explaining not only the topics i am going to cover, but how IoT is managed in Azure. I also just received the Microsoft MXChip IoT DevKit. Microsoft's elegant answer to learning IoT development.

Stay tuned..............

 

 

Welcome to my Blog

Hello and welcome to my first blog.

     This will be a place where i will share things i have found in my coding travels. Some will be Azure and some will not, it just depends on what i am working on at the time.  As always i will promote my Slot Machine application. This is where i tryout new ideas and incorporate them into a slot machine game. 

     And if that's not enough, when ever possible i will blog about hiking and my goal to hike the entire Appalachian Trail. My Wife, Son and Daughter have finished Georgia, now on to the next 2000 miles. You can find information about the entire trail here :The Appalachian Trail